In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to install moreutils on Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
We all know about the GNU core utility GNU Core Utilities, which is preinstalled with all Unix-like operating systems. They are the basic utilities related to file, Shell, and text processing in the GNU operating system. The GNU core utility includes many daily operation commands, such as cat, ls, rm, mkdir, rmdir, touch, tail, and wc. In addition to these utilities, there are more useful utilities that are not pre-installed in the Unix-like operating system, and they come together to form a growing collection of moreutilis. Moreutils can be installed on GNU/Linux and a variety of Unix types of operating systems, including FreeBSD,openBSD and Mac OS.
As of the time of writing this guide, moreutils provides the following utilities:
Chronic-run the program and ignore the normally running output
Combine-Lines that merge files using Boolean operations
Errno-query errno name and description
Ifdata-get network interface information without parsing the results of ifconfig
Ifne-run the program when the standard input is not empty
Isutf8-check whether the file or standard input is encoded in UTF-8
Lckdo-run the program with lock
Mispipe-use pipes to connect two commands and return the exit status of * commands
Parallel-run multiple tasks simultaneously
Pee-pass standard input to multiple pipes
Sponge-integrate standard input and write to a file
Ts-adds timestamp information to standard input
Vidir-manipulate catalog files using your default text editor
Vipe-insert information editing into the pipe
Zrun-automatically decompress and pass it as an argument to the command
Install moreutils on Linux
Since moreutils has been packaged into a variety of Linux distributions, you can install moreutils using the package manager corresponding to the distribution.
On Arch Linux or derived Antergos and Manjaro Linux, run the following command to install moreutils:
$sudo pacman-S moreutils
On Fedora, run:
$sudo dnf install moreutils
On RHEL,CentOS and Scientific Linux, run:
$sudo yum install epel-release$ sudo yum install moreutils
On Debian,Ubuntu and Linux Mint, run:
$sudo apt-get install moreutilsMoreutils-package more useful Unix utilities
Let's take a look at the usage details of several moreutils tools.
Combine utility
As the name of combine suggests, this utility in moreutils can merge lines in two files using Boolean operations including and,not,or and xor.
And-outputs lines that are contained in both file1 and file2.
Not-outputs lines that the file1 contains but the file2 does not.
Or-outputs the lines contained in file1 or file2.
Xor-outputs lines that are only contained by file1 or file2
The following example makes it easy for you to understand the functions of the utility. Here are two files, named file1 and file2, with the following contents:
$cat file1iswaswerewherethere $cat file2iswerethere
Next, I use the and Boolean operation to merge the two files.
$combine file1 and file2iswerethere
As you can see from the output of the example above, the and Boolean operation outputs only those lines that both file1 and file2 contain; more specifically, the command output is the line shared by the two files, is,were and there.
Let's switch to not operation and take a look at the output.
$combine file1 not file2waswhere
As you can see from the output above, the not operation outputs lines that file1 contains but file2 does not.
Ifdata utility
The ifdata utility can be used to check whether a network interface exists or to obtain information about a network interface, such as an IP address. Unlike the pre-installed ifconfig and ip commands, the output of ifdata is easier to parse, which is designed to be easy to use in Shell scripts.
If you want to see the IP address of an interface, take wlp9s0 as an example, run the following command:
$ifdata-p wlp9s0192.168.43.192 255.255.255.0 192.168.43.255 1500
If you only view the mask information, run the following command:
$ifdata-pn wlp9s0255.255.255.0
If you look at the physical address of the network interface, run the following command:
$ifdata-ph wlp9s0A0:15:46:90:12:3E
If you determine whether the interface exists, you can use the-pe parameter:
$ifdata-pe wlp9s0yespee command
This command is somewhat similar to the tee command.
Let's first look at the use of tee with an example.
$echo "Welcome to OSTechNIx" | tee file1 file2Welcome to OSTechNIx
The above command first creates two files named file1 and file2;, then appends the "Welcome to OSTechNix" line to the two files, and * prints out "Welcome to OSTechNix" in the terminal.
The pee command provides similar functionality, but with a slight difference from tee. Check out the following example:
$echo "Welcome to OSTechNIx" | pee cat catWelcome to OSTechNIxWelcome to OSTechNIx
As you can see from the command output above, there are two cat command instances that take the output of the echo command and execute it, so two identical outputs appear in the terminal.
Sponge utility
This is another useful utility in the moreutils package. Sponge reads standard input and writes it to the specified file. Unlike redirection in Shell, sponge receives the full input and then writes to the output file.
Look at the contents of the following text file:
$cat file1IYouMeWeUs
As you can see, the file contains some unordered lines; more specifically, these lines are "not" sorted alphabetically. What would you do if you wanted to install alphabetical sorting of its contents?
$sort file1 > file1_sorted
That's the right thing to do, right? Of course it is! In the above command, I sort the contents of the file1 file in alphabetical order and save the sorted contents in the file1_sorted file. But if you use the sponge command, you can accomplish the same task without creating a new file (that is, file1_sorted), as follows:
$sort file1 | sponge file1
So, let's check to see if the contents of the file are sorted alphabetically:
$cat file1IMeUsWeYou
Did you see that? There is no need to create a new file. This is very useful in scripting. The other good news is that if the file to be written already exists, sponge will leave its permission information permissions unchanged.
Ts utility
As the name suggests, the ts command adds a timestamp timestamp to the beginning of each line output.
View the output of the following command:
$ping-c 2 localhostPING localhost (localhost.localdomain (:: 1)) 56 data bytes64 bytes from localhost.localdomain (:: 1): icmp_seq=1 ttl=64 time=0.055 ms64 bytes from localhost.localdomain (:: 1): icmp_seq=2 ttl=64 time=0.079 ms-localhost ping statistics-2 packets transmitted, 2 received, 0% packet loss, time 1018msrtt min/avg/max/mdev = 0.055, 0.067, 0.079, 0.012 ms
Next, run the same command in conjunction with the ts utility:
$ping-c 2 localhost | tsAug 21 13:32:28 PING localhost (localhost (:: 1)) 56 data bytesAug 21 13:32:28 64 bytes from localhost (:: 1): icmp_seq=1 ttl=64 time=0.063 msAug 21 13:32:28 64 bytes from localhost (:: 1): icmp_seq=2 ttl=64 time=0.113 msAug 21 13:32:28Aug 21 13:32:28-localhost ping statistics-Aug 21 13:32:28 2 packets transmitted, 2 received, 0 packet loss Time 4msAug 21 13:32:28 rtt min/avg/max/mdev = 0.063 ms 0.088 Universe 0.113 Universe
As you can see from the output, ts adds a timestamp at the beginning of each line. Here is another example:
$ls-l | tsAug 21 13:34:25 total 120Aug 21 13:34:25 drwxr-xr-x 2 sk users 12288 Aug 20 20:05 DesktopAug 21 13:34:25 drwxr-xr-x 2 sk users 4096 Aug 10 18:44 DocumentsAug 21 13:34:25 drwxr-xr-x 24 sk users 12288 Aug 21 13:06 Downloads [...] vidir utility
The vidir utility allows you to edit the contents of a specified directory using the vi editor (or other editor specified by the $EDITOR environment variable). If no directory is specified, vidir will edit your current directory by default.
The following command edits the contents of the Desktop directory:
$vidir Desktop/
Vidir
The above command uses the vi editor to open the specified directory, where the files in the directory correspond to a number. Below you can edit these files in the directory as vi does: for example, deleting a line means deleting the corresponding file in the directory, and changing the string in the line means renaming the file.
You can also edit subdirectories. The following command edits the current directory and all subdirectories:
$find | vidir-
Please note the-at the end of the command. If-is specified as the directory to be edited, vidir will read a series of file names from standard input and list them for you to edit.
If you only want to edit the files in the current directory, you can use the following command:
$find-type f | vidir-
Only want to edit specific types of files, such as .PNG files? You can use the following command:
$vidir * .png
At this point, the command will only edit files in the current directory with the suffix .PNG.
Vipe utility
The vipe command allows you to use the default editor to receive Unix pipe input, and then use the pipe output for the next program after editing.
Executing the following command opens the vi editor (the editor I use by default, of course). You can edit the pipe input of the echo command (that is, "Welcome to OSTechNix") and * output the edited content to the terminal.
$echo "Welcome to OSTechNIx" | vipeHello World
As you can see from the output above, I piped "Welcome to OSTechNix" into the vi editor, edited the content as "Hello World", and * displayed it.
All right, that's all for introduction. I've only introduced a few utilities, while moreutils contains more useful utilities. I listed the utilities included in the current moreutils package at the beginning of the article, and you can get more details about the commands on the man help page. For example, if you want to learn about the vidir command, run:
$man vidir Thank you for your reading! This is the end of the article on "how to install moreutils on Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.