Last active
August 15, 2017 08:18
-
-
Save askedrelic/4a0e35c10957b6794f0623faa9c36311 to your computer and use it in GitHub Desktop.
Find examples #unix
This file contains 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
# better mv | |
find . -name "*.symlink" -exec sh -c 'echo "$1" ".${1%.symlink}"' _ {} \; |
This file contains 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
Command Breakdown: | |
1. '.' => search path starting at current directory marked by ' . ' | |
2. -name => set find match name (in this case all files that end with .gappedPeak) | |
3. -exec => execute the following command on every match | |
4. sh -c => 'exec' creates an independent shell environment for each match | |
5. mv "$1" "${1%.gappedPeak}.bed" => mv first variable (denoted by $1), which is the current file name, to new name. Here I do a substring match and delete; so take first var again, $1 and use % to delete .gappedPeak from the string. The .bed at the end just concatenates the remaining variable, which is now just test#, with .bed, creating the new test#.bed filename. | |
6. The underscore is a placeholder for $0 | |
7. The {} is replaced by each (*.gappedPeak) filename found by the find command, and becomes $1 to the sh command. | |
8. \; marks the end of the -exec command. You can also use ';' or ";". | |
find . -name "cover.1*" -exec sh -c 'echo "$1" ".${1%.1.jpg}.jpeg"' _ {} \; |
This file contains 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
# sort sizes of cover.jpg | |
find . -iname cover.* -print0 | xargs -0 -I {} ls -ash "{}" | sort -h |
This file contains 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
# find symlinks in current dir | |
find -maxdepth 1 -type l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment