Managing Files

 Linux includes a number of commands to help you read files in different ways. You can read files from top to bottom or vice-versa, you can be limited to few lines, you can count the lines, words, alphanumeric characters within a file, In addition linux lets you search through the files.

1. file
Although some distribution differentiate between file types by colour, but there are no standard extensions in Linux. Executable files don"t end in .exe similarly for documents file may not end in .doc . The file command lets you view type of each file.


2. cat
The concatenate(cat) command is used to read a file in linux. It sends the text of a file to standard output.

# cat file

It can even be used to read the multiple files, in sequence, with the
cat file1 file2 command


3. head and tail
The head file provides you with the view of the first few lines of the file; while the tail command provides you with the view of the last few lines of the same file. You can regulate the amount of the file that you see with switches. For eg:-

# head -n15 abc.txt
It provides you with the first 15 lines of abc.txt file similarly if you substitute head with tail it provides you with the last 15 lines of abc.txt file.


           COMMAND               RESULT
   head 400b abc.txtit shows the first 400 bytes of the file abc.txt
   tail 4k abc.txtit shows final 4kb of the file known as abc.txt
   head 3m abc.txtit shows first 3mb of the file abc.txt
   tail -n22it shows last 22lines of abc.txt

Note:- head command is generally used when you want to know what actually the file is about which can be interpreted by knowing first few lines but what the tail command is used you guess it and provide it in comments section than i will let you know.


4. more and less
The more and less commands used to view the contents of a text file.
The more command is to review the contents of the file one page at a time.
The less command is more versatile; unlike more, it allows you to scroll up and down any large file by using page up and down keys.

Because they can read text a little bit at a time, these commands can open file more quickly than text editor like vi.

# less -N bigfile



Related Posts:-

Comments

0 Responses to "Managing Files"

Post a Comment

 

Managing Shell And its Secrets

Subscribe To Get Update On Mobile

Subscribe
Get updates of latest post on your mobile free