linux:find
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:find [2018/05/15 10:43] – Wulf Rajek | linux:find [2025/02/11 21:14] (current) – Wulf Rajek | ||
---|---|---|---|
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: | ||
Line 33: | Line 43: | ||
</ | </ | ||
+ | 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 " | ||
+ | </ | ||
+ | |||
+ | ====== Recursively delete empty directories ====== | ||
+ | < | ||
+ | find . -type d -empty -delete | ||
+ | </ |
linux/find.1526377383.txt.gz · Last modified: 2023/05/29 11:53 (external edit)