You are on page 1of 4

In this guide, you will find out how to use Linux to find a file or series of files.

You can use the file manager provided with your Linux distribution to search for files. If you are used
to using Windows then a file manager is akin to Windows Explorer. It contains a user interface with a
series of folders which when clicked show the subfolders within those folders and any files that are
contained within.

Most file managers provide a search feature and a method for filtering the list of files.
The best way to search for files is to use the Linux command line because there are many more
methods available to search for a file than a graphical tool could ever possibly attempt to include.

How To Open A Terminal Window
In order to search for files using the Linux command line, you will need to open a terminal window.
There are many ways to open a terminal window as shown in this guide. One way that is sure to work
on most Linux systems is to press the CTRL, ALT and T key at the same time. If that fails to use the
menu on your Linux desktop environment to find the terminal editor.

The Easiest Way To Find A File
The command used to search for files is called find.
Here is the basic syntax of the Find command.
find
The starting point is the folder where you want to start searching from. To start searching the whole
drive you would type the following:

find /
If however, you want to start searching for the folder you are currently in then you can use the
following syntax:
find .
Generally, when searching you will want to search by name, therefore, to search for a file called
myresume.odt across the whole drive you would use the following syntax:
find / -name myresume.odt

The first part of the find command is obviously the word find.
The second part is where to start searching from
The next part is an expression which determines what to find.

The file was last changed n minutes ago  -cnewer . if you want to search for the current file system you can use a full stop as follows: find .The file is executable  -false . The starting position can be literally anywhere on your file system. There are however other expressions you can use as follows:  -amin n .The file was last accessed n minutes ago  -anewer . For example to search for the home folder type the following: find ~ -name game The tilde is a metacharacter commonly used for denoting the home folder of the current user. You will probably need to elevate your permissions using the sudo command or switch to an administrator account using the su command. If you want to search the entire file system then you need to start at the root folder as follows: find / -name game It is likely that the results returned by the above command will show permission denied for many of the results returned.The file was last changed more than n days ago  -empty .Always false .The file was last accessed more recently than it was modified  -atime n . For instance. Expressions The most common expression you will use is -name. The -name expression lets you search for the name of a file or folder.The file is empty  -executable .The file was last accessed more n days ago  -cmin n .Finally the last part is the name of the thing to find. Where To Start Searching From As mentioned briefly in the previous section you can choose any location in the file system to start searching from.The file was last changed more recently than the file was modified  -ctime n . You can find the name of the current folder using the pwd command. -name game The above command will look for a file or folder called the game in all folders under the current folder.

search for a file with the specified name  -newer name .file's data was last modified n minutes ago  -mtime n .search for a symbolic link  -mmin n . You might want to do this if you want to backup and remove old files that you don't access regularly.search for a path  -readable .The file is on the specified file system  -gid n .search for a file with no group id  -nouser .Search for a file but ignore case  -inum n .search for a expression but ignore case  -links n .The file belongs to group with the ID n  -group groupname .find files which are readable  -regex pattern .The file belongs to the named group  -ilname pattern .search for a particular type  -uid uid .files numeric user id is the same as uid  -user name .file is owned by user specified  -writable .search for a file with the specified number of links  -lname name .file's data was last modified n days ago  -name name .  -fstype type .search for a file with the specified node  -ipath path .Search for a symbolic line but ignore case  -iname pattern .search for files that can be written to How To Find Files Accessed More Than A Certain Number Of Day Ago Imagine you want to find all the files within your home folder accessed more than 100 days ago.search for files matching a regular expression  -type type .search for a file edited more recently than the file given  -nogroup .search for a path but ignore case  -iregex expression .search for a file with no user attached to it  -path path . In order to do this run the following command: find ~ -atime 100 How To Find Empty Files And Folders If you want to find all the empty files and folders in your system use the following command: find / -empty How To Find All Of The Executable Files If you want to find all of the executable files on your computer use the following command: find / -exec .

mp3 How To Send Output From Find The Find Command To A File The main problem with the find command is that it can sometimes return too many results to look at in one go.mp3 -fprint nameoffiletoprintto How To Find And Execute A Command Against A File Imagine you want to search for and edit a file at the same time. You can do this by running the following command in the terminal: man find .How To Find All Of The Readable Files To find all of the files that are readable use the following command: find / -read Patterns When you search for a file you can use a pattern. maybe you are searching for all files with the extension mp3. The above command searches for a file called filename and then runs the nano editor for the file that it finds. Summary The find command is very powerful. You can use the following pattern: find / -name *. You can use the following command: find / -name filename -exec nano '{}' \. You can pipe the output to the tail command or you can output the lines to a file as follows: find / -name *. For example. This guide has demonstrated how to search for files but there are a huge number of options available and to understand all of them you should check out the Linux manual.