Linux find Command - Everything You Need To Know
We all need time to find a file that was taken on a specific date, time, or name. Ever wondered how are you going to find it? Yeah! I assume you might say about the search function in nautilus, pacman, or any other file manager you use, but what if you are not allowed to use it! Your file manager just freezes while searching for lots of files. Well, let’s come to the point. Today you will learn about the famous Linux find Command. What is it? Keep reading.
What is ‘find’ for?
The Command ”find” is use in Linux to search for files having certain name, date, time or whatever criteria you apply to it. You can search for the file modified minutes ago or days ago. You can search for the file that you accessed today or months ago. It all depends on just simple words with this one powerful command “Find”.
Some find Command Illustrations
1. This command will list out all the files in present directory even including its subdirectories.
$ find .
Or
$ find . -print “.print” is used for older UNIX systems. Here “.” is used for the current directory.
2. This command will list out all files under a certain directory. $ find /home -name 3. Ok! Let’s search for a specific file under a specific directory.
$ find /music -name linuxandubuntu.txt
4. Let’s assume you want to know all the specific format files, then this will be useful.
$ find /music -name “*.mp3”
5. Searching for a file, but doesn’t remember the case? Then here is the command to search the file ignoring the case. Just change “name” with “iname”.
$ find /music -iname “*.mp3”
6. When the find option is used it travels down in all subdirectories available which consume our time. So, we can limit the depth of the search by this command. Just add “maxdepth 2”. You can replace “2” with any number of directories.
$ find /music -maxdepth 2 -name abc.mp3
7. Find the file with certain permission isn’t also difficult with find command. Here is how you do it. You can change the perm 0664 with any permission you want.
$ find . type f -perm 0664
Here are some commands that can be used to find files on certain criteria –
$find | /home | abc.mp3 | |||
1 | File modified 10 days ago | -mtime 10 | |||
2 | File accessed 10 days ago | -atime 10 | |||
3 | File belonging to certain user | -user Jay | |||
4 | File changed in last hour | -cmin -60 | |||
5 | File based on size like 10mb | -size 10m | |||
6 | File modified between 10-20 days ago | -mtime +50 -mtime -100 | |||
7 | File between 10mb-20mb | -size +50m -size -100m | |||
8 | Delete certain file | -exec rm -f {} \; | |||
9 | Find hidden file | -type f |
Note:- The delete command should be used after the name of the file not first. There are still many commands that are really useful and helpful. But is find command really simple for a newbie or a user that has encountered for the first time with them? The answer is NO.
Also Read – How To Find Large Files Using Command Line In Linux
Arguments
No matter how powerful the “find” command is, there are many people that argue that “find” command is too complex sometimes to handle to use without any help. I decided to test this theory and I found that this theory is also right. I mean to delete a single file that is willing to enter an almost whole line of command? No, a regular Linux user who wants to use Linux for his daily music, video, and pics are not going after this. If you have been a developer or a Linux commands master you can easily achieve this. I myself didn’t know all the command and thus I was forced to look into GNU for “find” commands.
So, my overall reaction is that find commands are useful but for much complex work a newbie or home user or your old parents really can’t afford that depth knowledge. Also if you want to search your whole PC, “find” command requires time as it doesn’t index file rather depends on a fresh search assuming you have modified your PC even just last second which is unimpressive.
Options
The options for rescue are also here if you don’t want to mess with the “find” command.I found that the built-in search function also performs decently if you just want to search some file with the specific name. Also, there are certain apps that can be installed in your Linux OS for search facilities like gnome-search tool, Catfish also gets the job done easily. Although gnome-search tool is slow, which I didn’t like but it’s better than using that command line interface every time.
My Own Searches/Examples
Here are the two screenshots of my own searches with this more or less awesome “find” command in my Linux Mint 18.1 including catfish.
Above I searched for my song system-wide rather than typing whole messy location. It took approx 50 sec to find that song.
Catfish was rather easy in search of location, type and other things to enter. The overall search took 15sec. I accept system-wide search would have taken much time but I am sure it would less than 50 sec.
Conclusion
Well! Overall I was impressed by “find” command, but it is not so easy and fast. Rather I would have 1st option to Catfish as it is really easy but at the same time it is not powerful as per the “find” command and it would be wrong to say that any app could replace the “find” command completely. ”find” command is more or less last resort helper and rescuer and it has truly no replacement.