Linux important commands illustrations examples



 |  

In this article we will explain the usage of important linux commands with examples. We have divided all the commands into categories and we will illustrate them one by one using a linux operating system.

Online courses related to this article


Course description

Learn to develop embedded systems, interfacing electronic peripherals through real time projects and get required practical skills for software jobs



Course description

Learn to develop software solutions for linux environment, implement requirements through real time projects and get required practical skills for software jobs

I have executed the commands using a raspberry pi. You can execute the commands listed in this article using virtualbox simulation environment.

Article contents

File System Commands

System Info Commands

Process Management Commands


File System Commands

ls, ls -al, ls -lt
    ls is a basic linux file system command to list down the files and directories in the current directory. ls will not show the timing of change of the file and directory content and their permissions. You can see the permissions using ls -al. In the illustration below you can see Calculator is having read, write and executable permission where as add.c is having read and write permission. ls -lt will list the content same as ls -al but it will sort the formatted listing by time modification. As you can see from the illustration below Calculator is modified last at 04.41 hence listed at the top and add.c is listed at the bottom.
Linux file system command illustrations

pi@raspberrypi:~/C $ ls
add.c  Calculator  divide.c  libcalc.so  multiply.c  subtract.c
add.o  common.h    divide.o  main.c      multiply.o  subtract.o
pi@raspberrypi:~/C $ ls -al
total 68
drwxr-xr-x  2 pi pi 4096 Jun 28 04:41 .
drwxr-xr-x 31 pi pi 4096 Jun 27 07:50 ..
-rw-r--r--  1 pi pi   42 Jun 28 04:24 add.c
-rw-r--r--  1 pi pi  860 Jun 28 04:37 add.o
-rwxr-xr-x  1 pi pi 8380 Jun 28 04:41 Calculator
-rw-r--r--  1 pi pi   94 Jun 28 04:27 common.h
-rw-r--r--  1 pi pi   49 Jun 28 04:25 divide.c
-rw-r--r--  1 pi pi  952 Jun 28 04:37 divide.o
-rwxr-xr-x  1 pi pi 7968 Jun 28 04:34 libcalc.so
-rw-r--r--  1 pi pi  343 Jun 28 04:40 main.c
-rw-r--r--  1 pi pi   51 Jun 28 04:25 multiply.c
-rw-r--r--  1 pi pi  872 Jun 28 04:37 multiply.o
-rw-r--r--  1 pi pi   47 Jun 28 04:24 subtract.c
-rw-r--r--  1 pi pi  872 Jun 28 04:37 subtract.o
pi@raspberrypi:~/C $ ls -lt
total 60
-rwxr-xr-x 1 pi pi 8380 Jun 28 04:41 Calculator
-rw-r--r-- 1 pi pi  343 Jun 28 04:40 main.c
-rw-r--r-- 1 pi pi  952 Jun 28 04:37 divide.o
-rw-r--r-- 1 pi pi  872 Jun 28 04:37 multiply.o
-rw-r--r-- 1 pi pi  872 Jun 28 04:37 subtract.o
-rw-r--r-- 1 pi pi  860 Jun 28 04:37 add.o
-rwxr-xr-x 1 pi pi 7968 Jun 28 04:34 libcalc.so
-rw-r--r-- 1 pi pi   94 Jun 28 04:27 common.h
-rw-r--r-- 1 pi pi   49 Jun 28 04:25 divide.c
-rw-r--r-- 1 pi pi   51 Jun 28 04:25 multiply.c
-rw-r--r-- 1 pi pi   47 Jun 28 04:24 subtract.c
-rw-r--r-- 1 pi pi   42 Jun 28 04:24 add.c
pi@raspberrypi:~/C $

pwd, cd, cd dir, mkdir dir, touch, rm, rm -rf, cp, mv
    pwd is the command to see your current working directory. in the illustration below it shows I am in /home/pi/C directory. cd ../ will move one directory down where as cd dir Change directory to dir. Similaryly ../../ will change directory to two levels down.
    mkdir dir will create a new directory dir where as rmdir dir will delete directory dir from your current directory. rm file will delete a file. Also note that I have created a directory New and created a file inside it using touch command and then tried to delete the New directory. But it failed saying directory is not empty. In this case we use -rf option to force directory deletion.
    cp is the command used to move a file or directory from one directory to another. In the illustration I have moved the subtract.c from current directory to /home/pi/try directory. mv command is used to rename a file. In the illustration file.c is renamed as file1.c.
Linux file system command illustrations

pi@raspberrypi:~/C $ pwd
/home/pi/C
pi@raspberrypi:~/C $ cd ..
pi@raspberrypi:~ $ pwd
/home/pi
pi@raspberrypi:~ $ cd C
pi@raspberrypi:~/C $ pwd
/home/pi/C
pi@raspberrypi:~/C $
pi@raspberrypi:~/C $ cd ../../
pi@raspberrypi:/home $ pwd
/home
pi@raspberrypi:/home $
pi@raspberrypi:/home $ cd pi/C
pi@raspberrypi:~/C $ mkdir NewDir
pi@raspberrypi:~/C $ ls
add.c  add.o  Calculator  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  NewDir  subtract.c  subtract.o
pi@raspberrypi:~/C $ rmdir NewDir/
pi@raspberrypi:~/C $ ls
add.c  add.o  Calculator  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  subtract.c  subtract.o
pi@raspberrypi:~/C $
pi@raspberrypi:~/C $ rm Calculator
pi@raspberrypi:~/C $ ls
add.c  add.o  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  subtract.c  subtract.o
pi@raspberrypi:~/C $
pi@raspberrypi:~/C $ mkdir New
pi@raspberrypi:~/C $ ls
add.c  add.o  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  New  subtract.c  subtract.o
pi@raspberrypi:~/C $ cd New
pi@raspberrypi:~/C/New $ touch file.c
pi@raspberrypi:~/C/New $ vi file.c
pi@raspberrypi:~/C/New $ vi file.c
pi@raspberrypi:~/C/New $ cd ..
pi@raspberrypi:~/C $ rmdir New/
rmdir: failed to remove 'New/': Directory not empty
pi@raspberrypi:~/C $
pi@raspberrypi:~/C $ rm -rf New
pi@raspberrypi:~/C $ ls
add.c  add.o  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  subtract.c  subtract.o
pi@raspberrypi:~/C $ ls
add.c  add.o  common.h  divide.c  divide.o  libcalc.so  main.c  multiply.c  multiply.o  subtract.c  subtract.o
pi@raspberrypi:~/C $ cp subtract.c /home/pi/try/
pi@raspberrypi:~/C $ cd /home/pi/try/
pi@raspberrypi:~/try $ ls
a.out  file.c  subtract.c
pi@raspberrypi:~/try $ mv file.c file1.c
pi@raspberrypi:~/try $ ls
a.out  file1.c  subtract.c
pi@raspberrypi:~/try $
cat, tail, more, head

To Read Full Article

Subscribe courses or Pay Per Course & logged in




Want to contribute or ask a new article? Write and upload your article info .
 |  
Share


 Articles

 Linux Software

 C Programming

 Search Code Snippets

 Popular C search examples

 Popular C search MCQs



 Online certificate courses

 Test your skills:online tests

 C Programming

 Python Programming

 Linux Software

 Quantitative Aptitude

 Embedded System Software