linux:find
This is an old revision of the document!
find examples
Find and extract all rar files in subfolders into the current folder:
find . -name *.rar -exec unrar x {} \;
Find duplicate files:
find . ! -empty -type f -exec md5sum {} + | sort | uniq -w32 -dD
Find duplicate filenames:
find . -mindepth 1 -printf '%h %f\n' | sort -t ' ' -k 2,2 | uniq -f 1 --all-repeated=separate | tr ' ' '/'
Find files older than 7 years:
find . -mtime +2555 -print
Find directories containing files older than 30 days:
find . -type f -mtime +30 -printf '%h\n' | sort | uniq > old.txt
Find directories containing ONLY files older than 30 days (not working with subdirs properly):
find . -type f -mtime +30 -printf '%h\n' | sort | uniq > old.txt find . -type f -mtime -30 -printf '%h\n' | sort | uniq > new.txt grep -vf new.txt old.txt
Remove all old temporary MS Office lock files:
find . -type f -mtime +10 -name "~*" -print0 | xargs -r0 rm --
Show top level folders and full file count and file count>7years:
find . -maxdepth 1 -type d -print0 -exec echo -n " " \; -exec sh -c "find '{}' -type f | wc -l | tr -d '\n'" \; -exec echo -n " " \; -exec sh -c "find '{}' -type f -mtime +2555 | wc -l" \;
Convert tabs to spaces in source code:
find . -name '*.php' ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;
linux/find.1530632885.txt.gz · Last modified: 2023/05/29 11:53 (external edit)