find:
Command used to find the files on linux environment.
Syntax goes like this
find [starting point] [search criteria] [action]
Some of the ways to search files listed below for reference:
1.Basic usage:
find . -name “*.jpg”
Explanation: find is the command, the dot ‘.‘ means start from the current directory, and the -name “*.jpg” tells find to search for files with .jpg in the name. The * is a wild card.
2.Find all css files in the ‘/var/www‘ directory:
find /var/www -name “*.css” -print
3.Find Files by Size
a.Find all ‘.txt‘ files that are less than 100kb in size.
find . -name *.txt -size -100k -ls
b.Find Files over a GB in size
find ~/Movies -size +1024M
c.Find all files that are over 40kb in size.
find . -size +40k -ls
4.Find and remove Files:
The power comes when you want to apply an action with the search. This command will find all css files and then remove them.
find . -name “*.css”-exec rm -rf {} \;
It is worth noting that find is recursive so be very careful when using the ‘-exec‘ flag. You could accidentally delete all css files in your computer if you are in the wrong directory. It is always a good idea to run find by itself before adding the -exec flag.
No comments:
Post a Comment