Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
TetraWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Linux 101 hacks
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=='''Hack 18. Find Command'''== find is frequently used command to find files in the UNIX filesystem based on numerous conditions. Let us review some practice examples of find command. Syntax: find <nowiki>[pathnames] </nowiki><nowiki>[conditions]</nowiki> '''How to find files containing a specific word in its name?''' The following command looks for all the files under /etc directory with mail in the filename. <nowiki># </nowiki>find /etc -name "*mail*" '''How to find all the files greater than certain size?''' The following command will list all the files in the system greater than 100MB. <nowiki># </nowiki>find / -type f -size +100M '''How to find files that are not modified in the last x number of days?''' The following command will list all the files that were modified more than 60 days ago under the current directory. <nowiki># </nowiki>find . -mtime +60 '''How to find files that are modified in the last x number of days?''' The following command will list all the files that were modified in the last two days under the current directory. <nowiki># </nowiki>find . –mtime -2 '''How to delete all the archive files with extension *.tar.gz and greater than 100MB?''' Please be careful while executing the following command as you don’t want to delete the files by mistake. The best practice is to execute the same command with ls –l to make sure you know which files will get deleted when you execute the command with rm. # find / -type f -name <nowiki>*.tar.gz </nowiki>-size +100M -exec ls -l {} \; # find / -type f -name <nowiki>*.tar.gz </nowiki>-size +100M -exec rm -f {} \; '''How to archive all the files that are not modified in the last x number of days?''' The following command finds all the files not modified in the last 60 days under /home/jsmith directory and creates an archive files under /tmp in the format of ddmmyyyy_archive.tar. <nowiki># find /home/jsmith -type f -mtime +60 | xargs tar -cvf /tmp/`date '+%d%m%Y'_archive.tar`</nowiki> On a side note, you can perform lot of file related activities (including finding files) using [http://www.thegeekstuff.com/2008/10/midnight-commander-mc-guide-powerful-text-based-file-manager-for-unix/ ][http://www.thegeekstuff.com/2008/10/midnight-commander-mc-guide-powerful-text-based-file-manager-for-unix/ midnight commander GUI], a powerful text based file manager for Unix.
Summary:
Please note that all contributions to TetraWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TetraWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)