Created
January 5, 2018 17:13
-
-
Save srividya22/28caced0bb2b2f94d4982e267330a85a to your computer and use it in GitHub Desktop.
xargs cheatsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# turn a find or cut (cut delimiter, get first column) output into a list | |
/etc find . -name "*bash*" | xargs | |
cut -d, -f1 file.csv | xargs | |
# find a file and grep for a word in the file | |
find . -name "*.java" | xargs grep "Stock" | |
# handeling filenames which have WHITESPACE | |
ls *txt | xargs -d '\n' grep "cost" | |
# find file and remove it, command is different if there is white space present in filename | |
find . -name "*m1.java" | xarg rm | |
find /tmp -name "*m 1.java" -print0 | xargs -0 rm | |
# move files with multiple different extensions to the home dir | |
find . -name '*bed' -o -name '*txt' -print0 | xargs -r0 mv -t ~/ | |
# count lines of all text files in the cwd | |
ls -1 *.txt | xargs wc -l | |
# rename files to append .old on the end of the filename (-I allows {} to represents each file outputed from ls command) | |
ls *old | xargs -I {} mv {} {}.old | |
# find fastQ files in sub dirs, sort and pair them (helpful for pairing pair-end fastqs on the same line, which can be piped into trim_galore etc.) | |
find ~/fastq/*/* -name '*.fastq.gz' | sort | xargs -n2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment