Linux Commands

Some important Linux Commands

Here I am going to add some important Linux commands which is very important in our day to day IT professional activities. I hope this is useful for you.

cd

This commands is use to change the directory. Like this:-

[[email protected] ~]# cd /home/
[[email protected] home]# pwd
/home
[[email protected] home]# cd /
[[email protected] /]# pwd
/
[[email protected] /]#

pwd

It gives us the absolute path, which means the path  starts from the root.The root is the base of the Linux file system. It is denoted by a forward slash( / ). Like this:-

[[email protected] log]# cd /var/log
[[email protected] log]# pwd
/var/log
[[email protected] log]#

df -h

Its gives details of directories like directories size, used size and available size.

[[email protected] log]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 50G 855M 50G 2% /
devtmpfs 2.9G 0 2.9G 0% /dev
tmpfs 2.9G 0 2.9G 0% /dev/shm
tmpfs 2.9G 8.5M 2.9G 1% /run
tmpfs 2.9G 0 2.9G 0% /sys/fs/cgroup
/dev/mapper/centos-home 94G 33M 94G 1% /home
/dev/sda1 497M 125M 373M 25% /boot
tmpfs 581M 0 581M 0% /run/user/0
[[email protected] log]#

ls

Its provide list of files in current directory and files of provided directory. Like this:-

[[email protected] log]# ls
anaconda btmp dmesg.old messages spooler wpa_supplicant.log
audit cron lastlog ppp tallylog wtmp
boot.log dmesg maillog secure tuned
[[email protected] log]# ls /var/log
anaconda btmp dmesg.old messages spooler wpa_supplicant.log
audit cron lastlog ppp tallylog wtmp
boot.log dmesg maillog secure tuned
[[email protected] log]#

ls -la

You can use this command to display hidden file. The hidden file start from .file-name. Like this:-

[[email protected] ~]# pwd
/root
[[email protected] ~]# ls
anaconda-ks.cfg
[[email protected] ~]# pwd
/root
[[email protected] ~]# ls -la
total 36
dr-xr-x---. 2 root root 4096 May 11 17:14 .
dr-xr-xr-x. 17 root root 4096 May 11 09:13 ..
-rw-------. 1 root root 1395 May 11 09:14 anaconda-ks.cfg
-rw-------. 1 root root 430 May 11 17:14 .bash_history
-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc
-rw-r--r--. 1 root root 100 Dec 29 2013 .cshrc
-rw-r--r--. 1 root root 129 Dec 29 2013 .tcshrc
[[email protected] ~]#

mkdir

You can use mkdir command to create directory. Like this:-

[[email protected] home]# mkdir test
[[email protected] home]# ls -l
total 0
drwxr-xr-x. 2 root root 6 May 11 17:37 test
[[email protected] home]#

touch

You can use touch command to create empty file. Like this:-

[[email protected] home]# touch test2
[[email protected] home]# ls -l
total 0
drwxr-xr-x. 2 root root 6 May 11 17:37 test
-rw-r--r--. 1 root root 0 May 11 17:40 test2
[[email protected] home]#

cat

You can use cat command to display files. Let’s display file with cat commands, which we have just created and show how its work.

[[email protected] home]# cat test2
[[email protected] home]#

its nothing returning its means our test2 file is empty.

[[email protected] ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[[email protected] ~]#

vi

You can use vi command to edit the file let see how to edit the file. First of all you have to type vi test2 and enter then your test2 file will be open once a file open then you have to type i to go to edit mode and now you can type any word like:- “this is my test2 file” if you want to save this file you have to type wq! then your file will be save. Like this:-

[[email protected] home]# vi test2
This is my test2 file

~
~
~
~
:wq!

copy

You can use copy command to copy  files or directory from source directory to destination directory. Like this:-

[[email protected] home]# cp test2 /tmp/
[r[email protected] home]# cd /tmp/
[[email protected] tmp]# ls -l
total 4
-rwx------. 1 root root 827 May 11 09:14 ks-script-PBlwED
-rw-r--r--. 1 root root 0 May 11 18:00 test2
-rw-------. 1 root root 0 May 11 09:11 yum.log
[[email protected] tmp]#

move

You can use move command to move files or directories from source directory to destination directory. Like this:-

[[email protected] home]# mv test2 /home/test
[[email protected] home]# cd /home/test
[[email protected] test]# ls -l
total 0
-rw-r--r--. 1 root root 0 May 11 17:40 test2
[[email protected] test]#

rmdir

You can use rmdir command to remove directory. But first you have to remove files from parent directory then you can delete parent directory. Like this:-

[[email protected] home]# rmdir test
rmdir: failed to remove ‘test’: Directory not empty
[[email protected] home]#

rm

You can use rm command to remove the files. Like this:-

[[email protected] home]# cd test

[[email protected] test]# ls -l
total 0
-rw-r--r--. 1 root root 0 May 11 17:40 test2
[[email protected] test]# rm test2
rm: remove regular empty file ‘test2’? y
[[email protected] test]# ls -l
total 0
[[email protected] test]# cd ..
[[email protected] home]# ls -l
total 0
drwxr-xr-x. 2 root root 6 May 11 18:18 test
[[email protected] home]# rmdir test
[[email protected] home]# ls -l
total 0
[[email protected] home]#

file

You can use file command to identify types of file. Like this:-

[[email protected] log]# file /var/log//messages
/var/log//messages: UTF-8 Unicode text
[[email protected] log]# file /etc/hosts
/etc/hosts: ASCII text
[[email protected] log]#