Table of Contents
1、fold" >1、fold
2、column" >2、column
3、sg" >3、sg
4、xxd" >4、xxd
5、pwdx" >5、pwdx
6、write" >6、write
Home System Tutorial LINUX Interesting treasure! 6 Unique and Amazing Linux Utilities for You

Interesting treasure! 6 Unique and Amazing Linux Utilities for You

Feb 13, 2024 pm 09:42 PM

In this article, we'll dig deeper into the hidden corners of /usr/bin and uncover some more interesting treasures. We'll explore some unique and interesting programs that may seem outdated at first glance, but are actually 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.

1、fold

First of all, we have a very useful little tool that can help you wrap input lines to a specific 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 using the following command:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ echo "12345678" | fold -w 7
Copy after login

The corresponding output should be:

1234567
8
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

Now we can quickly fit some text into our length limit. This is useful for breaking up long text streams or for enforcing line length limits on code or other configuration files.

For more details on using fold, check out the wiki page.

2、column

This is another very useful formatting tool. The column tool can help you create columns in text output or even generate entire tables, all from the command line.

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
Copy after login

The output of the command should look like this:

one    two     three
1      2       3
93139  777777  999999
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

As you can see, the output is automatically formatted into neatly aligned columns. This forms a small table in the output, which automatically resizes based on 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.

3、sg

You may have heard of the newgrp command. This command executes commands as a different group, but there is a simpler utility that achieves the same functionality. The sg utility allows you to directly execute commands with the permissions of another group you specify. You don't need to use pipes or change existing shell groups, just specify a group and a command.

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
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

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.

4、xxd

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. It has the added advantage that you can use this utility to do hex dumps and restores. 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
Copy after login

我们只需提供输入,xxd 将自动将文件编码到 stdout(对于较短的输入文件,这是一个很方便的默认功能):

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ xxd linuxmi
00000000: 6c69 6e75 786d 690a
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

您还可以通过传递一个额外的文件名参数来直接将输出发送到转储文件:

xxd linuxmi 93139
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

这将将十六进制转储发送到名为 93139 的文件中。

xxd 的 man 页面可以在此处找到。

5、pwdx

这个方便的小实用程序来自于我们都熟悉和喜爱的古老 ps 实用程序家族。pwdx 实用程序可以让您获取运行中进程的当前工作目录。您只需要将进程的 PID 传递给它,它就会告诉您该进程的工作目录在哪里。

假设我们想找出 cron 进程在我们的机器上的工作目录。首先,我们只需要使用 ps 搜索并找到它的 PID,像这样:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ ps aux | grep cron
Copy after login
有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

在这里,我们可以看到cron的PID是612。现在,我们只需要将该进程的PID传递给pwdx来确定其工作目录,像这样:

┌──(linuxmi㉿linuxmi)-[~/www.linuxmi.com]
└─$ sudo pwdx 691
Copy after login

如下图:

有趣的宝藏!6 个你独特而惊人的 Linux 实用工具

由于cron是系统进程,您需要使用sudo才能获取有关它的信息。命令完成后,我们得到了cron的当前工作目录,即 /var/spool/cron。
这可以是一个非常有价值的故障排除工具,特别是当您追踪目录范围问题时。通过使用 pwdx 进行快速检查,您可以准确地确定一个进程认为它应该从哪个位置运行。

在这里查看 pwdx 的 man 页面。

6、write

这个强大的小程序可能不会像您一开始想的那样执行某个特定任务。它在 Linux 中已经存在了几十年,甚至可以追溯到 1975 年 Unix 的第 6版。

write 实用程序实际上允许您向同一系统上的其他用户发送消息。您可以针对任何其他登录的用户发送消息。提供用户名,您将进入一个交互式shell,以向他们写任何您想要的文本。您键入的所有内容(包括换行符)都将出现在目标用户的控制台上。

这里是一个快速示例:

write 
Copy after login

这将使您进入一个交互式控制台,以向相应的用户发送消息。请记住,这是一种相当侵入性的与其他用户通信的方式。这将使他们的终端显示您输入的文本,而无需任何警告或提示。对他们来说,这将出现在他们的终端上,就像自动出现的信息一样。由于这是单向通信,他们也无法回复。

尽管现在有更好的方法来处理用户之间的消息传递,但这是计算历史的一部分。我相信今天仍然可以有一些创造性的用途。

The above is the detailed content of Interesting treasure! 6 Unique and Amazing Linux Utilities for You. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How To Easily Configure Flatpak Apps Permissions With Flatseal How To Easily Configure Flatpak Apps Permissions With Flatseal Mar 22, 2025 am 09:21 AM

Flatpak application permission management tool: Flatseal User Guide Flatpak is a tool designed to simplify Linux software distribution and use. It safely encapsulates applications in a virtual sandbox, allowing users to run applications without root permissions without affecting system security. Because Flatpak applications are located in this sandbox environment, they must request permissions to access other parts of the operating system, hardware devices (such as Bluetooth, network, etc.) and sockets (such as pulseaudio, ssh-auth, cups, etc.). This guide will guide you on how to easily configure Flatpak with Flatseal on Linux

How To List Or Check All Installed Linux Kernels From Commandline How To List Or Check All Installed Linux Kernels From Commandline Mar 23, 2025 am 10:43 AM

Linux Kernel is the core component of a GNU/Linux operating system. Developed by Linus Torvalds in 1991, it is a free, open-source, monolithic, modular, and multitasking Unix-like kernel. In Linux, it is possible to install multiple kernels on a sing

Yt-dlp Commands: The Complete Tutorial For Beginners (2025) Yt-dlp Commands: The Complete Tutorial For Beginners (2025) Mar 21, 2025 am 11:00 AM

Have you ever wanted to save your favorite videos from the internet? Whether it's a funny cat video or a tutorial you want to watch later, Yt-dlp is here to help! In this comprehensive yt-dlp tutorial, we will explain what yt-dlp is, how to install i

How To Type Indian Rupee Symbol In Ubuntu Linux How To Type Indian Rupee Symbol In Ubuntu Linux Mar 22, 2025 am 10:39 AM

This brief guide explains how to type Indian Rupee symbol in Linux operating systems. The other day, I wanted to type "Indian Rupee Symbol (₹)" in a word document. My keyboard has a rupee symbol on it, but I don't know how to type it. After

What is the Linux best used for? What is the Linux best used for? Apr 03, 2025 am 12:11 AM

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

Linux Kernel 6.14 RC6 Released Linux Kernel 6.14 RC6 Released Mar 24, 2025 am 10:21 AM

Linus Torvalds has released Linux Kernel 6.14 Release Candidate 6 (RC6), reporting no significant issues and keeping the release on track. The most notable change in this update addresses an AMD microcode signing issue, while the rest of the updates

How To Enable Bucklespring Keyboard Sound In Linux How To Enable Bucklespring Keyboard Sound In Linux Mar 22, 2025 am 09:07 AM

Experience the satisfying click of a vintage IBM Model M keyboard, even without owning one! This tutorial shows you how to enable the authentic sound of a bucklespring keyboard on your Linux system using the Bucklespring utility. Table of Contents -

LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing LocalSend - The Open-Source Airdrop Alternative For Secure File Sharing Mar 24, 2025 am 09:20 AM

If you're familiar with AirDrop, you know it's a popular feature developed by Apple Inc. that enables seamless file transfer between supported Macintosh computers and iOS devices using Wi-Fi and Bluetooth. However, if you're using Linux and missing o

See all articles