Friday, April 23, 2010

grep: global regular expression print

Some of the most useful unix tools and commands for daily use in a day's life of a system admin...(more to be added, keep checking)

printenv --prints all system and user created env. vairables.

cd ~directory_name -takes you directly to that directory

id --display system id number

tail --display last 10 lines. if tail -20 then display last 20 lines

grep string fileName --display lines with the "string" in the fale called "fileName"

cd ~ --go to home directory

diff {file1} {file2} -- show the differences in file1 and file2

sdiff {file1} {file2} --show files side by side

wc {file} --cound words in a file

df --system disk capacity

du --system disk usage

\\10.5.109.104\c$ to remote access unshared

ps ux --display processes owned by the current user.

kill -9 process_id --will kill the process, -9 here ensures execution.

du -sc * | sort -n | tail -- list size of all the names and sizes of all files and directories, sort in increasing size order, print the last few lines

uname -aspi --enlist the osx kernel etc

grep -r -i somethingtosearchfor ./ --recursively search all files and directories for the string.

find . -exec grep "boo" {} \; --search for string "boo" in every directory below the current directory

tail -n8 fileName | grep "boo" --performs a grep on the last 8 lines of file called "a_file"

find | grep "hello" --will print out the file that find returns that contain the text "hello"

find . -exec grep "boo" {} \; --search for the string "boo" in every directory below the current directory.

grep -c "boo" fileName --will print an integer indicating the number of lines that matched the string "boo"

grep -l "boo" * --searching through multiple files for the same string

grep -x "boo" a_file --searching for eXact matches only.

grep "e$" a_file --search in all lines containg words having the letter "e" as the last letter

No comments:

Post a Comment