find

Table of Contents

1. Running shellcheck recursively

find repos/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. References