mirror of
https://github.com/chubin/cheat.sheets
synced 2024-11-17 09:25:32 +00:00
cddd2c0e11
Many uses for this! Say you install a large set of updates, so want to cross-check the old list to the new one, in order to find out which new executables were installed. Or, perhaps less obscure, you might this list, without the `-printf` part, to check their permission and ownership settings.
62 lines
2.0 KiB
Plaintext
62 lines
2.0 KiB
Plaintext
# Find files by case-insensitive extension (ex: .jpg, .JPG, .jpG):
|
||
find . -iname '*.jpg'
|
||
|
||
# Find directories:
|
||
find . -type d
|
||
|
||
# Find files:
|
||
find . -type f
|
||
|
||
# Find files by octal permission:
|
||
find . -type f -perm 777
|
||
|
||
# Find files with setuid bit set:
|
||
find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
|
||
|
||
# To find files with extension '.txt' and remove them:
|
||
find ./path/ -name '*.txt' -exec rm '{}' \;
|
||
|
||
# Find files with extension '.txt' and look for a string into them:
|
||
find ./path/ -name '*.txt' | xargs grep 'string'
|
||
|
||
# Find files with size bigger than 5 Mb and sort them by size:
|
||
find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z
|
||
|
||
# Find files bigger thank 2 MB and list them:
|
||
find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
|
||
|
||
# Find files modified more than 7 days ago and list file information
|
||
find . -type f -mtime +7d -ls
|
||
|
||
# Find symlinks owned by a user and list file information
|
||
find . -type l --user=username -ls
|
||
|
||
# Search for and delete empty directories
|
||
find . -type d -empty -exec rmdir {} \;
|
||
|
||
# Search for directories named build at a max depth of 2 directories
|
||
find . -maxdepth 2 -name build -type d
|
||
|
||
# Search all files who are not in .git directory
|
||
find . ! -iwholename '*.git*' -type f
|
||
|
||
# Find all files that have the same node (hard link) as MY_FILE_HERE
|
||
find . -type f -samefile MY_FILE_HERE 2>/dev/null
|
||
|
||
# Find all files in the current directory and modify their permissions
|
||
find . -type f -exec chmod 644 {} \;
|
||
|
||
# Find files with extension '.txt.' and edit all of them with vim
|
||
# vim is started only once for all files
|
||
find . -iname '*.txt' -exec vim {} \+
|
||
|
||
# Find all files with extension '.png' and rename them by changing extension to
|
||
# '.jpg' (base name is preserved)
|
||
find . -type f -iname '*.png' -exec bash -c 'mv "$0" "${0%.*}.jpg"' {} \;
|
||
|
||
# Use logic and grouping to delete extension-specific files.
|
||
find \( -iname "*.jpg" -or -iname "*.sfv" -or -iname "*.xspf" \) -type f -delete
|
||
|
||
# List all executable files, by basename, found within PATH.
|
||
find ${PATH//:/ } -type f -executable -printf "%P\n"
|