0% found this document useful (0 votes)
17 views16 pages

DFT Training - 0 Linux Commands

The document outlines various Linux commands including grep, sed, and file management commands for tasks such as counting words, creating sequences and directories, checking memory, and modifying files. It also covers overriding commands, printing specific columns, and zipping files. Additionally, it provides examples for each command to illustrate their usage effectively.

Uploaded by

sharath A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views16 pages

DFT Training - 0 Linux Commands

The document outlines various Linux commands including grep, sed, and file management commands for tasks such as counting words, creating sequences and directories, checking memory, and modifying files. It also covers overriding commands, printing specific columns, and zipping files. Additionally, it provides examples for each command to illustrate their usage effectively.

Uploaded by

sharath A
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

LINUX COMMANDS

Grep commands
Sed commands
Overriding commands
Zipping commands
GREP COMMAND
To count no of user-defined words in the code, we use
grep “^anil” Yogish.txt(filename).
grep -c “anil” Yogish.txt--- for count.
grep -i “anil” Yogish.txt--- for including capital letters.
grep -c “^anil” Yogish.txt |wc -l --- for count(numbers).
grep help ---for more commands
Sequence creation

For sequence (number) creation


seq 1 500 > Yogish1.txt – For creating 1 to 500 numbers.
Series directory creation
For creating series of directories like folder inside folder.
mkdir -p Yogish2/Yogi/Yog– Internal folders can be created by using single command.

For deleting 100 lines in a single command.


100dd ---editor command( no need to give insert mode).
We have point the cursor from which line we want to delete.
For copying same line ten times.
yy 10 p ---editor command (no need to go to insert mode).
We have point the cursor from which line we want to copy.
Memory checking
For checking the full disc memory.
df -kh---to check the total storage.
For checking the memory of each file.
du -sh*(* for all files separately).
SED commands
To replace a name in the code without opening the commands prompt, we can use sed
commands.
Ex:To replace anil to Rajanni in the code
sed -i.bak ‘s/anil/Rajanni/g’ Yogish.txt
.bak- Backup file where you can have the previous file stored safely
s-substitute
Anil- Source
Rajanni-Destination
g-Globally
Yogish.txt- Filename
SED commands
To select and replace the string from 4-7 lines we use
sed -I ‘4,7 s/Rajanni/good_boy/’ Yogish.txt
SED commands
For printing the whole string in the file, we use
sed -n ‘4,$p’ Yogish.txt
$ indicates the total no of lines( Ex: we have 50 lines in total, the $ will print from 4 to 50).
For printing the string form 4-7 lines alone in a file, we use
sed -n ‘4,7 p’ Yogish.txt
SED commands
Cat commands -to open the contents of file in
Terminal(only for small codes)-cat Yogish.txt
For modifying selected lines in the file
with one regular expression.
Example-sunil, sunil1, sunil9
sed -i ‘s/Yogish[0-9]/bad_boy/g’ Yogish.txt
For modifying selected lines in file with
more than one expression.
sed -i ‘s/Sharath[0-9][0-9]/Sharath_sir/g’ Yogish.txt
Print commands
Printing particular column of a file.
awk ’{print $1}’ Yogish.txt
awk ’{print $2}’ Yogish.txt
Print commands
To print the first 10 lines in the code.
head filename.txt
To print the last 10 lines in the code.
tail filename.txt

Creating dummy file


touch filename.txt
Overriding commands
Before overriding
sed -i ‘/Report/i\100’ Yogish.txt
After overriding
sed -i’/Sharath_sir/a\777’ Yogish.txt
Paste commands
For unlinking a file
unlink--command
For linking
ln-s -- link a file in same directory
For linking a file to some other directory
ln -s filename-- just to link to other directory.
For general pasting data from one file to another file
Paste Yogish.txt Chinny.txt
Yogish.txt - Source
Chinny.txt- Destination
Zipping commands
For zipping a file.
gzip filename
To check the memory occupied by the file.
du -sh filename.gz
To unzip any file that’s been zipped.
gunzip filename
VERSION CONTROL

You might also like