Lesson 06 - Introduction To CLI

Download as pdf or txt
Download as pdf or txt
You are on page 1of 46

Ubuntu Fundamentals

Introduction to CLI
Learning Objectives

By the end of this lesson, you will be able to:

Execute various commands in the terminal

Apply superuser commands using the sudo command

Find help for commands using manual pages

Navigate through the file system

Manipulate files and folders

Execute system commands


Starting Up the Terminal

To start the terminal, right click on the mouse and select the option open terminal.
Running Commands as Superuser

A normal user does not have the privilege to perform certain tasks.

• The sudo command in Linux elevates the privilege of a


normal user to perform certain restricted tasks.
• In Ubuntu, by default, a user can join the sudo group to get
these facilities.
• The user doesn’t require a root password of the root user to
execute the privilege commands.
Manual Pages

• Manual pages have all the information about


the commands.
• They are also called man pages.
• Example: man cat command to view the
function, description, and options of the cat
command.
Manual Sections

The manual pages are further divided into several sections. They are :

• The Executable programs or shell commands


• System calls
• Library calls
• Special files
• File formats
• Miscellaneous
• Games
• System admin commands
• Kernel routines
Manual Captions

A command’s manual page has several captions:

• Name
• Synopsis
• Description
• Options
• Exit values
• Files
man -k Command

• Use the command man -k <keyword>, keyword


can be anything.

• Example: Check for printf. This command will


extract all the text information that matches one
or more characters from the keyword.

• After extracting all the content, find the command


from the list. It is printf in this case.

• The number next to the command indicates the


section of the man page this command belongs to.
Find Command

The type command or which command is used to find the version of a command.

• The version of the command is selected


based on the path variable.
Moving Around the File System

• A directory is a file that contains the names of


the other files.

• It is also called a pointer as it points to the files


you are looking for.

• The command $ ls-l can be used to list the


contents of the directory and $ pwd to view the
current working directory.
Moving Around the File System

A file is defined as the space occupied by data on the hard disk.

• Every file or directory in Linux is assigned a numerical


value called inode.

• The system will not identify the files without the inode
numbers.

• Inode numbering will start from 2, as 0 and 1 are


reserved numbers.

• The default directory is root; its inode number is 2.


Soft and Hard Links

• As some files have long names, it might be difficult


to refer to them. Soft links help you refer to the
same files with a shorter version of the name.

• You can use a soft link to create two or more names


for a single file and use any one to refer to the file.
Soft and Hard Links

• Hard links are used to have a backup copy of the file without
having to occupy any additional space.

• This is useful in case of accidental deletion of files. So, even if


one file is removed, you can retrieve the same data using the
copied version.

• Any change in one file gets reflected in all the copied files.

• The copied files have the same inode number.


Manipulating Commands

Some of the commands used to manipulate files are:

cp Copy mkdir Create a directory

mv Rename chmod Change permissions

rm Remove chown Change ownership

ls List files and directories


Creating Files and Directories

• The three ways to create a file in Ubuntu are:

o touch command

o cat command

o vi editor.

• The file created by any of these three methods occupies zero bytes of space.

• After entering the required data in the created file, use the control + d keys to save the file.
Creating Files and Directories

The mkdir command is used to create a directory.

Syntax:

mkdir <directory_name>

Hierarchy of directories can be created using this command.


Copying Files and Directories

In Linux, the command cp is used to copy a file or its contents from one
folder to another folder.

Syntax:

cp <source_filename> <destination_filename>
Copying Files and Directories

The different options available for the copy command are:

Option Description
-i Ask for user permission before writing to the destination file
-b Create a backup copy of the destination file
-f Copy file to the destination file forcefully if you don’t have permission
-p Preserve file attributes if possible
Copying Files and Directories

• The copy command of a directory is similar to the copy


command of a file.
• The option -r will recursively copy the contents of the
source directory to the destination directory.

Syntax:

cp -r <source_dir> <destination_dir>
Renaming Files and Directories

The mv command in Linux is used to rename a given file.

Syntax:

