You are on page 1of 23

Linux Basic

Command & Operation


Shell ?

Simply put, the shell is a program that takes commands from the keyboard and gives them to the
operating system to perform. In the old days, it was the only user interface available on a Unix-like
system such as Linux. Nowadays, we have graphical user interfaces (GUIs) in addition to command
line interfaces (CLIs) such as the shell.

(https://linuxcommand.org/lc3_lts0010.php)
Linux Operating System Shell

1. Command Line Interface (CLI) Shell


○ Korn Shell (ksh)
○ C Shell (csh)
○ Bourne Shell (sh)
○ Z Shell (zsh)
○ Debian Almquist Shell (dash)
○ Bourne Again Shell (bash)
○ Restricted bash Shell (rbash)
2. Graphical User Interface (GUI) Shell
○ GNOME
○ KDE
○ Unity
Mini Lab

● List Shell Installed


○ cat /etc/shells
● Check user using which shell
○ grep $USER /etc/passwd
Shell Type Command

1. Internal (built -in )


○ Include from Shell
○ Example : cd , pwd
2. External
○ Part of software/application installed
○ Example : ping , ip
Mini Lab

● Check list command type built-in :


○ help
○ help -d
● Check command type :
○ type -a [command name]
○ command -V [command name]
● Built In type shell help using :
○ help [command name]
● External type shell help using :
○ man [command name]
Component Command

command Options / Parameter Argument

ls -l /etc/

cd /usr/share/doc

ls -l -t
Absolute & Relative path

● Absolute Path

An absolute pathname begins with the root directory and follows the tree, branch by
branch, until it reaches the desired directory or file. Absolute paths always start with /

● Relative Path

A relative pathname starts from the present working directory. Relative paths never start
with /
Basic Command for Operation
Command Description

cd Call Directory / Change the shell working directory

ls To get list of directory contents

pwd To get current shell working directory

touch To create empty file and to update access & modification times

rm To remove file or directories

mkdir To create/make directories

passwd To change password


Basic Command for Operation
Command Description

cat Use for viewing files that are not very long, not provide scroll back

less Use to view larger files, its paging program, provide scroll back, provide
search & navigate

tail Use to print last 10 lines, change number using option -n follow line
number, ex : tail -n 30. Use option -f to follow output appended data

grep Searches text files & data streams for patterns and can be used with regular
expressions

echo Displays a line of text either on standard output or to place in a file


Basic Special Characters

Chracters Description

> Redirect output

>> Append output

< Redirect Input

| Use to pipe the result into next command

\ Use at end of the line to indicate command continues to the next line
Mini Lab

● Redirect output
○ echo “Hello World!” > /root/hello.txt
● Append output
○ echo “Today is lovely day” >> /root/hello.txt
● Redirect input
○ wc -l < /root/hello.txt
○ wc -l << EOF
This is a test command
For input redirection
EOF
Mini Lab

● Pipe
○ cat /etc/ssh/sshd_config | less
● End of line indications
○ echo “Hello my Name \

is John Doe”
Linux Structure Directory / FHS

Dir Description

/bin Essential user command binaries (for use by all users)

/boot Static files of the boot loader

/dev Device files

/etc Host-specific system configuration

/home User home directories (optional)

/lib Essential shared libraries and kernel modules


Linux Structure Directory / FHS

Dir Description

/media Mount point for removable media

/mnt Mount point for a temporarily mounted filesystem

/opt Add-on application software packages

/root Home directory for the root user (optional)

/run Run-time variable data

/sbin Essential System binaries


Linux Structure Directory / FHS

Dir Description

/srv Data for services provided by this system

/tmp Temporary files

/usr Multi user applications, utilities and data

/var Directory contains files that are expected to change in size and content as the
system is running (var stands for variable)

Source : https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
Software Management : APT Tools
Management Command

Update apt update

Upgrade apt upgrade

Add Source package from CD/DVD Rom apt-cdrom add

Search apt search package1

Install apt install package1

Remove apt remove package1

ReInstall apt --reinstall install package1


Mini Lab

● Search
○ apt search tree
● Install
○ apt install tree
● Uninstall
○ apt remove tree
Software Management : DPKG Tools
Management Command

Search installed software dpkg -l | grep package1

Install dpkg -i package1

Remove dpkg --purge package1

Reconfigure dpkg-reconfigure package1


Mini Lab

● List installed software


○ dpkg -l
○ dpkg -l |grep tree
● Remove software
○ dpkg -r tree
○ dpkg –purge tree
File Editor : vim
Mode Description

normal Default; for navigation and simple editing

insert For explicitly inserting and modifying text

Command line For operations like saving, exiting, etc.


File Editor : vim
Command Usage

vi file1 Edit file1

vi -r file1 Edit file1 in recovery mode from a system crash

:r file2 Read in file2 and insert at current position

:w Write to the file (save)

:w file3 Write out to file3 (save to file3)

:q! Quit event trough modifications have not been saved

::wq! Exit & write out modified file


File Editor : vim
Command Usage

:1 Goto N line

ESC →v Mode block (visual)

ESC →y Yanked, copy from visual

ESC →p Paste

:e! file2 Move edit to file2

You might also like