find
Files
Older than 30 days
_$: find . -mtime +30
Newer than 30 days
_$: find . -mtime -30
Newer than 30 minutes
_$: find . -mmin -30
Older than 30 days and delete them
_$: find . -mtime +30 -delete
_$: find . -mtime +30 -exec rm {} \;
Modified between 01/01/2015 and 08/01/2015
_$: find . -newermt 2015-01-01 ! -newermt 2015-01-08
Modified between 01/01/2015 23:30 and 08/01/2015 22:15
_$: touch -t 1501012330 /tmp/t1
_$: touch -t 1501082215 /tmp/t2
_$: find . -newer /tmp/t1 -not -newer /tmp/t2
With the oldest subdirectory
_$: find . -mindepth 1 -type d -printf '%T+ %p\n' | sort | head -n 1 | cut -d' ' -f2
Bigger than 100 bytes
_$: find . -size +100c
With SUID bit
_$: find . -perm -4000
With SGID bit
_$: find . -perm -2000
That are executable
_$: find . -type f -name "*.py" -executable
That belong to root:root
_$: find . -type f -user root -group root
All symbolic links in this directory
_$: find . -maxdepth 1 -type l
Ignoring a directory
_$: find . -name "*.py" -not -path "./static/*"
_$: find . -name "*.py" -o -path "./static/*" -prune # Faster
With .xml
or .sql
extension
_$: find . \( -name "*.xml" -or -name "*.xml" \) # Beware of the whitespaces
Return true if the file exists, false if it does not exist:
_$: [[ $(find . -type f -name "*.txt" | wc -l) -gt 0 ]] && true || false