Ubuntu Promising Commands

Chaining two or more commands together gives real power to shell. Hundreds of commands are available but combining them and using in different way is a real game. Lets get a flavor of combination of commands , some automotive and interesting commands. Do you mind taking a ☕ CUP of coffee or tea before you start?

This will tutorial will be based on scenarios. Definitely its going to be interesting one !!

Table of Content

  • Working with Files
  • Working with System Information
  • Working with Process
  • Conclusion

Working with Files

  • How to remove blank lines while you print the output?
cat -sn /proc/cpuinfo      

# Here s means suppress the blank lines and n is number of lines in output
  • How to print the output of several files together?
cat -s file1.txt file2.txt   

# Here s means suppress the blank lines 
  • How to check files and directories size on the disk?
du -ahc /etc/ansible        

# Here a is used to list al files & directories, "h" is human readable and "c" is total size of files.
  • How to exclude files and directories while checking size on the disk?
du --exclude="*.xml" --exclude="*.xsl" 

# Here we are excluding every xml and xls from the list
  • How to redirect the output to new file ?
# Creating new PATH and and storing it in new file i.e. file.txt
echo 'export PATH=$PATH:/usr/local/bin' >> file.txt
  • How to find files that are greater than 100K and owned by particular user ?
# Finding all the txt files that have size greater than 100k and owned by user ubuntu
find /home -name "*.txt" -size 100k -user ubuntu 
  • How to find files with specific permissions ?
# Finding files in /etc/ansible where user,others have read, group has write permissions
find /etc/ansible -perm u=r,g=w,o=r 

# u stands for users, g for group of and o for others 
  • How to search a string in a directory and sub directories?
grep -r "searchme" /etc/* 

# Here we will find searchme in all files and folders under /etc
  • How to ignore specific lines with a condition in a file?
grep -v "searchme" file.txt   

# Here v flag will ignore all those line which contains searchme
  • How to Create a soft link?

Softlinks are are also known as symlink and dumbpointers. It is just a redirect to a real file.

ln -s myfile mylink    

# Here we already have myfile created and we are creating mylink
  • How to sort the files according to size ?
ls --sort size -r *.org  

# Here we already have myfile created and we are creating mylink
  • How to sort the files according to the given column values ?
ls -la | sort -n -k7  

# Here ls -la list the files , n is used to sort numerical values and k denotes which column to sort ( 7th Row ) in below example

Working with System Information

  • How to check devices and storage blocks in your system ?
lshw  # This command has very big output , try to use grep along with it
  • How to list the status of all modules in kernels?

NOTE: Kernel works as a interface between HARDWARE and SOFTWARE . It controls all the processes

lsmod # This is equivalent to /proc/modules
  • How to see the High Level information of the System ?

Working with Process

  • How to check all the running process with sort command ?
ps aux 

# Here a is for all users, x denotes all process attached to terminal and u is user oriented.
ps aux --sort=-%cpu | grep -v `whoami`
ps -eo pid,ppid,user,cmd --sort=-%mem

# Here e is for every active process , o denotes user defined output and we are sorting the memory
ps -ef --sort=-%mem

# Here e is for every active process , f  denotes full listing
  • How to work with fg command ?

Bring the suspended Job in foreground, lets see an example

sleep 100 &    # Run Job in background
jobs           # To check Jobs
fg %1          # Bring background Job in foreground
  • How to work with bg command ?

Bring the suspended Job in Background, lets see an example

sleep 100 then clt+z  # To Suspend the Job
jobs                  # To check Jobs
bg %1                 # Bring stopped Job in background
  • What is top command ?

top command is used to monitor and control process. There are

  • How to Display free memory and used memory of the system?
vmstat 5 10    # Here 5 denotes every 5 seconds and 10 denotes for 10 iterations


In this tutorial you learnt various scenario based ubuntu commands that are useful for every administrator. You learnt how to view process , system information and saw scenario based commands. So, What commands are you going to use in your next assignment ?

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