linux:find
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| linux:find [2017/11/25 20:02] – created Wuff | linux:find [2025/05/19 12:15] (current) – [Recursively changing extension] Wuff | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== find examples ====== | ====== find examples ====== | ||
| + | |||
| + | General note to '' | ||
| + | The following executes program and sends a space separated list of quoted filenames to it. Program may be called multiple times if the amount of arguments exceeds ARG_MAX. | ||
| + | < | ||
| + | |||
| + | The following executes program with one! quoted filename, then executes program again with the next etc. | ||
| + | < | ||
| + | |||
| + | |||
| + | |||
| Find and extract all rar files in subfolders into the current folder: | Find and extract all rar files in subfolders into the current folder: | ||
| < | < | ||
| find . -name *.rar -exec unrar x {} \; | 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 ' | ||
| + | </ | ||
| + | |||
| + | Find directories containing ONLY files older than 30 days (not working with subdirs properly): | ||
| + | < | ||
| + | find . -type f -mtime +30 -printf ' | ||
| + | find . -type f -mtime -30 -printf ' | ||
| + | grep -vf new.txt old.txt | ||
| + | </ | ||
| + | |||
| + | Remove all old temporary MS Office lock files: | ||
| + | < | ||
| + | find . -type f -mtime +10 -name " | ||
| + | </ | ||
| + | |||
| + | Show top level folders and full file count and file count> | ||
| + | < | ||
| + | find . -maxdepth 1 -type d -print0 -exec echo -n " " \; -exec sh -c "find ' | ||
| + | </ | ||
| + | |||
| + | Convert tabs to spaces at the beginning of lines in source code: | ||
| + | < | ||
| + | find . -iname ' | ||
| + | </ | ||
| + | Better with ' | ||
| + | < | ||
| + | find . -iname ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | Fixing permissions of directories / files of a path: | ||
| + | < | ||
| + | find / | ||
| + | find / | ||
| + | </ | ||
| + | |||
| + | Recursive file renaming (e.g. from " | ||
| + | < | ||
| + | #NOTE: use -n in rename parameter to test! | ||
| + | find . -type f -name " | ||
| + | </ | ||
| + | |||
| + | Recursive file renaming extension (e.g. from " | ||
| + | < | ||
| + | find . -type f -name ' | ||
| + | </ | ||
| + | |||
| + | |||
| + | Move files in subdirectories to other directory while retaining directory structure | ||
| + | < | ||
| + | find . -maxdepth 2 -type f -print | cpio -pvdumB / | ||
| + | |||
| + | #Do this for each directory | ||
| + | for d in */; do | ||
| + | cd $d; find . -maxdepth 2 -type f -print | cpio -pvdumB / | ||
| + | done | ||
| + | |||
| + | #If directory must not have trailing /, use this in substitution | ||
| + | ${d%/*} | ||
| + | |||
| + | delete empty directories: | ||
| + | find / | ||
| + | </ | ||
| + | |||
| + | ====== Replace spaces with underscores ====== | ||
| + | Mass replace spaces with underscores | ||
| + | < | ||
| + | for file in *; do mv " | ||
| + | </ | ||
| + | |||
| + | ====== Find largest subdirectories ====== | ||
| + | < | ||
| + | du -hd1 | sort -h | ||
| + | </ | ||
| + | |||
| + | ====== Recursively changing extension ====== | ||
| + | < | ||
| + | find . -type f -name " | ||
| + | |||
| + | find . -type f -name ' | ||
| + | </ | ||
| + | |||
| + | ====== Recursively delete empty directories ====== | ||
| + | < | ||
| + | find . -type d -empty -delete | ||
| </ | </ | ||
linux/find.1511640151.txt.gz · Last modified: (external edit)