Perpetual PC's

Web Site Design.       Networks.

Commands and references ( GNU / linux kernel 2.4.18-3 and 2.4.18-14 )   
Linux is a registered trademark of Linus Torvalds


The commands with their most common usage are in brackets like this: [ command ].
Don't type the brackets, just what is inside of them.

Back to the index page



search a directory's files for a word:
Lets say you have a website directory with 5000 files and you want to know if one particular page is in there. You know it contains the name Robert. Do this:   [ grep "Robert" * ]
This will search every file in that directory and display each instance of the word Robert. Remember, this command is case sensitive.

search a file (for everything except something)
[ grep -v 64.38 file.name ]
searches the file "file.name" for everything except the expression 64.38

[ grep -v 64.38 file.name > new_file ]
searches the file "file.name" for every thing except the expression 64.38 and sends the results to the file "new_file".

search a file
[ grep 64.38 file.name ]
searches the file "file.name" for the expression 64.38

[ grep 64.38 file.name > new_file ]
searches the file "file.name" for the expression 64.38 and sends the results to the file "new_file".

search for a word in a file in a directory (for example your home directory) tree:
Lets say you are looking for the word foo
try this:   [ grep -r -w "\<foo\>" * > findfoo ]
this will search the directory tree recursively and send the output to the file findfoo. If your directory tree contains many files and directories this file will be huge, so be cautioned.
Once you have the file findfoo, do this:   [ grep foo findfoo ]
this will display the line and the file that the word foo is in. If the word you are searching for is a common word like "the" or "stop" you will get thousands of files with that word in it, so be aware that you may end up with a lot of files to look through. This kind of a search will work best if you are looking for a rather unique word or combination of letters.

if you have a sorted file with a single column structured like this(it could have hundreds of lines)with digits from 0 to 7:
1
---------x
2
--------w-
3
--------wx
4
-------r--
5
-------r-x
6
-------rw-
7
-------rwx
-------rwx
-------rwx
10
------x---
11
------x--x
12
------x-w-
13
------x-wx
14
------xr--

do this to sort out the numbers and non-integer values:
[ grep -o '[01234567]*' ]   this displays all the numbers
[ grep -v '[01234567]' ]   this displays all the non-integer values



Perpetual PC's home page

Perpetual PC's link page