![]() ![]() In most Linux distributions, you would use Ctrl + Alt + T to do so. ⬇️ Click to Tweet The 40 Most-Used Linux Commandsīefore jumping into the most-used Linux commands, make sure to fire up a terminal. You can invoke flags using hyphens ( -) and double hyphens ( -), while argument execution depends on the order in which you pass them to the function.ĭid you know that 90% of all cloud infrastructure and hosting services use Linux? □ For this reason alone, it is crucial to be familiar with popular Linux commands. In most cases, the argument is a file path, but it can be anything you type in the terminal. ![]() Most of the time, flags are optional.Īn argument or parameter is the input we give to a command so it can run properly. Most Linux commands have a help page that we can call with the flag -h. For example, when you close a window by clicking on the “X,” there’s a command running behind that action.Ī flag is a way we can pass options to the command you run. ![]() A command line is an interface that accepts lines of text and processes them into instructions for your computer.Īny graphical user interface (GUI) is just an abstraction of command-line programs. Do you know of any other best example of the uniq command in Linux? Let us know your views in the comments below.A Linux command is a program or utility that runs on the command line. In this guide, we learned the uniq command using practical examples. However, we can also combine other supported options with these commands. In this example, we used the sort and uniq commands without any options. Remove Non-adjacent Duplicate Lines in File In such cases, first, we can sort the file contents and then pipe that output to the uniq command as shown. However, sometimes we want to remove the duplicate entries regardless of their order in the given file. One of the trivial limitations of the uniq command is that it only removes adjacent duplicate entries. Here, we can see that the uniq command displays the lines that aren’t duplicated. Now, let’s use the -u option to print unique lines only: $ uniq -u linux-distributions.txt Similarly, we can also instruct the uniq command to print non-duplicate lines only. In previous examples, we saw how to print duplicate lines. In the above output, we can see that each repeated group is separated by a new line delimiter. Let’s use the -all-repeated=separate option to achieve the same: $ uniq -all-repeated=separate linux-distributions.txt However, we can make the same output more readable by separating each group by a new line. In the previous example, we printed all duplicate lines. Show Duplicate Lines By Groups in a New Line The above output doesn’t show the text UBUNTU, CENTOS, and Alpine as those are uniq lines. In a similar way, we can also show all the duplicates lines using the -D option: $ uniq -D linux-distributions.txt In the previous example, we saw how to display a duplicate line from each group. In the above output, we can see that the uniq command shows the duplicate entry from each group. Sometimes, we want just want to print the duplicate lines from a text file, in that case, you can use the -d option as shown. Along with this, the same happens with the string CentOS and CENTOS. In this example, we can observe that now, the string Ubuntu and UBUNTU is treated as same. Remove Duplicate Lines Ignore Case Insensitive However, we can disable this default behavior by using the -i option as shown. Remove Duplicates with Case Insensitiveīy default, the uniq command works in a case-sensitive way. In the above output, the first column represents the number of times the line is repeated. We can achieve this using the -c option as shown in the below example: $ uniq -c linux-distributions.txt However, sometimes we also want to know how many times the duplicate line appears. In the previous example, we saw how to remove duplicate lines. In the above output, we can see that the uniq command has successfully eliminated the duplicated lines. One of the common uses of the uniq command is to remove the adjacent duplicate lines from the text file as shown. Now, let’s use this file to understand the usage of the uniq command. To begin, first, let’s create a simple text file with a vi editor and add the following duplicate contents located in the adjacent lines. It is important to note that, all the options and parameters of the uniq command are optional. The syntax of the uniq command is very easy to understand and is similar to other Linux commands: $ uniq ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |