Unix/Linux Important Command Reference

Unix/Linux Command Reference

Introduction: This post contains important commands which required most of time when user work on Unix machine. Find commands with description below –

**************************************************************

File Commands

**************************************************************

ls Directory listing
ls -al Formatted listing with hidden files
cd dir Change directory to dir
 cd  Change to home
pwd   Show current directory
 mkdir dir Create a directory dir 
 rm file  Delete file
 rm -r dir  Delete directory dir
rm -f file Force remove file
rm -rf dir Force remove directory dir *
cp file1 file2 Copy file1 to file2
cp -r dir1 dir2 Copy dir1 to dir2; create dir2 if it
doesn’t exist
mv file1 file2 Rename or move file1 to file2
if file2 is an existing directory, moves file1 into
directory file2
 ln -s file link  Create symbolic link link to file
touch file Create or update file
cat > file Places standard input into file
more file Output the contents of file
head file Output the first 10 lines of file
tail file Output the last 10 lines of file
tail -f file Output the contents of file as it
grows, starting with the last 10 lines

 

**************************************************************

Process Management

**************************************************************

ps Display your currently active processes
top Display all running processes
kill pid Kill process id pid
killall proc Kill all processes named proc *
bg Lists stopped or background jobs; resume a
Stopped job in the background
fg Brings the most recent job to foreground
fg n Brings job n to the foreground

 

**************************************************************

File Permission

**************************************************************

chmod octal file Change the permissions of file
to octal, which can be found separately for user,
group, and world by adding:
● 4 – read (r)
● 2 – write (w)
● 1 – execute (x)
Examples:
chmod 777 – read, write, execute for all
chmod 755 – rwx for owner, rx for group and world
For more options, see man chmod.

**************************************************************

SSH

**************************************************************

ssh user@host Connect to host as user
ssh -p port user@host Connect to host on port
port as user
ssh-copy-id user@host Add your key to host for
user to enable a keyed or passwordless login

**************************************************************

Searching

**************************************************************

grep pattern files Search for pattern in files
grep -r pattern dir Search recursively for
pattern in dir
command | grep pattern Search for pattern in the
output of command
locate file Find all instances of file

**************************************************************

System Info

**************************************************************

date Show the current date and time
cal Show this month’s calendar
uptime Show current uptime
w Display who is online
whoami Who you are logged in as
finger user Display information about user
uname -a Show kernel information
cat /proc/cpuinfo Cpu information
cat /proc/meminfo Memory information
man command Show the manual for command
df Show disk usage
du Show directory space usage
free Show memory and swap usage
whereis app Show possible locations of app
which app Show which app will be run by default

**************************************************************

Compression

**************************************************************

tar cf file.tar files Create a tar named
file.tar containing files
tar xf file.tar Extract the files from file.tar
tar czf file.tar.gz files Create a tar with
Gzip compression
tar xzf file.tar.gz Extract a tar using Gzip
tar cjf file.tar.bz2 Create a tar with Bzip2
compression
tar xjf file.tar.bz2 Extract a tar using Bzip2
gzip file Compresses file and renames it to
file.gz
gzip -d file.gz Decompresses file.gz back to
file

**************************************************************

Network

**************************************************************

ping host Ping host and output results
whois domain Get whois information for domain
dig domain Get DNS information for domain
dig -x host Reverse lookup host
wget file Download file
wget -c file Continue a stopped download

**************************************************************

Shortcuts

**************************************************************

Ctrl+C Halts the current command
Ctrl+Z Stops the current command, resume with
fg in the foreground or bg in the background
Ctrl+D Log out of current session, similar to exit
Ctrl+W Erases one word in the current line
Ctrl+U Erases the whole line
Ctrl+R Type to bring up a recent command
!! Repeats the last command
exit Log out of current session

Leave a Reply

Your email address will not be published. Required fields are marked *