For those who are unsure how to use linux commands. We begin truly learning Linux. So, open a terminal, if you use windows, open PuTTY, and log in to the server.
First, we start with pwd command which means Print Working Directory. This command shows you where you are in the file system. It will help to knowing the file system and help to learn everything else.
pwd command
[root@linuxguideco home]# pwd
/home
man command
This command brings up the online unix manual. It can be used for each of the commands and can see the manual of the given command.
[root@linuxguideco /]# man ls (ls command manual)
cal command
cal commands shows the current month calendar
[root@linuxguideco /]# cal
April 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
‘cal ’ will display calendar for specified month and year.
[root@linuxguideco /]# cal 01 1990
January 1990
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
date command
This command will display current date and time.
[root@linuxguideco /]# date
Mon Apr 29 13:01:31 PKT 2013
This command will only display current time.
[root@linuxguideco /]# date +%T
13:03:08
whoami command
This command shows current logged in user.
[root@linuxguideco /]# whoami
root
id command
id command shows user and groups (UID and GID) of current user.
[root@linuxguideco /]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linuxguideco bin]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
du command
shows the total size used by the files.
[root@linuxguideco guide]# du -c /dev
shows the directory size
[root@linuxguideco guide]# du -s /dev
96 /dev
shows directory size with human understanding.
[root@linuxguideco guide]# du -hs /dev
96K /dev
df command shows free disk space.
[root@linuxguideco guide]# df
ls command
To show the current directory list.
[root@linuxguideco /]# ls
bin boot dev etc home lib media misc mnt net opt proc root sbin selinux srv sys tmp usr var
[root@linuxguideco /]# ls -l
drwxr-xr-x 2 root root 4096 Apr 12 10:13 bin
[root@linuxguideco /]# ls -al
drwxr-xr-x 23 root root 4096 Apr 30 14:51 .
drwxr-xr-x 23 root root 4096 Apr 30 14:51 ..
-rw------- 1 root root 19 Apr 12 17:53 .bash_history
drwxr-xr-x 2 root root 4096 Apr 12 10:13 bin
cd command
for changing the directory.
[root@linuxguideco /]# cd /usr/
[root@linuxguideco usr]#
one step back to the directory.
[root@linuxguideco usr]# cd ..
[root@linuxguideco /]#
go to previous working directory
[root@linuxguideco usr]# cd -
/
go to current login user home directory
[root@linuxguideco /]# cd ~
[root@linuxguideco ~]#
mkdir command
Create a folder on root partition.
[root@linuxguideco /]# mkdir /guide
create a folder in /guide
[root@linuxguideco /]# mkdir /guide/test
create multiple folder in multiple directories with single command
[root@linuxguideco /]# mkdir /usr/dir1 /var/dir2 /etc/dir3
create multiple folder in same directory
[root@linuxguideco /]# mkdir dir11 dir12 dir13
cp command
copy a file in directory
[root@linuxguideco guide]# cp file /guide2
copy a file from /guide/file to /guide2/dir
[root@linuxguideco guide]# cp /guide/file /guide2/dir
copy a directory with -r option
[root@linuxguideco guide]# cp -r dir6 dir7
copy a file from /guide/file1 paste in /usr with file2 name
[root@linuxguideco guide]# cp /guide/file1 /usr/file2
rm command
remove a file
[root@linuxguideco guide]# rm file
remove a file with forcefully option
[root@linuxguideco guide]# rm -f file
remove a directory without -r option, it will appear an error
[root@linuxguideco /]# rm guide
rm: cannot remove directory `guide': Is a directory
remove a directory with -r option
[root@linuxguideco /]# rm -r guide
remove a directory with -r option
[root@linuxguideco /]# rm -rf guide
move command
Move /usr/dir1 to /opt/ with different name
[root@linuxguideco /]# mv /usr/dir1 /opt/dir2
Rename the folder name mydir to dir
[root@linuxguideco /]# mv /usr/mydir /usr/dir
Rename the file1 name with file2
[root@linuxguideco /]# mv file1 file2
For reading a file on terminal
[root@linuxguideco etc]# cat /etc/grub.conf
commands
read a file page by page with less command
[root@linuxguideco /]# less /etc/grub.conf
read a file page by page with more command
[root@linuxguideco /]# more /etc/grub.conf
read first ten lines of grub.conf
[root@linuxguideco /]# head /etc/grub.conf
read last ten lines of grub.conf
[root@linuxguideco /]# tail /etc/grub.conf
read first 12 lines with -n option
[root@linuxguideco /]# head -n 12 /etc/grub.conf
read last 13 lines with -n option
[root@linuxguideco /]# last -n 13 /etc/grub.conf
copy the contents of /etc/grub.conf in /guide/file
[root@linuxguideco /]# cat /etc/grub.conf > /guide/file
Append the contents of /guide/file in /guide2/file
[root@linuxguideco /]# cat /guide/file >> /guide2/file
merging two commands with pipe sign output of the first command is input of second command
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | more
count the total lines of httpd.conf
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | wc -l
479
show only conf words in httpd.conf
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | grep conf
flush the contents of file
[root@linuxguideco /]# cat /dev/null > /guide/file
help commands
[root@linuxguideco guide]# man mkdir
[root@linuxguideco guide]# info mkdir
[root@linuxguideco guide]# mkdir --help
[root@linuxguideco guide]# apropos "partition"
I hope these basic commands will surely help out to Linux beginner users.
First, we start with pwd command which means Print Working Directory. This command shows you where you are in the file system. It will help to knowing the file system and help to learn everything else.
pwd command
[root@linuxguideco home]# pwd
/home
man command
This command brings up the online unix manual. It can be used for each of the commands and can see the manual of the given command.
[root@linuxguideco /]# man ls (ls command manual)
cal command
cal commands shows the current month calendar
[root@linuxguideco /]# cal
April 2013
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
‘cal ’ will display calendar for specified month and year.
[root@linuxguideco /]# cal 01 1990
January 1990
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
date command
This command will display current date and time.
[root@linuxguideco /]# date
Mon Apr 29 13:01:31 PKT 2013
This command will only display current time.
[root@linuxguideco /]# date +%T
13:03:08
whoami command
This command shows current logged in user.
[root@linuxguideco /]# whoami
root
id command
id command shows user and groups (UID and GID) of current user.
[root@linuxguideco /]# id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
[root@linuxguideco bin]# id root
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)
du command
shows the total size used by the files.
[root@linuxguideco guide]# du -c /dev
shows the directory size
[root@linuxguideco guide]# du -s /dev
96 /dev
shows directory size with human understanding.
[root@linuxguideco guide]# du -hs /dev
96K /dev
df command shows free disk space.
[root@linuxguideco guide]# df
ls command
To show the current directory list.
[root@linuxguideco /]# ls
bin boot dev etc home lib media misc mnt net opt proc root sbin selinux srv sys tmp usr var
[root@linuxguideco /]# ls -l
drwxr-xr-x 2 root root 4096 Apr 12 10:13 bin
[root@linuxguideco /]# ls -al
drwxr-xr-x 23 root root 4096 Apr 30 14:51 .
drwxr-xr-x 23 root root 4096 Apr 30 14:51 ..
-rw------- 1 root root 19 Apr 12 17:53 .bash_history
drwxr-xr-x 2 root root 4096 Apr 12 10:13 bin
cd command
for changing the directory.
[root@linuxguideco /]# cd /usr/
[root@linuxguideco usr]#
one step back to the directory.
[root@linuxguideco usr]# cd ..
[root@linuxguideco /]#
go to previous working directory
[root@linuxguideco usr]# cd -
/
go to current login user home directory
[root@linuxguideco /]# cd ~
[root@linuxguideco ~]#
mkdir command
Create a folder on root partition.
[root@linuxguideco /]# mkdir /guide
create a folder in /guide
[root@linuxguideco /]# mkdir /guide/test
create multiple folder in multiple directories with single command
[root@linuxguideco /]# mkdir /usr/dir1 /var/dir2 /etc/dir3
create multiple folder in same directory
[root@linuxguideco /]# mkdir dir11 dir12 dir13
cp command
copy a file in directory
[root@linuxguideco guide]# cp file /guide2
copy a file from /guide/file to /guide2/dir
[root@linuxguideco guide]# cp /guide/file /guide2/dir
copy a directory with -r option
[root@linuxguideco guide]# cp -r dir6 dir7
copy a file from /guide/file1 paste in /usr with file2 name
[root@linuxguideco guide]# cp /guide/file1 /usr/file2
rm command
remove a file
[root@linuxguideco guide]# rm file
remove a file with forcefully option
[root@linuxguideco guide]# rm -f file
remove a directory without -r option, it will appear an error
[root@linuxguideco /]# rm guide
rm: cannot remove directory `guide': Is a directory
remove a directory with -r option
[root@linuxguideco /]# rm -r guide
remove a directory with -r option
[root@linuxguideco /]# rm -rf guide
move command
Move /usr/dir1 to /opt/ with different name
[root@linuxguideco /]# mv /usr/dir1 /opt/dir2
Rename the folder name mydir to dir
[root@linuxguideco /]# mv /usr/mydir /usr/dir
Rename the file1 name with file2
[root@linuxguideco /]# mv file1 file2
For reading a file on terminal
[root@linuxguideco etc]# cat /etc/grub.conf
commands
read a file page by page with less command
[root@linuxguideco /]# less /etc/grub.conf
read a file page by page with more command
[root@linuxguideco /]# more /etc/grub.conf
read first ten lines of grub.conf
[root@linuxguideco /]# head /etc/grub.conf
read last ten lines of grub.conf
[root@linuxguideco /]# tail /etc/grub.conf
read first 12 lines with -n option
[root@linuxguideco /]# head -n 12 /etc/grub.conf
read last 13 lines with -n option
[root@linuxguideco /]# last -n 13 /etc/grub.conf
copy the contents of /etc/grub.conf in /guide/file
[root@linuxguideco /]# cat /etc/grub.conf > /guide/file
Append the contents of /guide/file in /guide2/file
[root@linuxguideco /]# cat /guide/file >> /guide2/file
merging two commands with pipe sign output of the first command is input of second command
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | more
count the total lines of httpd.conf
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | wc -l
479
show only conf words in httpd.conf
[root@linuxguideco /]# cat /usr/apache2/conf/httpd.conf | grep conf
flush the contents of file
[root@linuxguideco /]# cat /dev/null > /guide/file
help commands
[root@linuxguideco guide]# man mkdir
[root@linuxguideco guide]# info mkdir
[root@linuxguideco guide]# mkdir --help
[root@linuxguideco guide]# apropos "partition"
I hope these basic commands will surely help out to Linux beginner users.
Nice work for beginners who wants to learn LINUX basic commands. Carry on your dear.. :)
ReplyDeleteNice, noticed a few commands that I didn't know about that seems useful. Thank you
ReplyDeletemy pleasure ... and thank you too for your comment...
ReplyDeleteNice dude.......
ReplyDeleteso nice of you dear ...
ReplyDelete