How to search and find files in Linux

Posted On Jan 27, 2008 at 5:31 pm

Lost A File?

Cant remember where you pout a file or application on your linux machine? Not to fear, there are multiple search programs in linux to help you find it.

GUI Searching

If your a desktop user and prefer GUI over command line interfaces, then you should use a file manager to search for files such as nautilus or konqueror. Simply press ctrl+f while in a file manager and its own search functions will appear.

Command Line - whereis

This command is useful for finding source, binary, and/or executable files that are associated with man pages. A quick example, lets find out where firefox is installed:

whereis firefox firefox: /usr/bin/firefox /etc/firefox.cfg

Command Line - locate

locate will let you search for files containing any text you want. locate uses a database for searching rather than real-time file traversing so you must first build the locate database of files by running updatedb as root. This process will take some time, but once the database is created, you will be able to search all your files instantly.

You can pipe theoutpute through less to make the ouput pause after each page of results. Example:

locate .mp3 | less

Command Line - find

find is a lot more involved command that allows you to narrow your search dramatically to find exactly what you need. You can narrow your search by a number of modifiers such as groups, permissions, modified dates, etc.

By default, fine will search the current directory recursively.

find /musicfolder/ -iname *awake*.mp3 ./Disturbed/Disturbed_-_Bonus_Tracks/Disturbed - Bonus Tracks/12 Disturbed - Awake.mp3 ./Godsmack/(2000) Awake/02.Awake.mp3 ./Godsmack/Godsmack - Good Times, Bad Times... 10 Years Of Godsmack/06 - Godsmack - Awake.mp3

The above command will look in /musicfolder/ for any files with a name (the iname means case insensitive, name means case sensitive) that contains "awake" and ".mp3" with any characters in front of or behind awake by using the wildcard *

Another useful search ability of find is to locate files modified in the last X amount of days:

find -mtime -10

You can also search for files modified in the last X minutes with

find -mmin -20

You can learn more about all the features and switches by running man find which will load the manual for that command.

This topic has the following tags:

Last 5 Linkbacks

Post Comment

You are replying to cancel reply

Your email address will not be visible to the public

Avatars by Gravatar. Join Gravatar for free to have your avatar shown everywhere you post.