Wednesday, July 26, 2017

Linux Basics - File Manipulations

In the previous post we looked into some commands related to file system of Linux. In this post we'll look into some commands related to file manipulation.

As mentioned in the previous post you can create empty files using touch command.
We can use a text editor like vi editor, nano or emacs to edit these files.
vi [filename] will open up the file in vi editor


you can use the text editors to edit and save files.

cat command can be used to print the content of a file on to the screen without having to open the file using a text  editor.

cat command can also be used to write data into files directly from the terminal
cat > mytext.txt will let you write data to mytext.txt until you press ctrl+D to save the data to the file

cat command prints entire file on the terminal, but if the file is  large this could raise problems. So there are few other commands that are more user friendly. 
head -n number_of_lines [filename] will display the given number of lines from the beginning of the file

tail command also behave the same as the head but it displays the given number of lines from the bottom of file.
less and more commands will print the content of the file until the screen is full and then will wait until enter key is pressed to display the next portion of the file. less command provide more text searching facilities in compared to head command. 
Lets meet with more Linux basics related to networking in the next post.



No comments:

Post a Comment