Section 2 Basic Linux Command
Section 2 Basic Linux Command
By Bean Bee
6/24/2021 1
In Linux, commands are ways or instructions
through which you can instruct your system to do
some action. Commands are executed in the
command line.
This command further passes to the shell which
reads the command and execute it. Shell is a method
for the user to interact with the system. Default shell
in Linux is called bash (Bourne-Again Shell).
6/24/2021 2
There are two types of shell commands:
6/24/2021 3
Directory
Description
Command
mkdir With mkdir command you can create your own directory.
6/24/2021 5
Once you launch the CLI (Terminal), you would
find something as guru99@VirtualBox(see
image) written on it.
6/24/2021 6
pwd command stands for print working
directory
6/24/2021 7
If you want to change your current directory
use the 'cd' command.
cd /tem
6/24/2021 8
If you want to navigate to the home directory,
then type cd.
6/24/2021 9
The root of the file system in Linux is
denoted by '/'. Similar to 'c:\' in Windows.
Note: In Windows, you use backward slash "\"
while in UNIX/Linux, forward slash is used "/“
Type 'cd /' to move to the root directory.
6/24/2021 10
You can navigate through multiple directories
at the same time by specifying its complete
path.
6/24/2021 11
A path in computing is the address of a file or folder.
Example
◦ In Windows
◦ C:\documentsandsettings\user\downloads
◦ In Linux
◦ /home/user/downloads
6/24/2021 12
An absolute path refers to the complete details needed
to locate a file or folder, starting from the root
element and ending with the other subdirectories.
6/24/2021 13
A relative path refers to a location that is relative to a
current directory
You do no need to type the absolute path
cd /home/guru99/Downloads
6/24/2021 14
Listing files (ls) command
If you want to see the list of files on your UNIX or Linux
system, use the 'ls' command.
It shows the files /directories in your current directory.
Note:
6/24/2021 15
Listing files (ls) command
Suppose, your "Music" folder has following sub-directories and
files.
6/24/2021 16
Listing files (ls) command
You can use 'ls -R' to shows all the files not only in directories but also
subdirectories.
6/24/2021 17
Listing files (ls) command
The 'ls -al' gives detailed information of the files
6/24/2021 18
Listing Hidden Files
Hidden items in UNIX/Linux begin with ‘.’ (period symbol) at
the start, of the file or directory.
Ls –a
6/24/2021 19
Creating & Viewing Files
The 'cat' command is used to display text files,
copying, combining and creating new text files.
To create a new file, use the command
1. cat > filename
2. Add content
3. Press 'ctrl + d' to return to command prompt.
6/24/2021 20
Creating & Viewing Files
To view a file, use the command –
cat filename
6/24/2021 21
Deleting Files
The 'rm' command removes files from the system without
confirmation.
To remove a file use syntax –
rm filename
6/24/2021 22
Moving and Re-naming files
To move a file, use the command.
mv filename new_file_location
sudo command_you_want_to_execute
For renaming file:
mv filename newfilename
6/24/2021 23
Creating Directories
Directories can be created on a Linux operating system using the following
command.
mkdir directoryname
For example,
mkdir mydirectory
6/24/2021 24
Removing Directories
To remove a directory, use the command –
rmdir directoryname
6/24/2021 25
The 'Man' command
Man stands for manual which is a reference book of a Linux operating system.
It is similar to HELP.
To get help on any command that you do not understand, you can type
man
6/24/2021 26
The History Command
History command shows all the basic commands in Linux that you have
used in the past for the current terminal session.
6/24/2021 27
The clear command
This command clears all the clutter on the terminal and gives you
a clean window to work on, just like when you launch the
terminal.
6/24/2021 28
Command Description
6/24/2021 29
mv file "new file path" Moves the files to the new location
mv filename new_file_name Renames the file to a new filename
Allows regular users to run programs with
sudo the security privileges of the superuser or
root
rm filename Deletes a file
6/24/2021 30
rmdir Deletes a directory
mv Renames a directory
pr -x Divides the file into x columns
pr -h Assigns a header to the file
pr -n Denotes the file with Line Numbers
lp -nc
Prints "c" copies of the File
lpr c
lp -d lpr -P Specifies name of the printer
Command used to install and update
apt-get
packages
mail -s 'subject' -c 'cc-address' -b
Command to send email
'bcc-address' 'to-address'
mail -s "Subject" to-address < Command to send email with
Filename attachment
More: https://www.javatpoint.com/linux-commands-list
6/24/2021 31
Filesystem hierarchy standard describes
directory structure and its content in Unix and
Unix like operating system. It explains where
files and directories should be located and
what it should contain.
6/24/2021 32
6/24/2021 33
Main directories
/bin is a place for most commonly used terminal commands,
like ls, mount, rm, etc.
/boot contains files needed to start up the system, including
the Linux kernel, a RAM disk image and bootloader
configuration files.
/dev contains all device files, which are not regular files but
instead refer to various hardware devices on the system,
including hard drives.
6/24/2021 34
/etc contains system-global configuration
files, which affect the system's behavior for
all users.
/home home sweet home, this is the place
for users' home directories.
/lib contains very important dynamic
libraries and kernel modules
6/24/2021 35
/media is intended as a mount point for
external devices, such as hard drives or
removable media (floppies, CDs, DVDs).
/mnt is also a place for mount points, but
dedicated specifically to "temporarily
mounted" devices, such as network
filesystems.
6/24/2021 36
/opt can be used to store additional software for
your system, which is not handled by the package
manager.
/proc is a virtual filesystem that provides a
mechanism for kernel to send information to
processes.
/root is the superuser's home directory, not in
/home/ to allow for booting the system even if
/home/ is not available.
6/24/2021 37
/run is a tmpfs (temporary file system) available
early in the boot process where ephemeral run-
time data is stored. Files under this directory are
removed or truncated at the beginning of the boot
process.
(It deprecates various legacy locations such as
/var/run, /var/lock, /lib/init/rw in otherwise non-
ephemeral directory trees as well as /dev/.* and
/dev/shm which are not device files.)
6/24/2021 38
/sbin contains important administrative
commands that should generally only be
employed by the superuser.
/srv can contain data directories of services such
as HTTP (/srv/www/) or FTP.
/sys is a virtual filesystem that can be accessed
to set or obtain information about the kernel's
view of the system.
6/24/2021 39
/tmp is a place for temporary files used by
applications.
/usr contains the majority of user utilities and
applications, and partly replicates the root directory
structure, containing for instance, among others,
/usr/bin/ and /usr/lib.
/var is dedicated to variable data, such as logs,
databases, websites, and temporary spool (e-mail
etc.) files that persist from one boot to the next. A
notable directory it contains is /var/log where
system log files are kept.
6/24/2021 40
To manage your files, you can use either the
GUI(File manager) or the CLI(Terminal) in Linux.
Both have its relative advantages. In the tutorial
series, we will focus on the CLI.
You can launch the terminal from the dashboard or
use the shortcut key Cntrl + Alt + T
The pwd command gives the present working
directory.
You can use the cd command to change directories
Absolute path is complete address of a file or
directory
Relative path is relative location of a file of
directory with respect to current directory
6/24/2021 41
Linux Filesystem Tree Overview
◦ https://help.ubuntu.com/community/LinuxFilesyst
emTreeOverview
Linux Command Line Tutorial
◦ https://www.guru99.com/terminal-file-
manager.html
6/24/2021 42
6/24/2021 43