Finding files in Linux System

By | October 25, 2018

Finding files in Linux System

Finding files in Linux System:

How can you find files whose location you have forgotten?
That is, you know it exists but don’t know in which directory it is located.You could
always visit each directory on the system in turn and use the ls command in each.
This would be very laboroius and could take quite some time.

Fourtunitly there is couple of commands available to help in this task.

The first one is called “find”.
Forexample: To find all the files in directory called “mydirecotry” and all its
subdirectories enter the following command.

find mydirectory -print

To find a particular file enter the following command:

find mydirectory -print -name filename

//find command directory name in which you are finding file -print -name filename

To find all files matching a pattern you can use wildcards, but in this case we want
to pass the wildcards to the find command,rather then let the shell expand them.

This is because the shell only looks in one directory when expanding wildcards and
unless the files we are searching are in the current directory, the expansion will
not help us.
To passs wild cards directly to a command without letting the shell expand them,we
can enclose them in single quotes ‘like this’.
So, to find all files beginning with ‘b’ in the current directory, and all subdirectories
, use the following command.

find . -print -name ‘b*’

Note: In find command . is used mean the current directory like: find . -print

Only use single quotes or apostrophe for wildcards.

Leave a Reply

Your email address will not be published. Required fields are marked *