Commands using xargs (661)


  • 0
    vboxmanage list runningvms | cut -d \" -f 2 | xargs -I % vboxmanage controlvm % poweroff
    magoon · 2013-11-05 16:58:03 0
  • If you want to do this in the some one db, use redis-cli -n5 KEYS "user*" | xargs redis-cli -n5 DEL


    0
    redis-cli KEYS "user*" | xargs redis-cli DEL
    vp_arth · 2013-10-31 04:10:29 0

  • 0
    redis-cli keys pattern\* | xargs redis-cli del
    pyrux · 2013-10-29 04:59:38 0

  • 1
    find -type f | grep -v "^./.git" | xargs md5sum | md5sum
    cakyus · 2013-10-28 18:35:19 1
  • Replace "foo" with "bar" in all files in current directory recursively


    1
    grep -lr "foo" . | xargs sed -i "s/foo/bar/g"
    sergeylukin · 2013-10-28 13:02:47 3
  • Opposite: Convert an one-liner to script: foo() { <one-liner> ; } ... typeset -f foo ... unset -f foo


    5
    (sed 's/#.*//g'|sed '/^ *$/d'|tr '\n' ';'|xargs echo) < script.sh
    knoppix5 · 2013-10-26 23:23:51 3
  • * Find all file sizes and file names from the current directory down (replace "." with a target directory as needed). * sort the file sizes in numeric order * List only the duplicated file sizes * drop the file sizes so there are simply a list of files (retain order) * calculate md5sums on all of the files * replace the first instance of two spaces (md5sum output) with a \0 * drop the unique md5sums so only duplicate files remain listed * Use AWK to aggregate identical files on one line. * Remove the blank line from the beginning (This was done more efficiently by putting another "IF" into the AWK command, but then the whole line exceeded the 255 char limit). >>>> Each output line contains the md5sum and then all of the files that have that identical md5sum. All fields are \0 delimited. All records are \n delimited.


    0
    find . -type f -not -empty -printf "%-25s%p\n"|sort -n|uniq -D -w25|cut -b26-|xargs -d"\n" -n1 md5sum|sed "s/ /\x0/"|uniq -D -w32|awk -F"\0" 'BEGIN{l="";}{if(l!=$1||l==""){printf "\n%s\0",$1}printf "\0%s",$2;l=$1}END{printf "\n"}'|sed "/^$/d"
    alafrosty · 2013-10-22 13:34:19 0
  • I did not come up with this one myself, but found this somewhere else several months ago. Show Sample Output


    0
    openssl rand -hex 1 | tr '[:lower:]' '[:upper:]' | xargs echo "obase=2;ibase=16;" | bc | cut -c1-6 | sed 's/$/00/' | xargs echo "obase=16;ibase=2;" | bc | sed "s/$/:$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.$//' | tr '[:lower:]' '[:upper:]')/"
    4fd · 2013-10-22 08:40:46 0

  • 0
    find *.less | xargs -I {} lessc {} {}.css && ls *.less.css | sed -e 'p;s/less.css/css/' | xargs -n2 mv
    ckrotcov · 2013-10-21 23:53:31 0
  • This command will delete all files and folders except 'skipme'. it could be a file or a folder.


    -11
    ls -R | grep -v skipme | xargs rm -Rf
    hadifarnoud · 2013-10-18 08:11:39 5
  • When you do a ls -1 | xargs rm it wouldn't workd because those files have spaces. So you must use find -print0 and xargs -0


    -3
    find /Users/jpn/.ievms/ -type f -print0| xargs -0 du -sh
    unixmonkey39631 · 2013-10-16 09:54:19 1
  • My first command :) I made this command to log public addresses of a virtual interface who connects random VPN servers around the world. Show Sample Output


    0
    (date "+%d-%m-%Y %H:%M:%S";curl -s --interface lo:1 ifconfig.me| xargs -t geoiplookup 2>&1)|sed -e 's/geoiplookup/IP:/g' -e 's/GeoIP Country Edition/Country/g'|tr -s "\n" " "|sed 'a\ '
    guerito · 2013-10-07 15:28:55 0
  • Sorts by latest modified files by looking to current directory and all subdirectories Show Sample Output


    1
    find . -name '*pdf*' -print0 | xargs -0 ls -lt | head -20
    fuats · 2013-10-03 21:58:51 0
  • This script can be used to download enclosed files from a RSS feed. For example, it can be used to download mp3 files from a podcasts RSS feed. Show Sample Output


    0
    wget -q -O- http://example-podcast-feed.com/rss | grep -o "<enclosure[ -~][^>]*" | grep -o "http://[ -~][^\"]*" | xargs wget -c
    talha131 · 2013-09-24 12:38:08 0
  • This command is used to verify a sha256sum-formatted file hash list on IBM AIX or any other UNIX-like OS that has openssl but doesn't have sha256sum by default. Steps: 1: Save to the filesystem a script that: A: Receives as arguments the two parts of one line of a sha256sum listing B: Feeds a file into openssl on SHA256 standard input hash calculation mode, and saves the result C: Compares the calculated hash against the one received as argument D: Outputs the result in a sha256sum-like format 2: Make the script runnable 3: Feed the sha256sum listing to xargs, running the aforementioned script and passing 2 arguments at a time Show Sample Output


    0
    echo '#! /usr/bin/ksh\ncat $2 | openssl dgst -sha256 | read hashish; if [[ $hashish = $1 ]]; then echo $2: OK; else echo $2: FAILED; fi;' > shacheck; chmod +x shacheck; cat hashishes.sha256 | xargs -n 2 ./shacheck;
    RAKK · 2013-09-18 21:51:20 2

  • 0
    ipcs -q | grep foo | awk '{print $2}' | xargs -I ipcid ipcrm -q ipcid
    eko · 2013-08-29 15:08:13 0
  • schema & tables To export into another backends style, just change backend to one of: access, sybase, oracle, postgres, mysql and sqlite Show Sample Output


    0
    db=example.mdb; backend=mysql; mdb-schema "$db" $backend | grep -v 'COMMENT ON COLUMN' && mdb-tables -1 "$db" | xargs -I {} mdb-export -I $backend "$db" {}
    garex · 2013-08-25 18:39:27 0

  • 1
    brew cleanup -n | awk '{print $3}' | xargs du -s | awk '{s+=$1} END {print s}'
    jaapie · 2013-08-24 07:50:20 0
  • Solves these pesky errors you see in the Apache log: [Fri Jun 28 17:51:00 2013] [emerg] (28)No space left on device: Couldn't create accept lock (/monsoon/opt/apache2/logs/accept.lock.356) (5) Naturally, can be used to get rid of other semaphores. Note: change the apache user in accordance to your ENV. Show Sample Output


    0
    ipcs -s | grep apache | awk ' { print $2 } ' | xargs ipcrm sem
    kernel01 · 2013-08-12 16:29:32 0
  • On Linux substitute pbpaste with `xsel --clipboard --output` or `xclip -selection clipboard -o` (untested)


    0
    pbpaste | xargs wget
    loopkid · 2013-08-11 23:12:10 0

  • 0
    find . -name "*.h" -o -name "*.cpp" | xargs sed -i 's/addVertexes/addVertices/g'
    egeoffray · 2013-08-07 07:31:45 2
  • Goes through all files in the directory specified, uses `stat` to print out last modification time, then sorts numerically in reverse, then uses cut to remove the modified epoch timestamp and finally head to only output the last 10 modified files. Note that on a Mac `stat` won't work like this, you'll need to use either: find . -type f -print0 | xargs -0 stat -f '%m%t%Sm %12z %N' | sort -nr | cut -f2- | head or alternatively do a `brew install coreutils` and then replace `stat` with `gstat` in the original command. Show Sample Output


    5
    find . -type f -print0 | xargs -0 stat -c'%Y :%y %12s %n' | sort -nr | cut -d: -f2- | head
    HerbCSO · 2013-08-03 09:53:46 2

  • -1
    ls | xargs -I{} du -sh {}
    kenshin54 · 2013-07-28 04:18:25 1
  • first grep all href images then sed the url part then wget


    1
    curl -s $1 | grep -o -i '<a href="//images.4chan.org/[^>]*>' | sed -r 's%.*"//([^"]*)".*%\1%' | xargs wget
    bugmenot · 2013-07-22 10:33:55 0

  • 0
    find ./ -type f -print0 | xargs -0 md5sum
    d24m · 2013-07-18 07:18:54 0
  • ‹ First  < 3 4 5 6 7 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: