Shell Commands
• User Name : user1
• Password : 123456
• Getting use to the command line environment BASH (Bourne Again Shell)
© Samantha Indika
• With in GUI : Gnome : Open a terminal
: KDE : Open a konsole
Application > Accessories > Terminal
Right-Click on Desktop > Open Terminal
• Without GUI
: minimize GUI shell
Ctrl + ALT + F1
: maximize GUI shell
Ctrl + ALT + F7
• What is command?
Command is executable file : GUI & TUI
Application > Accessories > Calculator
Help > About
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 1
Cont.. Shell Commands
Application > Accessories > Text Editor
Help > About
© Samantha Indika
[user1@srv2~]$gcalctool
[user1@srv2~]$gedit
[user1@srv2~]$gcalctool Copy (R.C > Copy) & Paste (R.C. > Paste / Shift + Ins)
[user1@srv2~]$cal Calendar / Output is text
[user1@srv2~]$date
[user1@srv2~]$clear or Ctrl + L
Pure command-line > Ctrl + ALT + F1
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 2
Cont.. Shell Commands
Root
Bin = binary
© Samantha Indika
OS related OS related
commands commands
[/bin] [/sbin]
System
System
[/usr]
Common Admin
Linux Connectors
User
Commands [/bin] [/sbin]
Software Software
Terminal changes : Edit > Current Profile
Colors, Effects, ……..
• How to get total number of commands?
[user1@srv2 ~]$[TAB] + [TAB] + [TAB] (3 times)
Enter key - line by line
Space bar - page by page
Ctrl + C - Cancel Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 3
Cont.. Shell Commands
• Directory listing commands Ctrl + H : Hidden Files/Folders
• Desktop > User1’s home > Ctrl + H Ctrl + H : Hide Files/Folders
.config : Hidden items
• Create Folder name : ABC
© Samantha Indika
• Create Folder name : .123
• Print working directory
[user1@srv2 ~]$pwd
/home/user1 Root
[Home]
[user1]
/home/user1
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 4
Cont.. Shell Commands
[user1@srv2 ~]$ Normal User
© Samantha Indika
Current
User
Logged Current
in Folder
Computer
Name
• List the content in the folder
[user1@srv2 ~]$ls
• All objects (hidden file/folder also)
[user1@srv2 ~]$ls Δ -a
• Manual of a command
[user1@srv2~]$man command
Browse : Up arrow, Down arrow, Left arrow, Right arrow
Quit :q
Julian Calendar
[user1@srv2~]$cal Δ -3 1…..7
[user1@srv2~]$cal Δ –y 8……15
16…..23
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 5
Cont.. Shell Commands
• Go to “home” folder /
[test1] [test2]
© Samantha Indika
[test3]
[test4]
[test5]
[user1@srv2 ~]$tree
[user1@srv2 ~]$tree Δ –C : To view with colors
[user1@srv2 ~]$tree Δ –a : All objects
[user1@srv2 ~]$tree Δ –C Δ –a or tree Δ –a Δ –C
OR
[user1@srv2 ~]$tree Δ –Ca
[user1@srv2 ~]$tree Δ –d : directories only
• Create 2 files in home folder using GUI. Eg : file1 & file2
[user1@srv2 ~]$tree
[user1@srv2 ~]$tree Δ –C
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 6
Cont.. Shell Commands
[user1@srv2 ~]$tree Δ –Cd
[user1@srv2 ~]$tree Δ -adC
© Samantha Indika
• To see a large output in part by part
[user1@srv2 ~]$command (with options) Δ |Δ more
Pipe Pager
mark
[user1@srv2 ~]$tree Δ –C Δ | Δ more
[user1@srv2 ~]$tree Δ –Ca Δ | Δ more
[user1@srv2 ~]$tree Δ –a Δ | Δ less
: Color codes are not supports
Q : quit
Up arrow
Down arrow
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 7
Cont.. Shell Commands
• Long list
#ls Δ –l
© Samantha Indika
#ls Δ –lh
drwxr-xr-x 1 user1 user1 4.0K Jun 27 17.11 test1
Ext3 Ownership Size Last Modified Object
permission (Bytes) Date & Time Name
Object File /
Value Folder /
File = 1 Symlink
Empty Folder =2
Data Folder = 4
#ls Δ –alh
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 8
Cont.. Shell Commands Root
• Directory browsing command
• Full path to the folder / Full path start
from here
© Samantha Indika
1 / home / user1 / test2 / test3
[/home]
2 / home / user1 / test2 / test4 / test5 [/user1]
• Relative path to the folder
/test1 /test2
• Don’t type the correct location
that you are already in
• Never type “ / “ in front Sub Folder
/test3 /test4
1 test2 / test3 1
/test5
2 test2 / test4 / test5 2
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 9
Cont.. Shell Commands
$pwd
$cd Δ /home/user1/test2/test3 << Full path
$pwd
© Samantha Indika
• To go to your home folder
$cd
$pwd
$cd Δ test2/test3 << Relative path
$cd
$cd Δ test2/test4/test5
• One folder back
$ls Δ -a
$cd . .
$pwd
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 10
Cont.. Shell Commands
$cd Δ . . Or $cd Δ . . / . .
$cd Δ . .
Executable File/Commands - Green
© Samantha Indika
• Go to root partition Symlink (Shortcut) - Light Blue
Executable files with Root Permission
- Red
$cd Δ / File - Black
$pwd Folder - Blue
$ls
$cd Δ /bin
$cd Δ /usr/share/backgrounds
$pwd
$cd Δ images
$pwd
$cd Δ . .
$pwd
$cd
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 11
Cont.. Shell Commands
• Go to Previous location
$cd Δ -
© Samantha Indika
$pwd
• Go to Root
$cd Δ /
$pwd
$ls
• Object management commands
File Folder Symlink
Main Object Sub Object
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 12
Cont.. Shell Commands
• Create new object
$mkdir Δ fol1
© Samantha Indika
$ls
$mkdir Δ fol2 Δ fol3 Δ fol4 Δ fol5
$ls
• Create a new folder within an existing folder
$ls Δ test1
• Create a sub folder call Linux in test1 folder
$cd Δ test1 $mkdir Δ test1/linux
$mkdir Δ linux $ls Δ test1/
$ls
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 13
Cont.. Shell Commands
• Create a new folder and a sub folder at once
• Eg: Create a folder call “Redhat” and create a sub folder call “centos” in
the Redhat folder.
© Samantha Indika
$mkdir Δ redhat $mkdir –p Δ redhat/linux
$mkdir Δ redhat/centos $ls
$ls Δ redhat
• Create a folder call (“my Δ data”)
• Ex: 1
$mkdir Δ “my Δ data”
OR
$mkdir Δ my \ data
• Create a folder call (“my Δ data Δ 2”)
• Ex: 2
$mkdir Δ “my Δ data Δ 2” Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
OR MCSA + Security + Messaging, MCP 14
$mkdir Δ my \ data \ 2
Cont.. Shell Commands
• Create a folder call (“my Δ data Δ 2”)
• Ex: 2
© Samantha Indika
$mkdir Δ “my Δ data Δ 2”
OR
$mkdir Δ my \ data \ 2
$ls
$ls Δ – l (L)
$ls Δ – 1 (1/One)
• New file
Use a text editor to Create / Edit / Read files
$nano Δ file1
CENTOS
To save a file : Ctrl + O
To exit a file : Ctrl + X Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 15
Cont.. Shell Commands
• Specify a location
$nano Δ fol2/file1
© Samantha Indika
CENTOS
Ctrl + O
Press ENTER Key
Ctrl + X
$ls Δ fol2
$cat Δ fol2/file1
• New Symlinks
Create a new symlink in your home folder to
access /usr/share/backgrounds/images folder
$cd
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 16
Cont.. Shell Commands
$ln Δ –s Δ /usr/share/backgrounds/images Δ link1
Link Destination folder location Symlink
Symlink
© Samantha Indika
Name
(Any Name)
$ls Δ -l
• To access the destination location using the symlink
$cd Δ link1
$pwd
$pwd Δ -P
• Create a new symlink in your home folder to access
$cd
$ln Δ –s Δ /etc/fstab Δ link3
$ls Δ -l
Destination File Symlink
Location NamePrepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 17
Cont.. Shell Commands
$ln Δ –s Δ /etc/fstab Δ /tmp/link3
$ls Δ /tmp
$cat Δ /tmp/link3
© Samantha Indika
• Use the link to access the file
Edit : $nano Δ link3
Read : $cat Δ link3
$pwd
$pwd Δ -P
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 18
Cont.. Shell Commands
• Rename
The current folder
$ls
© Samantha Indika
$ls
$mv Δ CurrentObjectName Δ NewObjectName
Eg : Rename test2 folder to data2
$mv Δ test2 Δ data2
$ls
Within a different folder
Eg : Rename linux folder within the test1 folder to windows
$mv Δ test1/linux Δ test1/windows
$ls Δ test1
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 19
Cont.. Shell Commands
• Moving Objects
Cut and Paste Root
Move File1 in to Folder1
© Samantha Indika
$mv Δ file1 Δ folder1 /
$ls Δ folder1
[/home] [/tmp]
Move Link1 in to Folder1
$mv Δ link1 Δ folder1
[/user1] file2
$ls Δ folder1
Move Folder1 in to /tmp
file1 link1 [folder1]
$mv Δ folder1 Δ /tmp
$ls Δ /tmp
Move /tmp/file2 in to my Home Folder
$mv Δ /tmp /file2 Δ ~
$cd
$ls
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 20
Cont.. Shell Commands
• Copying Objects
Copy and Paste
Copy File1 in to Folder1
© Samantha Indika
$cp Δ file1 Δ folder1
$ls
$ls Δ folder1
Copy Link1 in to Folder1
$cp Δ –d Δ link1 Δ folder1 -d = difference
Copy Folder1 in to /tmp
$cp Δ –r Δ folder1 Δ /tmp -r = recursive
$ls Δ /tmp
Copy /tmp/file2 in to my Home Folder
$cp Δ /tmp /file2 Δ ~
$cd
$ls
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 21
Cont.. Shell Commands
• Delete Objects
Files/Symlinks
$rm Δ objectname $rm Δ –i Δ objectname
© Samantha Indika
$rm Δ link1
$rm Δ file1 ? Y/N
$ls
Folders $rm Δ –ri Δ objectname
$rm Δ –r Δ foldername
? Y/N
$rm Δ –r Δ folder5
$ls
-r = recursive
Prepared by : Samantha Indika | MCT, ACS, CEH, CCNA, BCS
(Certificate), MCS (SL), MCITP, MCTS, MCSE + Security + Messaging,
MCSA + Security + Messaging, MCP 22