We will explore /usr/bin in depth and uncover some more interesting treasures. Although they may seem a little dated, we'll explore some unique and interesting programs that are still very useful today.
Let's get back on the road of adventure and continue to discover more wonderful things that Linux has to offer us.
We have a very practical little tool that can help you wrap input lines according to the specified length. You can define the length by specifying the number of bytes or spaces. Using the fold tool, you can quickly process files with different lengths.
For example, assume we have a line of input that is six characters long. We want to limit each line to only five characters and wrap the remainder. Using fold, we can achieve this with the following command:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ echo "12345678" | fold -w 7
The corresponding output should be:
12345678
Now we can quickly fit some text to our length limit. This is useful when breaking up long text streams or when imposing line length limits on code or other configuration files.
For more details on using fold, check out the wiki page.
This is another very useful formatting tool. You can use the column tool through the command line to create columns or even generate entire tables to facilitate text output.
Although the same functionality can be achieved using tools such as awk, the column tool is designed for this specific purpose, so it is very simple to use and its syntax is easy to remember.
If we want to build a simple table based on a few lines of input, we can execute the following command:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ echo -e "one two three\n1 2 3\n93139 777777 999999" | column -t
The output of the command should look like this:
onetwo three12 393139777777999999
As you can see, the output is automatically formatted into neatly aligned columns. A small table is formed in the output, automatically resizing according to the length of each line of input.
This tool will be a big help if you are working with a slightly longer unstructured data set on the command line and want to quickly create some tabular forms.
column's man page provides more usage details and unique ways of handling different inputs.
You may have heard of the newgrp command. There is a simpler tool that achieves the same effect without requiring you to execute commands as a different group. The sg utility allows you to directly execute commands with the permissions of another group you specify. Just specify a group and a command without having to use pipes or change existing shell groups.
To execute the ls command with the permissions of the sudo group, you can enter the following command:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ sg sudo ls
This will switch the ls command to run with the permissions of the sudo group. Once the command has finished executing, you will be returned to the normal group permissions you had before execution. The
sg command is very helpful for testing new group permissions or quickly switching context to run a program from another group.
For detailed usage information, please refer to sg's man page.
The xxd utility is one of many ways to perform a hex dump on Linux. There are many utilities with similar functionality, but the xxd program is slightly different. You can use this utility to perform hex dumps and restores, which has the added advantage of doing so. There are many configurable flags and you can also perform patching operations on binaries.
Suppose we want to take a hex dump of the following file named linuxmi:
linuxmi
We just provide the input and xxd will automatically encode the file to stdout (for shorter input file, this is a convenient default function):
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ xxd linuxmi00000000: 6c69 6e75 786d 690a
You can also send the output directly to a dump file by passing an additional filename argument:
xxd linuxmi 93139
This will send a hex dump to a file named 93139.
xxd's man page can be found here.
这个实用的小程序源于广为人知、备受喜爱的古老 PS 实用程序家族。pwdx 实用程序可以让您获取运行中进程的当前工作目录。只要您提供进程的 PID,它就能告诉您该进程的工作目录所在位置。
假设我们想找出 cron 进程在我们的机器上的工作目录。我们可以通过使用 ps 命令搜索并获取其 PID,示例如下:
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ ps aux | grep cron
在这里,我们可以看到cron的PID是612。这时,我们只需将该进程的PID传递给pwdx,就能确定它的工作目录
┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]└─$ sudo pwdx 691
如下图:
To access information about cron, you need to use sudo as it is a system process.。我们成功获取了cron的当前工作目录,即 /var/spool/cron,在命令执行完成后。当您需要跟踪目录范围问题时,这将是一个非常有价值的故障排除工具。您可以使用 pwdx 快速检查确定一个进程认为其应从哪个位置运行,以达到准确的目的。
在这里查看 pwdx 的 man 页面。
这个强大的小程序可能不会像您一开始想的那样执行某个特定任务。这个存在于Linux中已经有几十年了,可以追溯到1975年Unix的第6版。
The write utility actually allows you to send messages to other users on the same system.。您可以针对任何其他登录的用户发送消息。输入您的用户名,然后您可以进入一个交互式shell,用来书写任何您想要的文本。您键入的所有内容(包括换行符)都将出现在目标用户的控制台上。
这里是一个快速示例:
write <用户名>
这将使您进入一个交互式控制台,以向相应的用户发送消息。请记住,这是一种相当侵入性的与其他用户通信的方式。这将使他们的终端显示您输入的文本,而无需任何警告或提示。对他们来说,这将出现在他们的终端上,就像自动出现的信息一样。由于这是单向通信,他们也无法回复。
虽然目前有更优秀的处理用户间消息传递的方法,但这仍然是计算历史的一部分。我相信今天仍然可以有一些创造性的用途。
在这里查看官方的 man 页面。
The above is the detailed content of Interesting treasure! Six Unique and Amazing Linux Utilities. For more information, please follow other related articles on the PHP Chinese website!