Linux 终端中值得尝试的 24 条最有趣的命令
Linux具有丰富的命令集合,其中许多命令功能强大且可用于执行各种任务,但也有一些有趣而异想天开的命令可供您尝试以获得乐趣。
1. sl指挥部(蒸汽机车)
您可能知道命令ls 命令,它经常用于查看目录的内容,但是由于输入错误,有时会导致输入“ sl ”。
sl命令用于模拟一列火车在你的终端上行驶,当你不小心输入“ sl ”而不是“ ls ”(常见的输入错误)时。
安装 sl 命令
$ sudo apt install sl [On Debian, Ubuntu and Mint] $ sudo yum install sl [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/sl [On Gentoo Linux] $ sudo apk add sl [On Alpine Linux] $ sudo pacman -S sl [On Arch Linux] $ sudo zypper install sl [On OpenSUSE]
安装后,您可以尝试通过简单输入来运行sl命令。
$ sl
2. telehack 命令
telehack是一个提供类似于命令行环境的基于文本的界面的网站,您可以在其中与各种命令进行交互,探索模拟系统,玩基于文本的游戏,阅读文章,甚至参与模拟故事情节。
转到 telehack 网站并输入以下命令。
$ starwars
3. fortune 命令
fortune命令是一个有趣的命令,用于显示随机引用、妙语或财富信息。
安装 fortune 命令
$ sudo apt install fortune [On Debian, Ubuntu and Mint] $ sudo yum install fortune [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/fortune [On Gentoo Linux] $ sudo apk add fortune [On Alpine Linux] $ sudo pacman -S fortune [On Arch Linux] $ sudo zypper install fortune [On OpenSUSE]
安装后,您可以通过简单输入来尝试运行fortune命令。
$ fortune
4. rev 命令
rev命令用于反转给定输入中每行字符的顺序。它从标准输入或文件读取输入并输出反转后的行。
要反转文件中的字符,请使用以下命令。
$ rev example.txt
5. factor 命令
factor命令用于将给定的整数分解为其素因数。它计算指定数字的素因数并将其显示在标准输出上。
$ factor 5
6. Bash 中的嵌套循环
这不是一个命令,而是Bash 中的嵌套循环,用于打印从 1 到 12 的乘法表。它使用两个变量 i 和 j 来遍历数字并计算它们的乘积。
$ for i in {1..12}; do for j in $(seq 1 $i); do echo -ne $i×$j=$((i*j))\\t;done; echo;done
以下是该命令的解释:
for i in {1..12}; do # Outer loop iterating from 1 to 12 for j in $(seq 1 $i); do # Inner loop iterating from 1 to the current outer loop value echo -ne "$i×$j=$((i*j))\t"; # Print the multiplication expression and result done echo; # Move to the next line after each inner loop done
当您在终端中运行此命令时,它将生成以下输出。
7. cowsay 命令
cowsay命令用于生成一头牛或其他动物的 ASCII 艺术表示,并带有包含可自定义消息的语音或思维泡泡。
安装cowsay 命令
$ sudo apt install cowsay [On Debian, Ubuntu and Mint] $ sudo yum install cowsay [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/cowsay [On Gentoo Linux] $ sudo apk add cowsay [On Alpine Linux] $ sudo pacman -S cowsay [On Arch Linux] $ sudo zypper install cowsay [On OpenSUSE]
安装后,您可以尝试通过简单输入来运行cowsay命令。
$ cowsay I Love Example.com $ cowsay I Love Linux
将fortune与cowsay命令结合起来,显示随机的财富消息,使用管道符(|)将一个命令的输出作为另一个命令的输入。
在下面的例子中,“ fortune ”命令的输出作为“ cowsay ”命令的输入。
$ fortune | cowsay
xcowsay是一个图形程序,其响应方式与cowsay类似,但是采用图形方式,在桌面上生成带有可自定义消息的动画对话框,通常以一头牛或其他人物为特色。
安装 xcowsay 命令
$ sudo apt install xcowsay [On Debian, Ubuntu and Mint] $ sudo yum install xcowsay [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/xcowsay [On Gentoo Linux] $ sudo apk add xcowsay [On Alpine Linux] $ sudo pacman -S xcowsay [On Arch Linux] $ sudo zypper install xcowsay [On OpenSUSE]
安装xcowsay后,您可以通过运行以下命令启动它:
$ xcowsay I Love Example.com
8. yes 命令
yes命令重复打印指定字符串或文本的连续流直到终止,通常用于需要自动或重复输入特定值的脚本或命令行操作。
$ yes I Love Example.com
9. toilet 命令
toilet命令使用终端中的各种字体生成具有视觉吸引力的 ASCII 艺术文本横幅或大字母。
安装厕所命令
$ sudo apt install toilet [On Debian, Ubuntu and Mint] $ sudo yum install toilet [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/toilet [On Gentoo Linux] $ sudo apk add toilet [On Alpine Linux] $ sudo pacman -S toilet [On Arch Linux] $ sudo zypper install toilet [On OpenSUSE]
安装好马桶后,您就可以运行命令并输入要转换为 ASCII 横幅的文本。
$ toilet Example.com
如果要以大字体打印横幅,可以运行:
$ toilet -f big Example.com
10. cmatrix 命令
您可能看过好莱坞电影“黑客帝国”,并且会对Neo所拥有的力量感到着迷,他可以看到黑客帝国中的任何东西,或者您可能会想到一个看起来像黑客帝国 桌面的动画。
然后您应该使用cmatrix命令,它会在您的终端上显示一个动画矩阵般的文本字符雨,类似于“黑客帝国”电影。
安装 cmatrix 命令
$ sudo apt install cmatrix [On Debian, Ubuntu and Mint] $ sudo yum install cmatrix [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/cmatrix [On Gentoo Linux] $ sudo apk add cmatrix [On Alpine Linux] $ sudo pacman -S cmatrix [On Arch Linux] $ sudo zypper install cmatrix [On OpenSUSE]
一旦安装了cmatrix,您就可以运行命令,显示满是级联的绿色字符,类似于“黑客帝国”电影中的下落代码。
$ cmatrix
11. oneko 命令
好的,所以您认为 Linux 的鼠标指针是相同的、没有动画的黑色/白色指针,那么我担心您可能错了。
“ oneko ” 是一个会将“ Jerry ”附加到鼠标指针上并跟随指针移动的包。
安装 oneko 命令
$ sudo apt install oneko [On Debian, Ubuntu and Mint] $ sudo yum install oneko [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/oneko [On Gentoo Linux] $ sudo apk add oneko [On Alpine Linux] $ sudo pacman -S oneko [On Arch Linux] $ sudo zypper install oneko [On OpenSUSE]
一旦安装了oneko,您运行命令即可在屏幕上看到一只小动画猫。
$ oneko
Once you close the terminal from which oneko was run, Jerry will disappear, nor will start at start-up. You can add the application to start up and continue enjoying.
12. Fork Bomb
A fork bomb is a type of malicious code or command that can cause a denial-of-service (DoS) condition by rapidly and exponentially creating child processes, which exploits the “fork” system call in the operating system.
It can also cause severe disruption, loss of data, or damage to the system, which might make you unresponsive, and you might need to reboot the machine to regain control.
To check the power of the fork command you should try it once, but all at your own risk, close and save all other programs and files before running a fork bomb.
$ :(){ :|: & };:
Let’s break down how this fork bomb works:
:(){ ... }
– This defines a function named":"
(colon) without any arguments.:|:
– This calls the function recursively by piping its output to another instance of the function.&
– This puts the command in the background, allowing it to run concurrently.;:
– This executes the function again after the initial invocation, causing it to continue indefinitely.
13. while Command
The following while command is a bash script that provides you with a colored date and time in a stylized ASCII art format using the toilet. It uses a while loop to repeatedly execute the commands and includes a 1-second delay between each iteration.
$ while true; do echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done
Here’s an explanation of the command:
while true; do # Start an infinite loop echo "$(date '+%D %T' | toilet -f term -F border --gay)"; # Print the formatted date and time using toilet sleep 1; # Delay for 1 second done
The above script when modified with the following command, will give similar output but with a little difference, check it in your terminal.
$ while true; do clear; echo "$(date '+%D %T' | toilet -f term -F border --gay)"; sleep 1; done
14. espeak Command
The espeak is a text-to-speech (TTS) synthesis command that converts text input into spoken words in various languages and voices.
Install espeak Command
$ sudo apt install espeak [On Debian, Ubuntu and Mint] $ sudo yum install espeak [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/espeak [On Gentoo Linux] $ sudo apk add espeak [On Alpine Linux] $ sudo pacman -S espeak [On Arch Linux] $ sudo zypper install espeak [On OpenSUSE]
Once espeak is installed, you run the command with the text you want to be spoken.
$ espeak "I Love Example.com"
15. aafire Command
The aafire is a fun command that displays visually appealing ASCII art animation of a fire effect in the terminal using ASCII characters.
Install aafire Command
$ sudo apt install libaa-bin [On Debian, Ubuntu and Mint] $ sudo yum install aalib [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/aalib [On Gentoo Linux] $ sudo apk add aalib [On Alpine Linux] $ sudo pacman -S aalib [On Arch Linux] $ sudo zypper install aalib [On OpenSUSE]
Once aafire is installed, you run the command to see a fire animation in your terminal.
$ aafire
16. bb Command
The bb is a simple command-line ASCII art demo that displays an animated ASCII art representation of a bouncing ball on the terminal screen.
Install bb Command
$ sudo apt install bb [On Debian, Ubuntu and Mint] $ sudo yum install bb [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/bb [On Gentoo Linux] $ sudo apk add bb [On Alpine Linux] $ sudo pacman -S bb [On Arch Linux] $ sudo zypper install bb [On OpenSUSE]
Once bb is installed, you run the command to see a visual effect of a ball bouncing around the terminal screen.
$ bb
17. curl Command
Won’t it be an awesome feeling for you if you can update your Twitter status from the command line in front of your friend and they seem impressed?.
To post a status to Twitter using the curl command, you need to use the Twitter API’s POST endpoint for creating a tweet as shown.
$ curl -X POST -u "YourBearerToken:" -d "status=Your%20status%20message" "https://api.twitter.com/1.1/statuses/update.json"
18. ASCIIquarium
ASCIIquarium is an entertaining perl script that displays an animated aquarium in ASCII art format directly in your Linux terminal. It creates a simulation of underwater life with fish, plants, and other elements.
On Ubuntu or Debian-based systems, you can install ASCIIquarium with the following commands.
First, you need to install the Term::Animation module as shown.
$ sudo apt install libcurses-perl $ sudo apt install libcurses-perl $ wget https://cpan.metacpan.org/authors/id/K/KB/KBAUCOM/Term-Animation-2.5.tar.gz $ tar xzf Term-Animation-2.5.tar.gz $ cd Term-Animation-2.5/ $ perl Makefile.PL $ make $ sudo make install
Next, install ASCIIquarium with the following commands.
$ cd /tmp $ wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz $ tar -zxvf asciiquarium.tar.gz $ cd asciiquarium_1.1/ $ sudo cp asciiquarium /usr/local/bin $ sudo chmod 0755 /usr/local/bin/asciiquarium
Finally, run “asciiquarium” or “/usr/local/bin/asciiquarium” in the terminal without quotes and be a part of the magic that will be taking place in front of your eyes.
$ asciiquarium
19. Funny Linux Man Pages
Funny man pages, also known as “man pages with attitude,” are entertaining versions of the traditional Linux man pages, as they don’t offer abt serious or practical information, they are meant to bring a smile to your face.
Install Funny Man Pages
$ sudo apt install funny-manpages [On Debian, Ubuntu and Mint] $ sudo yum install funny-manpages [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/funny-manpages [On Gentoo Linux] $ sudo apk add funny-manpages [On Alpine Linux] $ sudo pacman -S funny-manpages [On Arch Linux] $ sudo zypper install funny-manpages [On OpenSUSE]
Once funny-manpages is installed, you can have access to the funny-man pages of the command you want to view.
$ man baby $ man celibacy $ man condom $ man date $ man echo $ man flame $ man flog $ man gong
20. pv Command
You might have seen the simulating text in movies, which appears as if it is being typed in real-time. Won’t it be nice, if you can have such an effect in your terminal?
This can be achieved, by installing the pv command (pipe viewer), which is used to monitor the progress of data through a pipeline.
Install pv Command
$ sudo apt install pv [On Debian, Ubuntu and Mint] $ sudo yum install pv [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/pv [On Gentoo Linux] $ sudo apk add pv [On Alpine Linux] $ sudo pacman -S pv [On Arch Linux] $ sudo zypper install pv [On OpenSUSE]
Once, the pv command is installed successfully on your system, let’s try to run the following one-liner command to see the real-time text effect on the screen.
$ echo "Example[dot]com is a community of Linux Nerds and Geeks" | pv -qL 10
The q
option means ‘quiet‘, no output information, and option L
means the limit of transfer of bytes per second. The number value can be adjusted in either direction (must be an integer) to get the desired simulation of text.
21. rig Command
The rig short for “Random Identity Generator” is a command that is used to generate random fake identities for testing, simulation, or other purposes.
Install rig Command
$ sudo apt install rig [On Debian, Ubuntu and Mint] $ sudo yum install rig [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/rig [On Gentoo Linux] $ sudo apk add rig [On Alpine Linux] $ sudo pacman -S rig [On Arch Linux] $ sudo zypper install rig [On OpenSUSE]
Once installed, you can use the rig command to generate random identities.
$ rig
22. aview Command
aview命令将图像转换为 ASCII 艺术并在终端中显示。要使用aview命令,您需要在系统上安装它。
$ sudo apt install aview [On Debian, Ubuntu and Mint] $ sudo yum install aview [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/aview [On Gentoo Linux] $ sudo apk add aview [On Alpine Linux] $ sudo pacman -S aview [On Arch Linux] $ sudo zypper install aview [On OpenSUSE]
我当前工作目录中有一个名为“ actress.jpg ”(猜猜女演员)的图像,我想以 ASCII 格式在终端上查看它。
$ aview actress.jpg
23. xeyes 命令
之前,我们介绍了一个命令“ oneko ”,它将鼠标指针附加到 Jerry 身上并不断追逐它。类似的程序“ xeyes ”是一个图形程序,只要您触发该命令,您就会看到两只怪物的眼睛追逐您的动作。
$ sudo apt install x11-apps [On Debian, Ubuntu and Mint] $ sudo yum install xeyes [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] $ sudo emerge -a sys-apps/xeyes [On Gentoo Linux] $ sudo apk add xeyes [On Alpine Linux] $ sudo pacman -S xeyes [On Arch Linux] $ sudo zypper install xeyes [On OpenSUSE]
安装后,运行:
$ xeyes
24. Linux 调整
现在是时候对 Linux 进行一些单行调整,以便在终端中获得一些乐趣了。
$ world bash: world: not found
$ touch girls\ boo** touch: cannot touch `girls boo**': Permission denied
$ nice man woman No manual entry for woman
$ ^How did the sex change operation go?^ bash: :s^How did the sex change operation go?^ : substitution failed
$ %blow bash: fg: %blow: no such job
$ make love make: *** No rule to make target `love'. Stop.
$ [ whereis my brain? sh: 2: [: missing ]
$ % man: why did you get a divorce? man:: Too many arguments.
$ % !:say, what is saccharine? Bad substitute.
$ \(- bash: (-: command not found
Linux 很顽皮——如果你明白我的意思的话...:)
$ who | grep -i blonde | date; cd ~; unzip; touch; strip; finger; mount; gasp; yes; uptime; umount; sleep
还有一些其他的,但它们并不适用于所有系统,因此本文不包含它们。它们包括 man dog、filter、banner等。
玩得开心,稍后你可以对我说谢谢,是的,非常感谢你的评论,这鼓励我们写更多。告诉我们你最喜欢哪个命令。请继续关注,我很快就会带着另一篇值得一读的文章回来。