Linux operatsion tizimida fayl tarkibi bilan ishlovchi buyruqlar juda ko’p. Ushbu buyruqlardan eng ko’p qo’llaniladigan asosiy qismini ko’rib chiqamiz. Quyidagi jadvalda biz ushbu buyruqlar bilan tanishamiz:
Buyruqlar | Vazifasi |
---|---|
grep | U berilgan fayldagi matn va satrlarni qidirish uchun ishlatiladi. |
head | U faylning boshlanishini ko’rsatadi. |
tail | U faylning oxirgi oxirgi qismini ko’rsatadi. |
more | Buyruqlar qatori tarkibni sahifa shaklida yoki ko’proq formatda ko’rsatadi. |
less | Buyruqlar qatori tarkibni sahifa shaklida yoki kamroq formatda ko’rsatadi. |
GREP buyru’gi
The ‘grep’ command stands for «global regular expression print». grep command filters the content of a file which makes our search easy.
grep with pipe
The ‘grep’ command is generally used with pipe (|).
command | grep <searchWord>
cat marks.txt | grep 9
grep without pipe
It can be used without pipe also.
grep <searchWord> <file name>
grep 9 marks.txt
grep options
- grep -vM: The ‘grep -v’ command displays lines not matching to the specified word.
- grep -v <searchWord> <fileName>
- grep -v 9 marks.txt
- grep -i: The ‘grep -i’ command filters output in a case-insensitive way.
- grep -i <searchWord> <fileName>
- grep -i red exm.txt
Head buyrug’i
The ‘head’ command displays the starting content of a file. By default, it displays starting 10 lines of any file.
head <file name>
head jtp.txt
Tail buyrug’i
Linux tail command is used to display the last ten lines of one or more files. Its main purpose is to read the error message. By default, it displays the last ten lines of a file. Additionally, it is used to monitor the file changes in real-time. It is a complementary command of the head command.
tail <file name>
tail num.txt
More buyrug’i
As ‘cat’ command displays the file content. Same way ‘more’ command also displays the content of a file. Only difference is that, in case of larger files, ‘cat’ command output will scroll off your screen while ‘more’ command displays output one screenful at a time.
Following keys are used in ‘more’ command to scroll the page:
- Enter key: To scroll down page line by line.
- Space bar: To go to next page.
- b key: To go to the backward page.
- / key: Lets you search the string.
more <file name>
more /var/log/udev
Less buyrug’i
The ‘less’ command is same as ‘more’ command but include some more features.
It automatically adjust with the width and height of the teminal window, while ‘more’ command cuts the content as the width of the terminal window get shorter.
less <file name>
less /var/log/udev