2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files by case-insensitive extension (ex: .jpg, .JPG, .jpG):
|
2019-08-01 12:19:46 +00:00
|
|
|
|
find . -iname '*.jpg'
|
2018-01-12 10:20:53 +00:00
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find directories:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type d
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files by octal permission:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f -perm 777
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files with setuid bit set:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
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 '{}' \;
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files with extension '.txt' and look for a string into them:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find ./path/ -name '*.txt' | xargs grep 'string'
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files with size bigger than 5 Mb and sort them by size:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -size +5M -type f -print0 | xargs -0 ls -Ssh | sort -z
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files bigger thank 2 MB and list them:
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files modified more than 7 days ago and list file information
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f -mtime +7d -ls
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find symlinks owned by a user and list file information
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type l --user=username -ls
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Search for and delete empty directories
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type d -empty -exec rmdir {} \;
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Search for directories named build at a max depth of 2 directories
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -maxdepth 2 -name build -type d
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Search all files who are not in .git directory
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . ! -iwholename '*.git*' -type f
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find all files that have the same node (hard link) as MY_FILE_HERE
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f -samefile MY_FILE_HERE 2>/dev/null
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find all files in the current directory and modify their permissions
|
2018-01-12 10:20:53 +00:00
|
|
|
|
find . -type f -exec chmod 644 {} \;
|
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find files with extension '.txt.' and edit all of them with vim
|
2018-01-12 10:20:53 +00:00
|
|
|
|
# vim is started only once for all files
|
|
|
|
|
find . -iname '*.txt' -exec vim {} \+
|
2019-05-01 09:43:34 +00:00
|
|
|
|
|
2019-11-06 00:45:05 +00:00
|
|
|
|
# Find all files with extension '.png' and rename them by changing extension to
|
|
|
|
|
# '.jpg' (base name is preserved)
|
2019-08-01 12:19:46 +00:00
|
|
|
|
find . -type f -iname '*.png' -exec bash -c 'mv "$0" "${0%.*}.jpg"' {} \;
|
2019-11-06 00:50:46 +00:00
|
|
|
|
|
|
|
|
|
# Use logic and grouping to delete extension-specific files.
|
|
|
|
|
find \( -iname "*.jpg" -or -iname "*.sfv" -or -iname "*.xspf" \) -type f -delete
|
2019-11-06 17:36:10 +00:00
|
|
|
|
|
|
|
|
|
# List all executable files, by basename, found within PATH.
|
|
|
|
|
find ${PATH//:/ } -type f -executable -printf "%P\n"
|