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:-

[root@urclouds ~]# cd /home/
[root@urclouds home]# pwd
/home
[root@urclouds home]# cd /
[root@urclouds /]# pwd
/
[root@urclouds /]#

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:-

[root@urclouds log]# cd /var/log
[root@urclouds log]# pwd
/var/log
[root@urclouds log]#

df -h

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

[root@urclouds 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
[root@urclouds log]#

ls

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

[root@urclouds log]# ls
anaconda btmp dmesg.old messages spooler wpa_supplicant.log
audit cron lastlog ppp tallylog wtmp
boot.log dmesg maillog secure tuned
[root@urclouds 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
[root@urclouds log]#

ls -la

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

[root@urclouds ~]# pwd
/root
[root@urclouds ~]# ls
anaconda-ks.cfg
[root@urclouds ~]# pwd
/root
[root@urclouds ~]# 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
[root@urclouds ~]#

mkdir

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

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

touch

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

[root@urclouds home]# touch test2
[root@urclouds 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
[root@urclouds 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.

[root@urclouds home]# cat test2
[root@urclouds home]#

its nothing returning its means our test2 file is empty.

[root@urclouds ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@urclouds ~]#

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:-

[root@urclouds 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:-

[root@urclouds home]# cp test2 /tmp/
[root@urclouds home]# cd /tmp/
[root@urclouds 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
[root@urclouds tmp]#

move

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

[root@urclouds home]# mv test2 /home/test
[root@urclouds home]# cd /home/test
[root@urclouds test]# ls -l
total 0
-rw-r--r--. 1 root root 0 May 11 17:40 test2
[root@urclouds 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:-

[root@urclouds home]# rmdir test
rmdir: failed to remove ‘test’: Directory not empty
[root@urclouds home]#

rm

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

[root@urclouds home]# cd test

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

file

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

[root@urclouds log]# file /var/log//messages
/var/log//messages: UTF-8 Unicode text
[root@urclouds log]# file /etc/hosts
/etc/hosts: ASCII text
[root@urclouds log]#