find
Table of Contents
- 1. Running
shellcheckrecursively - 2. Truncate the fractional part of
-printf '%T@' - 3. Symbolic links
- 4. Broken symbolic links
- 5. Access date older than
YYYYMMDD - 6. Modification date older than
YYYYMMDD - 7. Modification date is between
YYYYMMDDandYYYYMMDD - 8. Duplicate filenames
- 9. Compare 2 directories by filenames
- 10. Search files by permissions
- 11. Search directories whose permissions are not
755 - 12. ⚠️ Change permissions of files whose permissions are not
664 - 13. References
1. Running shellcheck recursively
find projects/scripts \( -name '.git' -type d -prune \) -o -type f -execdir shellcheck {} +
2. Truncate the fractional part of -printf '%T@'
Using %.n where n is an integer specifying the length of the string you want to keep
find /path/to/dir -type f -printf '%.6T@-%f\n'
3. Symbolic links
find ~/.config -type l
4. Broken symbolic links
find ~/.config -xtype l
5. Access date older than YYYYMMDD
find dir -type f ! -newerat YYYYMMDD
6. Modification date older than YYYYMMDD
find dir -type f ! -newermt YYYYMMDD
7. Modification date is between YYYYMMDD and YYYYMMDD
find dir -type f -newermt YYYYMMDD ! -newermt YYYYMMDD
8. Duplicate filenames
find dir -type f -printf '%f\n' | sort | uniq -d
9. Compare 2 directories by filenames
Comparing remote and local lists: sort files on the same host (see The impact of locales on sorting)
find dir1 -type f -printf '%f\n' > list1.txt find dir2 -type f -printf '%f\n' > list2.txt sort -u list1.txt -o list1.txt && sort -u list2.txt -o list2.txt diff list1.txt list2.txt
10. Search files by permissions
find . -perm 664
11. Search directories whose permissions are not 755
find . -type d ! -perm 755
12. ⚠️ Change permissions of files whose permissions are not 664
find DIR -type f ! -perm 664 -execdir chmod -c 664 {} +