Count files

Howto count files in a directory (wc will count the lines)

find . | wc -l

if you want only files, use:

find . -not -type d | wc -l

and if you don't want to dive into subdirectories:

find . -not -type d -maxdepth 1 | wc -l

Find files at specific age

Important to know:

Numeric arguments can be specified as
for greater than n,
for less than n,
for exactly n.

Delete all files not modified 180 days before:

find . -mtime +180 -exec /bin/rm {} \;

Or use the builtin delete:

find /var/lib/puppet/reports -type f -mtime +7 -delete

Print all files modified within the last 60 minutes:

find . -mmin -60 -print

Show disk usage

Print which directories in the current directory occupy how much space (in megabytes):

find . -maxdepth 1 -type d -exec du -ms {} \; | sort -nr

Change ownership

To change the ownership of files spread all over your harddrive the following command is very handy:

find /path/to/files -uid 1001 -print0 | xargs -0 chown www-data

Search htm(l) and php files

Search for *.htm *.html and *.php all at once:

find . -name \*.htm* -o -name '*.php'
linux/find.txt · Last modified: 2014-10 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready