Unix Commands Flashcards
Basic utilities are
grep, sed, awk, etc
grep stands for
global regular expression print
basic grep command
grep “searchtext” filename
grep -n “searchtext” filename
shows the matched text with line numbers
grep -vn “searchtext” filename
shows the results and the lines that don’t match the searchtext
grep - c “searchtext” filename
suppress printing of the matching lines but display only the number
grep -l “searchtext” *
shows the file name in which the searchtext is found
grep -i “SEARCHTEXT” filename
ignores the case and displays the results
grep -x “searchtext” filename
displays only the exact match
grep -A2 “searchtext” filename
displays the matched text plus additional two rows
% ls
lists the contents of your current working directory whose name doesn’t begin with a dot (.)
% ls -a
to list all files in your home directory including those that begin with a dot (.)
% mkdir
to make a sub directory
% cd
to change to a directory
% cd .
in unix . means current directory. this command is to stay in the same directory
. .
two dots means parent of the current directory
% cd ..
will take you one directory up the hierarchy
print working directory
pwd
% pwd
prints the full path of the working directory
% cd ~
change to home directory; same as cd
% cd . .
change to parent directory
cp file1 file 2
copy file1 and call it file2
mv file1 file2
move or rename file1 to file2
rm file
remove a file
rmdir directory
remove a directory
cat file
display a file
more file
display a file one page at a time
head file
display the first few lines of a file
tail file
dsplay the last few lines of a file
wc file
count the number of lines/words/characters in file