Linux Useful Commads

View the list of hidden files (files that begin with a period character .)
use  -a with ls.
eg. ls -la

cd command tricks
cd followed by nothing will change the directory to your home directory.
cd – : changes working directory to previous one.
cd ~zack: changes working directory to my home directory.

 

Useful programs
less
: can be used to view text files   eg. less file-name
file : can be used to get the type of data that a file contains. eg. file file-name

 

tr : translate range of characters into other range of characters.
eg. Translate characters in lowercase to uppercase. tr [a-z] [A-Z]
eg. Translate character a to b and 2 to 3. tr “a2” “b3” < names.txt

 

whoami: current user logged in
who: current user logged in

head :
head abc.txt     # display the first 10 lines
head -n4 abc.txt     # display the first 4 lines of file
head -n-6 abc.txt    # display all the lines except the last 6 lines of file

tail:
tail abc.txt    # display the last 10 lines of the file.
tail -n5 abc.txt    # display the last 5 lines of the file.
tail -n+8 abc.txt     # display from the 8th line till the last.

 

top: To see currently running processes and other information like memory and CPU usage with real time updates.

 

sort: sort the characters
uniq:
removes duplicates by comparing the adjacent values
eg. $ sort < sname | uniq > u_sname

 

bc: it is the calculator program in linux

Value Shown in bc as Shown in Linux Shell as
True/Yes 1 0
False/No 0 Non – zero value

cal : it’s the calendar program

Builtin shell variables:
$# : Gives no. of arguments to command.
$0 : Shell script name
$1, $2 : Argument 1 and 2 to script.
$*, $@ : Gives all the arguments to the script.

eg. Script name is abc
abc hello world
echo “No. of args $#”
echo “First arg $1”
echo “Second arg $2”
echo “Script name $0”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s