Browsing files.
Looking for file names
Perhaps you can remember this: You had some kind of file and could not remember where you put it.
This is where the command is to find useful. How to use? find is, of course, an extensive man page, but let's see some "typical": Find a file called lostfile.txt, covering the directory tree starting in the current directory:
find. lostfile.txt-name-print
Find also accepts wildcards. Remember to put the wildcards in quotes, otherwise the shell will not recognize them as such. Here's an example:
find. -name "lost *"-print
This command can be a bit slow when you need to search a large directory tree. You can help locate the command. This really does not look for a file directly to the file system. Search a database. It is quite fast but the database could be outdated. In some distributions located database is updated every night but you can, of course, run the command updatedb manually from time to time to update. locate searches substrings.
locate lostfile
This lostfile.txt locate files or mylostfile.txt, etc ...
Until now we were looking for files which had a remote idea of their names. Perhaps the file name was not lostfile.txt but lastfile.txt or leastfile.txt or lostfile.txt or Lostfile.txt or lostfile.text and can not remember the exact name. How can you find the file yet? in this case could use a utility to find files that tolerates faults in the writing of the name calling ftff (fault tolerant file find). This utility searches for the file and allows a number of errors in writing. " This command will find the misspelled names of the files:
ftff lostfiles.txt
The number of possible errors in the writing of the name depends on the length of it but also can be set with-t. To allow a maximum of 2 errors and also use a wildcard, just type:
ftff-t2 "lostfiles *"
ftff is a program of my authorship and is part of a package called whichman-1.4 that can be downloaded from
sunsite.unc.edu / pub / Linux/apps/doctools/whichman-1.4.tar.gz
Sometimes you want to find all the files in the directory tree that does not contain a certain string. For example all files except. O. C. Here are a couple of chances to do so:
find. ! -name "*. o"! -name "*. c"-print
find. -print | fgrep-v. 'or' | fgrep-v. 'c'
if you have the GNU version of find: find | fgrep-v. 'or' | fgrep-v. 'c'
Find | egrep-v '\. [c]'
Getting a full view of the filesystem
Sometimes you would get a total view of the file system against you. For example: You have a new CD and wanted to see what you have. You could just use ls-R. Personally I prefer easy reading by one of the following: draw a tree diagram tree (sunsite.unc.edu / pub / Linux / utils / file / tree-1.2.tgz).
tree
or long file names: tree-FF
It is also of course the old, but good find. The GNU version of find, which usually comes with Linux, also has the potential to change the print format for printing, such as the size of the file with the name:
find. -ls
find. gnu-print or find: find
find. -printf "% 7s% p \ n"
There is also a small perl program using the ls command does things like that. You can download it here: lsperl. You can probably find many more tools to view files, but this is, for most cases sufficient.
Finding files by content (searching for text strings in files)
The standard utilities to search for text strings in files are grep / egrep search for regular expressions to search for strings and fgrep literals. To find an expression in all the files in the current directory just type:
egrep-i "search expression" *
To search all files in chains around the tree to find the command you can combine with another search command file, for example: egrep. This can be done in many ways:
egrep-i "expression" `find. -type f-print `
find. -type f-exec egrep-i "expression" / dev / null () \;
find. -type f-print | xargs egrep-i "expression"
If you find this hard to remember then you can use a small shell script that can be found here grepfind This script also ensures that non-printable characters are removed if you run into a binary file egrep.
A search program is very interesting AGREP. This basically works as egrep searches but they tolerate errors in the writing of the name. This way you can also find misspelled words. To find an expression with a maximum of two mistakes you can write:
-2 AGREP-i "search exprission" *
The program can be downloaded from AGREP sunsite sunsite.unc.edu / pub / Linux / util s/text/agrep-2.04.tar.Z or its original site ftp://ftp.cs.arizona.edu/agrep/
Also glimpse. This is a powerful search utility. Uses a similar concept to locate. First, a database needs to be built so that the searches are fast. To build a search index of the contents of all files starting in the current directory:
glimpseindex.
After that you can search a string in all files that were previously indexed
-2 glimpse-i "search exprission"
Also glimpse tolerate typing errors (like AGREP) -2 and allowed two errors. glimpse is available in http://glimpse.cs.arizona.edu/
There are many search tools available for Unix and Linux in particular. Therefore this article may not be complete. If these tricks and more interested in profits as they take a look at the files. Ftp://sunsite.unc.edu/pub/Linux/utils in lsm.