GNU/Linux: findutils
Publish date: Sep 1, 2023
Last updated: Sep 13, 2023
Last updated: Sep 13, 2023
Some “find” variations that have been handy
Find and copy:
Copy all files with an .mp4 extension to another location:
find . -type f -iname "*.mp4" -exec cp "{}" /other/location/ \;
Find and print:
Print name, path, size, inode, and sha256 hash.
find . -type f -printf "%f\t %P\t %s\t %i\t " -exec sh -c 'sha256sum "{}" | cut -d " " -f 1 ' \;
Print path, name, size, time accessed, time modified and sha256 hash.
find . -type f -printf "%P\t %s\t %a\t %t\t" -exec sh -c 'sha256sum "{}" | cut -d " " -f 1 ' \;
Search file content:
Find files that contain a particular string.
find . -type f -print0 | xargs -0 grep "string"
Find and convert:
Find all files with a .txt extension and convert them to .doc (LibreOffice required).
find . -type f -name "*.txt" -exec soffice --headless --convert-to doc --outdir /output/directory/ "{}" \;
Merge all the files with an .mp4 extension that are in the current working directory into a single file (ffmpeg required).
find *.mp4 | sed 's:\ :\\\ :g'| sed 's/^/file /' > fl.txt; ffmpeg -f concat -safe 0 -i fl.txt -c copy output.mp4; rm fl.txt
Find and count:
Find and count all .jpeg files.
find . -type f -exec file '{}' \; | grep "JPEG" | wc -l
Find by time:
Created after a particular date (mm/dd/yyyy).
find -type f -newerct "09/01/2023"
Created during the last two days.
find . -type f -ctime -2
Find by permissions:
Find files that can be executed by anyone.
find . -type f -perm 777