Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

02-To Run of Various Shell Commands

The document provides information about various Linux shell commands. It discusses the basics of shells and different types of shells like command line shells and graphical shells. It then lists and describes several common Linux shell commands across different categories - basic commands for directory listing, file manipulation etc., commands for system information, and commands used for file handling. The commands covered include ls, cd, pwd, mkdir, rm, cp etc. and their usage is explained.

Uploaded by

Vedant
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

02-To Run of Various Shell Commands

The document provides information about various Linux shell commands. It discusses the basics of shells and different types of shells like command line shells and graphical shells. It then lists and describes several common Linux shell commands across different categories - basic commands for directory listing, file manipulation etc., commands for system information, and commands used for file handling. The commands covered include ls, cd, pwd, mkdir, rm, cp etc. and their usage is explained.

Uploaded by

Vedant
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Practical No.

N 02

Aim : To run
r and obsserve outpu
ut of variou
us linux sheell comman
nds

Theoryy :

Shell:
A shell is special user
u program m which prrovide an innterface to user
u to use ooperating sy ystem servicces.
Shell acccept humaan readable commands from user and converrt them intoo something g which kerrnel
can undderstand. Itt is a commmand languuage interp preter that execute
e commmands reead from innput
devicess such as keeyboards orr from filess. The shelll gets starteed when thee user logs in or start the
terminaal.

Linux Shell
S

Shell is broadly claassified intoo two categoories –


 Command Line L Shell
 Graphical shell
s

Commaand Line Shell:


S
mmand linee interface. A special prrogram called Terminaal in
Shell caan be accesssed by user using a com
linux/m
macOS or Command
C P
Prompt in Windows
W OS
O is proviided to typpe in the hu uman readaable
commannds such ass “cat”, “ls”” etc. and thhen it is being executee. The resullt is then displayed on the
terminaal to the userr.

Graphiical Shells:
Graphiccal shells prrovide meanns for manippulating proograms based on graphhical user in
nterface (GU
UI),
by allowing for operations
o s
such as opeening, closiing, movingg and resizzing windowws, as welll as
switchinng focus beetween winddows. Winddow OS or Ubuntu OS S can be connsidered as good exammple
which provide
p GU gram. User do not need to type in
UI to user foor interactinng with prog n command for
every acctions.

There are
a several shells
s are avvailable for Linux systeems like:
 BASH (Boourne Againn SHell) – It I is most widely
w used shell in Linnux system ms. It is usedd as
default logiin shell in Linux
L systemms and in macOS.$
m chaaracter is the default prrompt.

 CSH (C SH
Hell) – Thee C shell’s syntax and
d usage are very similar to the C programm
ming
language. The ‘%’ character is the default prompt.

 KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard
specifications etc.

Each shell does the same job but understands different commands and provide different built in
functions.

Shell Script:
Usually shells are interactive that mean, they accept command as input from users and execute
them. However some time we want to execute a bunch of commands routinely, so we have type in
all commands each time in terminal.

As shell can also take commands as input from file we can write these commands in a file and can
execute them in shell to avoid this repetitive work. These files are called Shell Scripts or Shell
Programs. Shell scripts are similar to the batch file in MS-DOS. Each shell script is saved with .sh
file extension e.g. myscript.sh.

A shell script have syntax just like any other programming language.A shell script comprises
following elements –

 Shell Keywords – if, else, break etc.


 Shell commands – cd, ls, echo, pwd, touch etc.
 Functions
 Control flow – if..then..else, case and shell loops etc.

Shell Commands:

1. Basic Commands
1.1 history:
The simple command “history” displays the list of all commands entered since the user started
the session.
Syntax: history
To clear all the previous history use command “history -c”.

1.2 help
The command of “help” provides you help to learn about all the built-in commands.
Syntax: help

1.3 dir
The command “dir” stands for directory and it is used to display the list of all directories or
folder in the current directory.
Syntax: dir

1.4 ls
The command “ls” displays the list of all directories, folder, and files present in the current
directory.
Syntax: ls

1.5 ls –ltr
The above-mentioned command displays the name of directories, folders, files with their
respective owner name, group’s name and rights your user have over these.

Syntax: ls -ltr
1.6 cd
The command “cd” stands for change directory and it is used to change the current directory
user is operating in via Terminal.
Syntax:

cd destination_directory’s_name
(to move forward from your current directory to the next directory within current directory)

cd .. (to move back in the previous directory from your current directory)

1.7 pwd
The command “pwd” displays the path of the current directory user is operating in via
Terminal.
Syntax: pwd

1.8 clear
The command “clear” is to clear the screen of Terminal.
Syntax: clear

1.9 whereis
The command “whereis” is self-explanatory, as it displays the path where the package for
specific built-in Linux command locates.

Syntax: whereis command_name

1.10 whatis
The command “whatis” is also self-explanatory, as it displays a brief description of what is the
functionality of specific built-in Linux command.

