A A A
logo2




Copy files



If you want to list the content of a directory you can use command ls.

owi@laptop:~$ cp ./unix/filename1 ./

File filename1 from directory unix was copied to the working directory.


The command mv is similar. It moves a file from one place to another .

owi@laptop:~$ mv ./unix/filename1 ./

File filename1 from directory unixwas moved to the working directory.




Show a file



The command more shows the first part of a file, just as much as will fit on one screen.

owi@laptop:~$ more /etc/passwd


Warning!
The command more sometimes doesn’t work. Then you can use pg or less. It has the same function.




First and last lines



File /etc/passwd has got a lot of lines. If you would like to see only first ten lines you can use command head.

owi@laptop:~$ head /etc/passwd

If you want to see other number of lines write head –n (number of lines) .

owi@laptop:~$ head -n15 /etc/passwd

If you would like to see only last ten lines you can use command tail.

owi@laptop:~$ tail -n4 /etc/passwd




How many bytes, words and lines is in file



If you would like to know how many bytes, words and lines is in the file you can use command wc.

owi@laptop:~$ wc /etc/passwd

If you use wc –l you will see only how many lines is in the file.

owi@laptop:~$ wc -l /etc/passwd




Sort contents of the file



If you would like to sort contents of some file you can use the command sort.

owi@laptop:~$ sort filename



Uniq lines in file



If you want to see uniq line in files use command uniq

owi@laptop:~$ uniq filename

The command uniq show only lines which don’t repeat.

Warning!!
The file should be sort at first. .




Cut fields of each line of a file



If you would like to cut some fields of each line of a file you can use command cut -f (number of fields which should stay).

owi@laptop:~$ cut -f1 filename

You will see only the firs field of line of a file. Sometimes the fields are separated with another symbol for example “:” like in file /etc/passwd. Then you must add –d”:”.

owi@laptop:~$ cut -f1 -d":" /etc/passwd

You can print more then one field but you must separate it with “,”.

owi@laptop:~$ cut -f1,3 -d":" /etc/passwd



Paste files



If you would like to paste two files you can use command paste. You can of course paste more then two files but then you must separate their names with “,”.

owi@laptop:~$ paste file1 file2



Compare files



To compare two files you can use command cmp then write the name of the files witch should be compare.

owi@laptop:~$ cmp file1 file2

If there will be some differences there will be shown the number of fields . If the files will be the same there will be nothing.


We can compare files with command diff too.

owi@laptop:~$ diff file1 file2

If there won’t be differences there will be shown the number of fields . If there will be some differences there will be nothing.



Autor: Aleksandra Przybyło
aleksandraprzybylo@gmail.com