The uniq command is a very powerful command, used with the sort command, especially for log file analysis. It allows you to sort and display entries by removing duplicates.
To illustrate how the uniq command works, let us use a firstnames.txt file containing a list of first names:
antoine
xavier
steven
patrick
xavier
antoine
antoine
steven
Note
uniq requires the input file to be sorted before running because it only compares consecutive lines.
With no argument, the uniq command will not display identical lines that follow each other in the firstnames.txt file:
$sortfirstnames.txt|uniq
antoine
patrick
steven
xavier
To display only the rows that appear only once, use the -u option:
$sortfirstnames.txt|uniq-u
patrick
Conversely, to display only the lines that appear at least twice in the file, use the -d option:
$sortfirstnames.txt|uniq-d
antoine
steven
xavier
To simply delete lines that appear only once, use the -D option:
$sortfirstnames.txt|uniq-D
antoine
antoine
antoine
steven
steven
xavier
xavier
Finally, to count the number of occurrences of each line, use the -c option:
The xargs command allows the construction and execution of command lines from standard input.
The xargs command reads whitespace or linefeed delimited arguments from standard input, and executes the command (/bin/echo by default) one or more times using the initial arguments followed by the arguments read from standard input.
A first and simplest example would be the following:
$xargs
use
of
xargs
<CTRL+D>
useofxargs
The xargs command waits for an input from the standard stdin input. Three lines are entered. The end of the user input is specified to xargs by the keystroke sequence Ctrl+D. xargs then executes the default command echo followed by the three arguments corresponding to the user input, namely:
$echo"use""of""xargs"
useofxargs
It is possible to specify a command to be run by xargs.
In the following example, xargs will run the command ls -ld on the set of folders specified in the standard input:
In this case, the xargs command must be forced to execute the find command several times (once per line entered as standard input). The -L option followed by an integer allows you to specify the maximum number of entries to be processed with the command at one time:
The special feature of the xargs command is that it places the input argument at the end of the called command. This works very well with the above example since the files passed in will form the list of files to be added to the archive.
Using the example of the cp command, to copy a list of files in a directory, this list of files will be added at the end of the command... but what the cp command expects at the end of the command is the destination. To do this, use the -I option to put the input arguments somewhere else than at the end of the line.
The yum-utils package is a collection of utilities, built for yum by various authors, which make it easier and more powerful to use.
Note
While yum has been replaced by dnf in Rocky Linux 8, the package name has remained yum-utils, although it can be installed as dnf-utils as well. These are classic YUM utilities implemented as CLI shims on top of DNF to maintain backwards compatibility with yum-3.
The repoquery command is used to query the packages in the repository.
Examples of use:
Display the dependencies of a package (it can be a software package that has been installed or not installed), equivalent to dnf deplist <package-name>
repoquery--requires<package-name>
Display the files provided by an installed package (does not work for packages that are not installed), equivalent to rpm -ql <package-name>
Contrary to what its name might suggest, the install command is not used to install new packages.
This command combines file copying (cp) and directory creation (mkdir), with rights management (chmod, chown) and other useful functionalities (like backups).
Size - Displays the file size in bytes. If this is a directory, it displays the fixed 4096 bytes occupied by the directory name.
Blocks - Displays the number of allocated blocks. Attention, please! The size of each block in this command is 512 bytes. The default size of each block in ls -ls is 1024 bytes.
Device - Device number in decimal or hexadecimal notation.
Inode - Inode is a unique ID number the Linux kernel assigns to a file or directory.
Links - Number of hard links. Hard links are sometimes referred to as physical links.
Access - The last access time of files and directories, i.e. atime in GNU/Linux.
Modify - The last modification time of files and directories, i.e. mtime in GNU/Linux.
Change - The last time the property is changed, i.e. ctime in GNU/Linux.
Birth - Birth time (Creation time). In some documents, it is abbreviated as btime or crtime. You need a file system and kernel version higher than a certain version to display the creation time.
For files:
atime - After accessing the file content using commands such as cat, less, more, and head, the atime of the file can be updated. Please pay attention! The atime of the file is not updated in real-time, and for performance reasons, it needs to wait for a period of time before it can be displayed.
mtime - Modifying the file content can update the mtime of the file (such as appending or overwriting the file content through redirection), because the file size is a property of the file, the ctime will also be updated simultaneously.
ctime - Changing the owner, group, permissions, file size, and links (soft and hard links) of the file will update ctime.
For directories:
atime - After using the cd command to enter a new directory that has never been accessed before, you can update and fix the atime of that directory.
mtime - Performing operations such as creating, deleting, and renaming files in this directory will update the mtime and ctime of the directory.
ctime - When the permissions, owner, group, etc. of a directory change, the ctime of the directory will be updated.
Tip
If you create a new file or directory, its atime, mtime, and ctime are exactly the same
If the file content is modified, the mtime and ctime of the file will inevitably be updated.
If a brand new file is created in the directory, the atime, ctime, and mtime of that directory will be updated simultaneously.
If the mtime of a directory is updated, then the ctime of that directory must be updated.