The document provides information about various Linux commands:
- The grep command searches files for patterns and prints matching lines. Common grep options include -i to ignore case and -n to print line numbers.
- The cut command extracts sections from files by byte position, character, or field and writes to standard output. It is used to select specific columns from a file.
- The paste command joins files horizontally by outputting lines consisting of lines from each file separated by tabs. It is commonly used to merge information from multiple files.
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
Linux Commands
1. Dr. D. P.
Mishra
Digitally signed by Dr. D. P. Mishra
DN: cn=Dr. D. P. Mishra, o=durg,
ou=BIT, email=dpmishra@bitdurg.
ac.in, c=IN
Date: 2023.02.14 13:34:20 +05'30'
2. grep command
• grep stands for global search for regular expression and print.
• The grep filter searches a file for a particular pattern of characters, and
displays all lines that contain that pattern
• searched pattern in the file is referred as the regular expression
• Syntax :
• grep [options] pattern [files]
• Options Description
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
3. Example
$cat > geekfile.txt
unix is great os. unix was developed in Bell labs.
learn operating system.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
$grep -i "UNix" geekfile.txt
Output:
unix is great os. unix was developed in Bell labs.
Unix linux which one you choose.
uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
4. egrep
• The egrep (Extended Global Regular Expression Print) command
• It is text processing tool that searches for patterns or regular
expressions in a specified location.
• The tool provides the same output as grep in faster mode
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
5. fgrep
• The fgrep command displays the file that contains the matched line if
you specify more than one file in the File parameter.
• The fgrep command differs from the grep and egrep commands
because it searches for a string instead of searching for a pattern
• fgrep is equivalent to grep -F command and it uses a fixed string for
search and hence it performs a faster search
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ fgrep [OPTIONS] PATTERNS [FILES] $ cat input.txt
6. cut command
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
• Linux cut command is useful for selecting a specific column of a file.
• It is used to cut a specific sections by byte position, character, and field
and writes them to standard output.
• It cuts a line and extracts the text data
• Syntax :
• $ cut OPTION... [FILE]...
7. Example
• $ cat > state.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
Apply following commands on state.txt:
List Without ranges: $ cut -b 1,2,3 state.txt
List with ranges : $ cut -b 1-3,5-7 state.txt
$ cut -b 1- state.txt
$ cut -b -3 state.txt
$ cut -c 2,5,7 state.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
8. Paste Command
• Paste command is used to join files horizontally (parallel merging) by
outputting lines consisting of lines from each file specified, separated
by tab as delimiter, to the standard output.
• When no file is specified, or put dash (“-“) instead of file name, paste
reads from standard input and gives output as it is until a interrupt
command [Ctrl-c] is given.
• Syntax: paste [OPTION]... [FILES]...
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
9. $ cat > capital
Itanagar
Dispur
Hyderabad
Patna
Raipur
$ paste number state capital
$ paste -d "|" number state capital
1|Arunachal Pradesh|Itanagar
2|Assam|Dispur
3|Andhra Pradesh|Hyderabad
4|Bihar|Patna
5|Chhattisgrah|Raipur
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Example
10. unmae & wget command
$ uname
• You can use the command to get the release number, version of Linux, and
much more.
• The “-a” flag is used to get detailed information.
$ wget
• You can use the wget command to download the content from the internet;
• for instance, the following command will download VirtualBox.
$ wget https://download.virtualbox.org/virtualbox/6.1.26/VirtualBox-6.1.26-
145957-Win.exe
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
11. apt-get or –apt command
• Most important and most used commands of Ubuntu that works with
Ubuntu Advanced Packaging Tool (APT);
• You can use this “-apt-get” or “-apt” to install or remove packages
• The “apt” requires sudo privileges to successfully execute the
command.
• Syntax : $ sudo apt install [packagename]
• To install vlc media player package use
• $ sudo apt install vlc
• To remove package - $ sudo apt remove [packagename]
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
12. history command
• The history command shows the
list of commands (with numeric
numbers) executed
• $ history
• One can execute any of the listed
commands
• If you want to execute the 2nd
command (which is apt update
command), then you have to write
“!74” to get the result of that
command:
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
13. ps command
• ps - using the -ps command, you will be able to get the list of
processes.
$ ps
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
14. w command
• W command will display the user details that are currently logged into
the system
• $ w
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
15. passwd
• passwd - With the help of the passwd command, you can change the
password of your Ubuntu user:
• You must pass “username” to “passwd” to change the password of
that; for example, the command given below will change the password
of user “6cse01”
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
16. hostname command
• This command will print your hostname on the terminal
• $ hostname
• bitlinux@6cse01 $ bitlinux
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
17. ping command
• Ping - you can use the ping command to check the connectivity to your server;
• for example, the command below will ping to YouTube and also prints the
response time
• $ping hostname or ip-address
• $ ping youtube.com
• $ ping google.com
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
18. $ uptime -shows how long system is running
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
19. $ users – shows username who are currently logged in
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
20. $ service – call and execute script
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
$ service --status-all
21. $ ps – display about running process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
22. kill, killall and pkill
• kill terminates processes based on Process ID number (PID),
• While the killall and pkill commands terminate running processes
based on their names and other attributes.
• Example
$ ps
PID TTY TIME CMD
11571 pts/20 00:00:00 bash
22166 pts/20 00:00:00 ps
$ kill -s 0 11571
$ kill -s 0 11579
bash: kill: (11579) - No such process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
23. $ pmap – memory map of process
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
24. $ free – shows memory status
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
25. $ netstat – display network status
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
26. $ nslookup – check domain name of ip info
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
27. $ route - list routing table for your server
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
28. ftp command
• Here, ftp stands for File Transfer Protocol. This utility helps you upload
and download your file from one computer to another computer.
• $ftp hostname or ip-address
• $ftp 172.16.0.100
• ftp> dir
• ftp> get <filename>
• ftp> quit
• 221 Goodbye.
• $
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
29. More Commands
• join
• Tee
• Comm
• Cmp
• Diff
• tr
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
30. Text Editing with Vi Editor
(vi- Visual Editor)
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
31. Vi Editor
• The VI editor is a screen based editor used by many unix users.
• It is the default editor that comes with the UNIX operating systems
and is called vi (visual editor).
• The improved version of vi is called the vim editor ( vi improved) is
available with Linux systems.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
32. Modes of vi editor
• There are three basic modes of vi:-
1. Command mode
2. Insert mode
3. Line mode
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
33. 1. Command mode:-
• This the default when you enter vi.
• In command mode - most letters, or short sequence of letters, that
you type will be interpreted as commands, without explicitly pressing
Enter.
• If you press ESC when you’re in command mode, your terminal will
beep at you.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
34. 2. Insert Mode
• Insert mode:- In insert mode, whatever you type is inserted in the file
at the cursor position.
• Type i to enter insert mode from command mode;
• press ESC to end insert mode, and return to command mode.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
35. 3. Line mode
• Line mode:- Use line mode to enter line oriented commands.
• To enter line mode from command mode, type a colon(:).
• Your cursor moves to the bottom of the screen, by a colon prompt.
• Type a line mode command and then press ENTER.
• Each time you use a line mode command, you must
• type a colon to enter line mode,
• then type the command by the colon prompt at the bottom of the screen,
• then press ENTER when you finish typing the command
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
36. Starting and stopping vi
• To edit file
$ vi generalnote
• Above command starts vi and allocates a memory buffer for
file generalnote
• If the file already exists, text in the file will be displayed on the screen.
• You can't add any text to the file until you go into insert mode because
vi started in the command mode.
• The tilde character (~) you see in the screen shot shows that the file
has no text in these lines.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
37. Starting and stopping vi
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
• The tilde character (~) you see in the screen
shot shows that the file has no text in these
lines.
• To switch to insert mode, press the
i character
• Press the Esc & : key to return to command
mode.
• To save file use :w command.
• To quit the editor use :q command
• Use : x or wq to save and quit in one step
38. Cursor Movement Commands
• The mouse does not move the cursor
within the vi editor screen. You must
have the key commands listed.
• Before using any of these
commands, make sure that you are
in the command mode by pressing
the ESC & : key.
• You can also instruct the vi editor to
display the line number with each
line using the :set
number command.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Symbol Function
l Move one character right
h Move one character left
j Move one line down
k Move one line up
< space > Move one character right
G Go to last line of the file
nG Go to line number n in the file
$ Go to end of current line
^ Go to start of line
w Go to beginning of next word
b Go to beginning of previous word
e Move to end of word
H Go to first line of screen
M Go to middle line of screen
L Go to last line of screen
( Go to beginning of sentence
) Go to end of sentence
{ Go to beginning of paragraph
} Go to end of paragraph
39. Inserting text in vi
Command Effect
i Start inserting text at the current cursor location.
I Start inserting text at the beginning of the current line.
a Start inserting text at the next character position relative to the current cursor
location.
A Start inserting text at the end of the current line.
o Append a blank line just below the current line and start inserting text from the
beginning of that line.
O Append a blank line just above the current line and start inserting text from the
beginning of that line.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
40. Deleting text in vi
Command Effect
x Delete character at current cursor location.
nx Delete n characters starting at current cursor location.
X Delete previous character from the current cursor location.
nX Delete n previous characters from the current cursor location.
dd Delete current line.
db Delete previous word.
dw Delete from current cursor location to the end of word.
dG Delete to the end of file including current line.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
41. Text replacement command in vi
Command Effect
r Replace current character remaining in command mode
s Replace current character and go to insert mode
R Replace multiple characters until the key is pressed
cw Change to the beginning of next word
cc Change entire line
cG Change to the end of file
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
42. Cut, Copy, and Paste Commands
Command Effect
yy Copy or yank current line
nyy Copy n lines starting from current line position
p Paste yanked text after the current cursor position
P Paste yanked text before the current cursor position
:m a Move current line and paste after line number a
:a,bmc Move lines from a to b and paste after line number c
:a,btc Copy lines from a to b and paste after line number c
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
44. What is in a shell script?
• A shell script is a text file that contains a sequence of commands for a
UNIX-based operating system.
• Shell scripting is an important part of process automation in Linux.
• Scripting helps you write a sequence of commands in a file and then
execute them.
• This saves you time because you don't have to write certain
commands again and again
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
45. How to write shell script
• Following steps are required to write shell script:
• (1) Use any editor like vi or gedit to write shell script.
• (2) After writing shell script set execute permission
• (3) Execute shell script as
• syntax:
• bash shell-script-name
• sh shell-script-name
• ./your-script-name
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
46. First shell script
echo "Our first script"
echo "--------------------------------------------"
echo # This inserts an empty line in output.
echo "We are currently in the following directory"
pwd
echo "This directory contains the following files"
ls
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
47. Prog1: Write following shell script, save it, execute it and
note down the it's output.
$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
echo "Today is c ";date
echo "Number of user login : c" ; who | wc -l
echo "Calendar"
cal
exit 0
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
48. Prog 2 : Using if-else to check whether two numbers are equal
a=10
b=20
if [ $a -eq $b ]
then
echo " Number is equal "
else
echo " number not equal "
fi
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
49. C- Program in Linux Environment
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg