0% found this document useful (0 votes)
10 views5 pages

File - Handling Commands

The document provides a comprehensive overview of various command-line utilities used in Linux, including 'find', 'paste', 'cut', 'grep', 'sed', 'head', 'sort', 'uniq', 'split', 'join', 'expand', 'unexpand', 'tail', 'nl', 'awk', 'last', 'wc', and 'tr'. Each command is explained with examples of usage, detailing their functions such as searching for files, manipulating text, sorting data, and counting lines or characters. The document serves as a practical guide for users looking to utilize these commands effectively in their workflows.
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)
10 views5 pages

File - Handling Commands

The document provides a comprehensive overview of various command-line utilities used in Linux, including 'find', 'paste', 'cut', 'grep', 'sed', 'head', 'sort', 'uniq', 'split', 'join', 'expand', 'unexpand', 'tail', 'nl', 'awk', 'last', 'wc', and 'tr'. Each command is explained with examples of usage, detailing their functions such as searching for files, manipulating text, sorting data, and counting lines or characters. The document serves as a practical guide for users looking to utilize these commands effectively in their workflows.
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/ 5

​ HYPER COMMANDS ​​


●​find
Used to search to tell you if a word exists in a file or not .
​ kali</> find ~/Desktop -name *.txt #find all file in Desktop that end with .txt
​ kali</> find -name “[Link]” #you should spesific directory first
#if exist 3 directorys and you want just search in 2 :
kali</> find dir1 dire2 -name “text”

#if you not have all the name exacly.


​ kali</> find . -name “.txt” -exec grep -l “some thing” {} .
​ kali</>find . -iname “txt” #find with issensetive key

kali</>find . -type f “name” #this give you -f for regular files and d for directorys
You can also costomize find with size and empty

●​past
Understanding this command by example:
​ [Link] ​ ​ ​ ​ ​ ​ [Link]
​ A​ ​ ​ ​ ​ ​ ​ 1
B​ ​ ​ ​ ​ ​ ​ 2
C​ ​ ​ ​ ​ ​ ​ 3
​ kali</> paste [Link] [Link]
A​ 1
B​ 2
C​ 3
kali</> past -d ‘,’ [Link] [Link] #set , like separator (the default is tab)
​ A,1
B,2​ ​ ​ ​ ​ #you can set multiple separators
C,3

●​cut
The cut command used to extract a part of text speciefed by user from the input or
text file is most used to manipulate data.
-​You can extract specific caracters :
kali</> cut -c 1 [Link] # Extrait le premier caractère de chaque lignes
a
​ 1
kali</> cut -c 1-3 [Link] # Extrait les caractères 1 à 3
​ Abc
123
kali</> cut -c 2,4 [Link] # Extrait les 2ᵉ et 4ᵉ caractères
​ bd
​ 24

-​This extractin spesific columes if separated by tab by default


kali</> cut -f 2,3
col2 ​ col3
​ 123 ​ xyz

-​You can specifiy the separator of colums like space ‘ ’


kali</> cut -d ' ' -f 1 [Link]
hello
linux
kali</> cut -d ' ' -f 2-3 [Link] #specificator separation (space)
world test
bash cut
#When you use the -s option, cut only outputs lines that contain the delimiter. Lines without
the delimiter are ignored.
kali</> cut -f 2,5 -s [Link]
●​grep
Get more about it it also used to extract ip adress from a file…
●​sed
The sed is usd to search for a word and change it in whole the text by another you
enter them.
kali</> sed “s/oldword/newword/g” [Link]
kali</> sed “1s/oldword/newword/” [Link] #this 1 to choose the ligne, (1,3)
kali</> sed “s/oldword/newword/” [Link] #don’t set g for apply changes just in
the fisrt word in each ligne.
kali</> sed -i “s/oldword/newword/g” [Link]
#the i is for save changes permanetly becaus if you does’nt use it the change set just
for your show not in the original file.

