System Admin Commands

Basic Linux Commands

Friends here I am going to add some System Admin 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@tzclouds ~]# cd /home/
[root@tzclouds home]# pwd
/home
[root@tzclouds home]# cd /
[root@tzclouds /]# pwd
/
[root@tzclouds /]#

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@tzclouds log]# cd /var/log
[root@tzclouds log]# pwd
/var/log
[root@tzclouds log]#

df -h

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

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

ls

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

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

ls -la

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

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

mkdir

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

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

touch

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

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

its nothing returning its means our test2 file is empty.

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

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

move

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

[root@tzclouds home]# mv test2 /home/test
[root@tzclouds home]# cd /home/test
[root@tzclouds test]# ls -l
total 0
-rw-r--r--. 1 root root 0 May 11 17:40 test2
[root@tzclouds 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@tzclouds home]# rmdir test
rmdir: failed to remove ‘test’: Directory not empty
[root@tzclouds home]#

rm

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

[root@tzclouds home]# cd test

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

file

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

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