- Find files which have been modified for more than or less than a certain time We can use 'find * -mtime n' to search files under current directory based on modification time. The numeric argument n can be specified as +n, meaning greater than n days; -n, meaning less than n days; or n, meaning exactly n days. For example,
to find files which were last modified for more than 30 days ago
find . -mtime +30to find files which were last modified for less than 15 days ago
find . -mtime -15to find files which were last modified for exactly 10 days ago
find . -mtime 10There are other options like
-mmin n, which refers to file's data was last modified n minutes ago -amin n, which refers to file's data was last accessed n minutes ago -atime n, which refers to file's data was last accessed n days ago -type f, which searches for regular file -type d, which searches for directory, -exec command, which executes command by passing in the find results, -perm /mode, which searches files with given permission
find /some-dir/* -mtimes +30 -type f -exec rm {} \;'-exec' is used to pass in commands like 'rm'; '{}' is replaced by the file name that 'find' returns; and the '-exec' command has to end with '\;'.
Another way will be
find /some-dir/* -mtimes +30 -type f -print0 | xargs -0 rmwhere 'xargs' reads 'find' results and execute 'rm' on each of the 'find' results
find . -name "*.txt" -print | xargs grep "some-string"
No comments:
Post a Comment