#to delet a word from a text file just don’t set anything between the last slachs
kali</> sed -i “s/oldword//g” [Link]
​ #search a line by a word when it find the word delet the whol ligne :
​ kali</> sed -i “/word/d” [Link] #just remove the s and add d instead of g
​ #remove empty lines :
​ kali</> sed -i “/^$/d” [Link]
​ #remove first or 2 lines :
​ kali</> sed -i “1,2d” [Link]
●​head
Show you the top 10 lines.
kali</> head [Link]
kali</> head -n1 [Link] #for specify the number of line to display
●​sort
The sort is use the ASCII to sort text, then the uppercase it went befor lowercasses
then Z < a :
kali</> sort [Link]
kali</> sort -r [Link] #reverse the order
●​uniq
The uniq command is used to output a text file when filtering dublicated lignes :
​ kali</> uniq [Link]
​ kali</> sort [Link] | uniq

●​split
It is a command used to divide a file to multipe other files in function of line number or data size:
-by lines :
kali</> split -l 100 [Link] Ahmed_
Lignes option​​ number of files you want ​ the name of files begane with

-by data size:


kali</> split -d 4k [Link] Ahmed_ #the d for size{Mega, Kilo}

●​join
Merge files or many files :
kali</> join [Link] [Link]

●​expand
Convert tab to space separator :
kali</> echo -e "nom\tprénom" | expand

●​unexpand
Convert space to tab separator :

●​tail
Show you the 10 end line it is the convert of head with option -n to specify lines, and
has a spetial parameter is -f this show the change in the real time
​ kali</> tail -n 12 [Link]
​ kali</> tail -f [Link]

●​nl
Used to show you the number of lines of a text file : (search more).
kali</> nl [Link]
●​awk
awk is used like cut but in the situation if exist many spaces and cant specify the space
like separator can conseder each space like a column:
kali</> awk {print $1} [Link] #the $1 is just to specify the column to display
kali</> ll
total 8
-rw-rw-r-- 1 kali kali 0 Mar 19 04:29 [Link]
-rw-rw-r-- 1 kali kali 304 Mar 20 20:32 file1
-rw-rw-r-- 1 kali kali 43 Mar 20 22:19 file2
-rw-rw-r-- 1 kali kali 0 Mar 19 04:28 file3
​ kali</> ll | awk '{print $1}'​ #$0 is to show all
​ total
-rw-rw-r--
-rw-rw-r--
-rw-rw-r--
-rw-rw-r–-
​ kali</> awk -F “;” ‘{print $1}’ [Link] #the -F is to specify the separator
​ kali</> awk -F “ ” ‘{print $1 $3}’ #you can show more than one column
​ kali</> awk -F “ ” ‘{print $1 “ ” $3 “/”}’ # you can add more things between them
​ kali</> awk -F “ ” ‘{print $1*2”}’ #the variable $ can be multiplied or…
​ kali</> awk -F "/" '{print $2/$3}' /etc/shells #just an important example
​ kali</> awk '{print $NF}' ​ #to show the last column from each ligne​
​ kali</> awk 'NR > 1 {print}' /etc/shells #skip the first ligne
​ kali</> awk '/^root/ {print}' /etc/passwd #^signify the begane of word
​ #this show just the cols who beganes with root
​ kali</>awk '/^[0-9]/ {print}' [Link] #select just the lignes who began with num

​ -more eazy concepts in awk in this link​

●​last
Show you the last logins list
●​wc
Is to count the number of caracter and lignes and words.
kali</> wc [Link]
​ 3 5 89 lignes ​ words caracters
​ kali</> wc -l ​ #the option l is for show just num of linges : -w and -

●​tr
It translate the output to a specific for (most used to make lowercase into uppercase)
​ kali</> echo “hello world” | tr [a-z] [A-Z]
​ ​ HELLO WORLD
​ kali</> echo “hello world” | tr -d [a-z] #delet all lowercase caracte

You might also like