Chapter 1
Chapter 1
Classroom
CHAPTER 1: ACCESSING THE COMMAND LINE
2
What is shell ?
• The Linux Command Line is Provided by a program called the shell.
• Among lots of Shell, Bourne-Again Shell(bash) is the Default shell in RHEL 7.
• bash is similar in concept to the command line interpreter of cmd.exe or
PowerShell.
3
Note: When a regular user starts a shell, the default prompt ends with a $
character.
Note: When a super user starts a shell, the default prompt ends with a #
character.
4
Accessing the Command Line
what is terminal ?
• User access the bash shell through a terminal. A terminal provides a
keyboard for user input and display for output.
• Terminal Access can also be configured through serial ports.
Virtual Console ?
• A Linux system physical console supports multiple virtual consoles which
act like separate terminals. Each virtual console supports an independent
login session
• By Default there are 6 virtual consoles. If Graphical environment is
available, it will run on the first virtual console and rest of the five are for
text login.
5
Commands Purpose
tty To view terminal type
w Show who is logged on and what they
are doing
who Show who is logged on
finger User information lookup
clear / ctrl + l To clear current terminal screen
cal Display Calander
pwd Print name of current/working
directory
lsblk List block (Harddisk,USB,CD/DVD Rom)
Devices
fdisk –l List the partition table for all block
devices
Basic Commands(continue…) 8
Commands Purpose
file To view a file type
free –m Display amount of free and used
memory (RAM) in the system.
lscpu Display information about the CPU
Architecture.
date Print system date and time.
hwclock query / set the hardware clock.
uptime Display how long the system has been
running.
logout / exit / ctrl + d Exit a login shell
ctrl + c Cancel current operation
man <command> Command reference manuals
<command> --help / <command> -h To display command helps
Basic Commands(continue…) 9
Commands Purpose
info <command> Command Info documents
<tab completion> Auto completion of commands/ files/
Variables etc…
history Display the command history list with
line numbers.
uname –r Print the kernel release
Basic Commands(continue…) 10
Shutdown Restart
init 0 init 6
poweroff reboot
systemctl poweroff systemctl reboot
shutdown –h <time> shutdown –r <time>
shutdown –h now shutdown –r now
shutdown –h 120 shutdown –r 120
halt –p halt –reboot
ctrl + alt + delete
Linux File System
Hierarchy -FSH
12
Path 13
/home/student/Desktop
# pwd
# ls
# ls -l
# ls -la
# ls -lh
# ls -R
# ls -l <Directory>
# ls -l /etc
# ls -R
# ls -l /etc /home
Cd < Change Directory> 15
# cd
# cd ~
# cd ~<username>
# cd ~student
# cd <absulate path of a dir>
# cd <Relative path of a Dir>
# cd ..
# cd ../..
# cd -
# cd .
# cd “Directory with Space”
# cd “Audio Song”
# cd Audio\ Song
# cd ~student/Desktop
Make Directory or Folder- mkdir
16
# mkdir <dir>
# mkdir <dir1> <dir2>
# mkdir Redhat Linux
# mkdir “Redhat Linux”
# mkdir <dir1/dir2>
# mkdir -p <dir1/dir2/dir3>
# mkdir <dir1/dir2/dir3> -p
# touch <filename>
# touch file1 file2
18
Output Redirection
# date
# date >file.txt [create new file file1 and output of date command will be there]
# cal >file.txt [will override the existing file with output of cal command]
# who >>file.txt [will append the output of who command]
Remove or Delete file or Directory 19
using rm command
# rm filename
# rm file1 file2
# rm -i file1 file2
# rm -f file1 file2 Remove only empty Directory using rmdir
# rm -r dir1 command
# rm -r dir1 dir2
# rmdir emptydir
# rm -r -f dir1 dir2
# rmdir *
# rm -rf dir1
# rmdir /testing/*
# rm dir -rf
# rm dir -fr
# rm -fr *
20
We can read the file using
# cat
# tac
# more
# less
# head
# tail
# vi/vim
cat 21
# Cat file1
# Cat file1 file2
# cat -n file1
# Cat > file1
# Cat >>file1
# cat /etc/redhat-release
# Cat /proc/partitions
Tac 22
Read the file in reverse order
# tac filename
# more <filename>
# more <file1> <file2>
# more /etc/postfix/main.cf
Press spacebar for Screen by Screen
less
Less <filename>
Press spacebar for Screen by Screen
Press Enter for line by line
Scroll is available using up and down arrow
24
Head
Prints the lines from a file beginning from top. By default head command will
display first 10 lines of a file
# head filename
# head -n <no of lines> <filename>
# head <no of lines> <filename>
# tail <filename>