Sunday, October 4, 2009

Linux - Finding A File


Linux - Finding A File
Find Command
The find command can be used to find a file that is stored somewhere in the file system. It is a very complicated command with lots of options, so I will only show you the most basic command. Suppose you know there is a file named mlocate.db somewhere in the file system but you don't know where. The command to type would be,
$ find / -name mlocate.db
This command tells the find program to start at the root directory (the / part) and search for a file a filed named (-name) mlocate.db. It should be noted that a *nix installation might have 10,000 or more files in the file system, so this command could run for quite a long time before it finds the file. If you have a hunch that the file you are looking for is in a subdirectory below root, say /usr, then you could narrow down your search by typing,
$ find /usr –name mlocate.db
Now, only the directory /usr and its subdirectories will be searched. To perform a case-insensitive search on the file use -iname option rather than -name.
Locate Command
You can also try the locate command,
$ locate whereis
If this does not work, you must first build the database with the command,
$ slocate -u
This will create a file that indexes all the files for fast lookup (may take several minutes)
Whereis Command
You can also try the whereis command to locate binary(executable files/commands) and their man pages,
$ whereis ls
This will locate the command ls and the respective man pages.

No comments:

Post a Comment