0% found this document useful (0 votes)
4 views25 pages

Chapter 1

The document provides an overview of accessing the command line in Linux, focusing on the shell, terminal, and virtual consoles. It details basic command syntax, common commands, and file system hierarchy, including how to navigate directories and manage files. Additionally, it covers commands for creating, reading, and deleting files, as well as output redirection and viewing file contents.

Uploaded by

fkoff002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

Chapter 1

The document provides an overview of accessing the command line in Linux, focusing on the shell, terminal, and virtual consoles. It details basic command syntax, common commands, and file system hierarchy, including how to navigate directories and manage files. Additionally, it covers commands for creating, reading, and deleting files, as well as output redirection and viewing file contents.

Uploaded by

fkoff002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Welcome To

Classroom
CHAPTER 1: ACCESSING THE COMMAND LINE
2

Accessing the Command Line


 What is Command Line ?.
• A Command line is a text-based interface.

 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

Accessing the Command Line


 What is shell prompt ?
• When a shell is used interactively, it displays a string which means it's
waiting for accepting command from user is called shell prompt.

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

Accessing the Command Line


 Virtual Console ? (Cont.)

• Changing the Virtual Console by Pressing alt+ctrl and pressing a


function key f2 to f6.

o Ctrl+Alt+F1 ==> Terminal1>>tty1


o Ctrl+Alt+F2 ==> Terminal2>>tty2
o Ctrl+Alt+F3 ==> Terminal3>>tty3
o Ctrl+Alt+F4 ==> Terminal4>>tty4
o Ctrl+Alt+F5 ==> Terminal5>>tty5
o Ctrl+Alt+F6 ==> Terminal6>>tty6
Basic command syntax 6

 The GNU Bourne-Again Shell (bash) is a program that interprets


commands typed in by the user. Each string typed into the shell can
have up to three parts: the command, options (that begin with a -
or --), and arguments. Each word typed into the shell is separated
from each other with spaces. Commands are the names of
programs that are installed on the system. Each command has its
own options and arguments.
Basic Commands 7

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

 An absolute path is defined as the specifying the location of a file or


directory from the root directory(/). In other words we can say absolute path is a
complete path from start of actual filesystem from / directory

 /home/student/Desktop

 The relative path are opposite to absolute pathname. A relative path


does not start with a slash ( / ). Generally you specifies location relative to your
current working directory. This is most useful to short a path name.
For example if your current working directory is /home/student and if you
would like to change directory to
 /home/student/docs/linux you can enter command
 - cd docs/linux instead of cd /home/student/docs/linux
ls – list of Files and Directories 14

# 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

# mkdir /home/student/Desktop/testing /tmp/testing1


# mkdir dir{a..z}
# mkdir dir{A..Z}
# mkdir dir{0..100}
# mkdir song/{bangla,english}
Create Empty File using touch 17
command
The touch command is the easiest way to create new, empty files. It is also used to
change the timestamps (i.e., dates and times of the most recent access and
modification) on existing files and directories.

# 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

# tac file1 file2


more 23

# more <filename>
# more <file1> <file2>
# more /etc/postfix/main.cf
 Press spacebar for Screen by Screen

 Press Enter for line by line


 Scroll is available using up and down arrow

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>

# head <file1> <file2>


Tail command 25

tail prints the last 10 lines of each FILE to standard


tail is the most important command for display log
# tail filename
# tail -n <no of lines> <filename>
# tail -<no of lines> <filename>
# tail -f <filename>

# tail <filename>

You might also like