Searching files in linux

Posted: June 28, 2012 in Linux
Tags: , , , ,

These are some of the useful commands to search files in linux system.

Consider we need to list all the mp3 files in our system. Use the following command

find / -name *.mp3

Now, we need to find a file which has the name in which some letters are s and e

find / -name *se*

if we need to search in a particular folder, just include the folder path

find Softwares/ -name *se*

Find command is useful but it will take some time to search the system if it contains too many files. Locate is a very simple and powerful command which can be used in place of find.

To find the file abc.txt command is

locate abc.txt

it will scan the system and list the locations where abc.txt is present.

Now, if we need to search in a specific directory just include the folder name.

locate Softwares/ *.txt

okay then why we should use locate command ? both yields the same result..

Its because locate command is too faster than find command. The reason for that is, there is a background process that runs on your system that essentially finds new files and stores them in a database. when you use the locate command, it then searches the database instead of searching your filesystem while you wait.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s