I'd like to put in the list some useful commands for finding things in Linux environment.
apropos keywords
- searches through manual descriptions for the keywords. Say, we are interested in commands to find anything:
$ apropos find search look locate match
what gives out a list of related commands with short helpful description. On my Mepis 8.0 virtual machine it shows the following lines among others:
...
apropos (1) - search the manual page names and descr...
look (1) - display lines beginning with a given string
find (1) - search for files in a directory hierarchy
grep (1) - print lines matching a pattern
kfind (1) - KDE find tool
locate (1) - list files in databases that match a pat...
rgrep (1) - print lines matching a pattern
whereis (1) - locate the binary, source, and manual pa...
which (1) - locate a command
...
apropos will work only if manuals are installed - usually they are, but sometimes for the sake of resource saving manuals can be omitted.
find
is a very powerful command for searching files in directories:
$ find startdir -name filename
Different options allow to search for files by name, size, type, permission, owner, etc. - check manual and help:
$ man find
$ find --help
grep
searches for a pattern inside text file:
grep "pattern" filename
Example of finding files and then find a pattern inside the files:
$ find /home/svn -name "test*txt"|xargs grep "first" -i
The first line of the test file.
There are some variations of grep as fgrep, rgrep, egrep, bzgrep, etc. - check it with "apropos grep".
kfind
is a GUI version of find with grep - it can search for files and pattern inside files.
look
prints out strings beginning with a pattern from a file:
$ look pattern filename
strings
prints out all strings from a text or binary file:
$ strings filename
whereis
locates different type of files. For instance:
$ whereis find
find: /usr/bin/find /usr/share/man/man1/find.1.gz
locate
searches for files in databases (it gives out all files with names containing given keyword):
$ locate find
which
search for executables and shows up the whole path to directories where the files are found:
$ which find
/usr/bin/find
0 comments:
Post a Comment