Syntax: whatis command_name

2. Commands used for System Information:


2.1 date
The simple “date” command displays the current date and time (including the day of the week,
month, time, time zone, year).

Syntax: date

2.2 TZ
By default, “date” command uses the time zone defined in path “/etc/localtime”. Linux user can
change the time zone via Terminal by using command “TZ”.

Syntax: TZ=Name_of_Time_Zone date

2.3 –set
Linux allows its user to set the current date and time of the system manually.

Syntax: date –set=”Date_in_format(YYMMDD) Time_in_format(HH:MM)”

2.4 df
The command “df” shows the amount of disk space used and disk space available on every file
system containing each filesystem’s name and its path.
Syntax: df

2.5 df –h
The command “df -h” shows the same result as the command “df” but now the data is in a more
human-readable form which can be easily comprehended by a new user.
Syntax: df -h

2.6 free
The command “free” displays the amount of free and used memory in the complete system.
Syntax: free

2.7 Ps
The command “ps” which is also known as process status command is used to provide
information about the processes currently running on the system, including their respective
process identification numbers (PIDs).

Syntax: ps

2.8 Uptime
The command “uptime” provides information about how long the system has been running in
one line. Result for this command includes the current time, the time duration system has been
running for, the number of users who are currently logged on, and the system load averages for
the past 1, 5, and 15 minutes respectively.

Syntax: uptime

2.9 w
The command “w” displays the detailed information about the users who are logged in the
system currently.

Syntax: w

2.10 passwd
The command “passwd” stands for password and it is used to change the password of the user.
Syntax: passwd user_name

2.11 exit
The command “exit” as the name says it is used to exit from the system and log out from the
current user.

Syntax: exit

2.12 shutdown
The command “shutdown” is used to shut down the system.
Syntax: shutdown

3. Commands used for File Handling:


3.1 mkdir
The command “mkdir” allows users to create directories/folders in the system. The user running
this command must have suitable rights over the parent directory to create a directory or they will
receive an error.

Syntax: mkdir New_Directory’s_Name

3.2 rmdir
The command “rmdir” allows users to remove directories/folders from the system. The user
running this command must have suitable rights over the parent directory to remove a directory
or they will receive an error.

Syntax: rmdir Directory’s_Name

3.3 rm
The command “rm” is used to remove files from the directory.
Syntax: rm file’s_name

3.4 mv
The command “mv” is used for two purposes

a) To move files or directories from one path to another path in the system.

Syntax: mv Source_File_name Destination_Path

Example:
Consider having two files in a directory (File1 and File2). Entering the command “mv File1
File2” will move data of File1 to File2 and delete source file(i.e. File1) from the system.

b) To rename a file or folder.

Syntax: mv File_name New_name_for_file

Example:
Consider having two files in a directory (File1 and File2). Entering the command “mv File1
File_Rename” will rename File1 to File_Rename in the same directory.

3.5 cp
The command “cp” is used to copy data from a source file to the destination file. Its function is
almost like the command “mv”. The only difference is by using the command “cp” the source
file is not removed from the directory after its data is moved to the destination file.

Syntax: cp source_file_name destination_file_name

3.6 cat
The command “cat” is a reverse of the command “tac”. It is used to display each line of the file
starting from the first row and finishing on its last row.

This command is more frequently used than “tac”.


Syntax: cat file_name

3.7 head
The command “head” prints the top N rows of data of the given input or file. By default, it prints
the first 10 lines of the specified files.
Syntax:

head -n File_name

3.8 tail
The command “tail” prints the last N rows of data of the given input or file. By default, it prints
the last 10 lines of the specified files.
Syntax:
tail -n File_name

3.9 echo
The command “echo” used to display any expression that is passed as an argument.
Syntax:

echo expression_to_be_displayed

3.10 grep
The command “grep” is used to search for a text in the specified file/folder.

Syntax: grep “expression_to_be_Searched” file_name_to_search_in

Example: grep “Are” B

The above-mentioned command will search for the word “Are” in the text of the file B.

3.11 zip
The command “zip” is used to compress one or more files and store them in a new file with .zip
extension.

Syntax: zip new_zip_file_name.zip

Example: zip Files.zip Check.txt Test.txt Output.txt

The above-mentioned command will compress all three files (Check.txt, and Test.txt and
Output.txt) and store these in a new file which we’re creating through this command i.e.
Files.zip.

3.12 unzip
The command “unzip” is used to decompress a .zip file and extract all the files within to current
directory.
Syntax: unzip zip_file_name.zip

Example: unzip Files.zip

Consider having a zip File named as Files.zip with a compressed .txt file in it. The above-
mentioned command will help you unzip the file (Files.zip) and extract the .txt file from it to the
current directory.

3.13 sudo
The command “sudo -I” is used to continue the session as a root user which has a lot more
privileges than normal system user.

Syntax: sudo -i

Result : Thus, we successfully run various shell commands on Ubuntu

You might also like