## ## Example of use of the find command ## find ~/ -name 'core*' -exec rm {} \; # Removes all core dump files from user's home directory. find /home/bozo/projects -mtime 1 # Lists all files in /home/bozo/projects directory tree that were modified within the last day. # # mtime = last modification time of the target file # ctime = last status change time (via 'chmod' or otherwise) # atime = last access time DIR=/home/bozo/junk_files find "$DIR" -type f -atime +5 -exec rm {} \; # ^^ # Curly brackets are placeholder for the path name output by "find." # # Deletes all files in "/home/bozo/junk_files" that have not been accessed in at least 5 days. # # "-type filetype", where # f = regular file # d = directory, etc. # (The 'find' manpage has a complete listing.) find . -name '*.*' -mtime +7 -exec echo '{}' \; find . -name "*.*" -mtime +7 -exec echo '{}' \; # Give exactly the same results # But: find . *.* -mtime +7 -exec echo '{}' \; # Gives the same but DOUBLE (i.e. reports twice, once with path in name and once just plain file name) find . -name '*.*' -type f -mtime +7 -exec echo '{}' \; # Displays single instance of the files reports with the prepending directory clash find . -name "*.*" -type f -mtime +7 -exec echo '{}' \; # ditto find . *.* -type f -mtime +7 -exec echo '{}' \; # Reports twice again (i.e. reports twice, once with path in name and once just plain file name)