The commands on ubuntu (80%) – part 3

Tram Ho

One fine day, a friend asked me how this A, B command works, if I want this result, how do I run the command now, do you know? Ubuntu is not it, google search is done, but there are many that do not know how to look? It is time consuming, so if you know a little bit about the command in ubuntu then look at it immediately, save time, but also be proud of the girls. So stop learning and get the 20% of the most important and common right away.

You who have not read the previous article can see here .


The wc command gives us statistical information about the content of a file or an output received after a certain command. syntax:

The result of the command will give information in turn: Number of lines | Number of words | number of bytes | file name

As an example above the output includes: 4 lines | 6 words | 31 bytes | file name. It is also possible to specify options for the output:

  • Count the number of lines

  • Count the number of words

  • Count the number of bytes

The wc statement can be used to count the output of the commands:


The grep command is a very useful tool that, when you master it, will greatly help you with your daily work. grep stands for “global regular expression print”.

You can use grep to search for keywords contained in the file:

Use the -n option to display line numbers. Or combine with another statement to check the result of that statement.

Many times when viewing a line gives quite little information, grep provides -C option to display the number of lines before and after the keyword found.

By default, grep will search case sensitive – case sensitive search. Use the -i option to search by insensitive – no case sensitive.


Suppose you have an information file of cats for example:

Use sort to sort these names:

Sorted results will be displayed, while the file content remains the same, if you want to update the file information, use > file . Use the -r option to get the opposite result.

sort Not only works with files, sort can work with other commands, the output of which is a result stream – pipe. Therefore, you can use sort to sort the output of another statement. For example: ls


uniq is a useful command for truncating duplicate lines in one file or the results of another command. However, when used by default, it can only delete contiguous lines.

With the sort statement, you can use the -u option or in combination with uniq to remove all duplicate lines:

Use the -d option to display only duplicate lines:

Use the -u option to display only lines that do not match:

Use the -c option to count how many rows are duplicated:


diff is a handy command. Let’s say you have 2 files, which contain almost the same information, but you can’t find the difference between the two files. diff will compare the two files and find the differences:

Use the -y option to compare each line of 2 files:


echo allows you to print to the screen the arguments passed to the command.

To add text to a file use the following command:

To overwrite text into a file use the following command:

Variable into the result:

You can execute a command and then print the result of that statement:

Done. This is part 3 offline. I will back this series later. You welcome to read part 4 link here. Thank you for your interest.

Share the news now

Source : Viblo