mv <old_file_name> <new_file_name>
Renaming Files and Directories

The same mv command is used to rename a directory.

Syntax:

mv <old_dir_name> <new_dir_name>
Moving Files and Directories

The mv command used for renaming files and directories can be used to move them
to a different location.

• The only change in the syntax is that instead of file or


directory name, you use the file location.

• If you compare the mv command with the cp


command, you see that the mv command deletes the
source location when it moves the files or directories
to the destination location.

Syntax:

mv <source_location> <destination_location>
Moving Files and Directories

The different options available for the mv command are:

Option Description
-i Ask user’s permission before performing the task
-f Ask user’s permission while writing protected files
-n Prevent overwriting of an existing file at destination
-b Backup the destination file
Removing Files and Directories

The rm command which stands for remove is used to delete or remove files and directories.

A directory can be removed only after all the files and directories within it are removed.
df Command

The df command is used to view the file system usage and the mount point of the file system.
df Command

The different options available for the df command are:

Option Description
-a Display the information about the file systems
-h Display the same file system information in a human readable format
-i List the information of inode
free Command

The free command is used to display the information of memory used by the system.

• There are two types of memories.


Physical memory, represented by Mem,
and swap memory.

• The information displayed by the free


command includes: total, used, free,
shared, buff/cache, and available.
top Command

The top command is used to display the information of processes running in Linux.

• The information provided is dynamic.

• The different information displayed includes,


PID, PR, VIRT, RES, SHR, USER, %CPU, TIME, NI,
and %MEM.
uname Command

uname command will provide the information regarding the OS distribution,


release version, CPU architecture, and kernel version.
uname Command

The different options available for the uname command are:

Option Description
-a Print the system information in a specific order
-s Print the kernel name
-n Print the hostname
-r Print the kernel version
-v Print the current kernel version
-m Print the machine hardware information
lsb_release Command

The lsb_release command is used to display the installed Linux distributor ID, release
version, and codename.
lsb_release Command

The different options available for the lsb_release command are:

Option Description
-a Print the OS distribution and releases information
-d Display the description
-c Display the code
ip Command

The ip command is used to display the IP related details of the system.

The different information displayed includes interface name, ip address,


network mask, and mac address.
lspci Command

The lspci command displays the machine hardware information based on the PCI architecture.

The information includes PCI bridge, VGA controller, Ethernet controller, USB controller,
audio device, and IDE interface.
lsusb Command

lsusb command is used to display the information of various USB devices connected to the system.
Key Takeaways

The sudo command in Linux elevates the privilege of a normal user to


perform certain restricted tasks as a normal user.

File system can be defined as a method of organizing and


managing data in the form of files and directories.

Soft links help you refer to a file with a long name with a shorter
version of the name.

mkdir command is used to create directories in Linux.


Knowledge Check
Knowledge
Check
Which command is used to view the information of running tasks or processes?
1

A. df

B. mv

C. top

D. rm
Knowledge
Check
Which command is used to view the information of running tasks or processes?
1

A. df

B. mv

C. top

D. rm

The correct answer is C

The top command is used to view the information of running tasks or processes.
Knowledge
Check
Which command is used to display the manual pages of a command?
2

A. man

B. manual

C. help

D. show
Knowledge
Check
Which command is used to display the manual pages of a command?
2

A. man

B. manual

C. help

D. show

The correct answer is A

The man command is used to display the manual pages of a command.


Knowledge
Check
Which command is used to view the Linux release version?
3

A. cp

B. help cp

C. man cp

D. lsb_release
Knowledge
Check
Which command is used to view the Linux release version?
3

A. cp

B. help cp

C. man cp

D. lsb_release

The correct answer is D

The lsb_release command is used to view the Linux release version.


Knowledge
Check
Which command is used to know the mount point of a file system?
4

A. df

B. dd

C. cd

D. mv
Knowledge
Check
Which command is used to know the mount point of a file system?
4

A. df

B. dd

C. cd

D. mv

The correct answer is A

The df command is used to view the mount point information of a file system.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy