Você está na página 1de 4

1.

Listing Files in current directory: ls


Listing files in a specific directory: ls path
2. Display contents of a file cat file name
3. Displaying first 5 lines from a file head -5 filename
4. Changing the directories cd <target directory>
5 creating file (empty file): touch
6. Displaying last 5 lines of a file tail -5 filename
7. Copy contents of one file into another
Cp source file target file
overwritten.

//If the target file already have data then it will be

8. Creating a directory mkdir


9. Renaming and removing the files
Mv

<old file> <newfile>

Mv <file name>

tmp/

// Renaming
// Moving

10. Finding the numbers of line in a file


Wc <file name>
in a file
11.

// it can be used to find number of line, words and characters

To see or seek help regarding any command


Man <command name>

Head command:
By default it prints first 10 files from a file
Display first 3 lines
Head n3 filename.txt
Skip last 3 lines and print the remaining
Head n-3 filename.txt
Print first n bytes
Head c5 filename.txt
Skipping last n bytes
Head c-5 filename.txt
Print lines between 3 to 6 lines

Head -6 filename | tail -3


Tail Command
Tail n2 filename.txt
Print lines from the nth line
Tail n+2 filename.txt
Print last n bytes
Tail c5 filename.txt
Print characters from the Nth byte
Tail c+60 filename.txt
Print last lines from dynamically changing file
Tail f filename.txt
added to the file.

// it prints last 10 lines and waits for the new lines to be

Uniq Command:
Is used to suppress the duplicate lines from a file. It discards all the successive
identical lines except one from the input and writes the output.
Uniq [options] filename
c: count the occurrence of each line
d: prints only duplicate lines
D: prints all duplicate lines
f: Avoid comparing first N fields
i: Ignore case when comparing
s: avoid comparing first n characters
u: prints only unique lines
w: compare no more than N characters in lines.
> cat example.txt
Unix operating system
unix operating system
unix dedicated server

linux dedicated server

1. Suppress duplicate lines: its default behaviors is to suppress default lines.


Note: You have to pass sorted input to uniq as it compares only successive lines.
Uniq filename.txt
> uniq example.txt
unix operating system
unix dedicated server

linux dedicated server


If not sorted: sort filename.txt | uniq
2. Count of lines: it prefixes each line with the count
Uniq c filename.txt
2 unix operating system
1 unix dedicated server

1 linux dedicated server


3. Display only duplicate lines:
Uniq d filename.txt
Unix operating system
4. Display all duplicate lines
Unix operating system
Unix operating system
5. Skip first n fields in comparison:

6. Print only unique lines


Uniq -u filename.txt
Unix dedicated server
Linux dedicated server

SED Command: Stream Editor used to modify line in unix


>cat file.txt
unix is great os. unix is opensource. unix is free os.
learn operating system.

unixlinux which one you choose.


Replacing or substituting string
Sed s/unix/linux/ filename.txt
By default, it will replace the first occurrence of UNIX with Linux in each line and it
wont replace the second/third/fourth occurrence in a line

Unix Imp Questions:


Display 1oth line of a line
Head -10 filename | tail -1
How to remove the header from a file
Sed i 1 d filename.txt
How to remove footer from the line
Sed I $ d filename.txt

Você também pode gostar