最近使用过的 4 5 条命令
我使用的是Fedora 30操作系统,安装的是KF5桌面。日常的生活和软件开发工作中,使用图形界面就足够了。
遇到特殊情况,例如需要对系统进行精细调整,或是需要修复某个故障时,使用命令行工具往往更高效。因为在使用命令行工具时,能够通过命令行参数解锁所有的可选项,其控制能力往往比图形界面工具更强大。
当你使用命令行工具时,相当于临时地对操作系统进行编程。铁甲钢拳里的松本鹰,在高潮部分的最后一个回合,宙斯倒下时,快速地敲着键盘,才让倒下的宙斯重新站起来。这是因为,松本鹰在开发时过于自信,认为宙斯不会倒下,使得宙斯的已有软件里,没有对“倒下之后重新站起”这种情况的处理。结果在实战中宙斯真的倒下去之后,既不会自动站起来,也无法通过界面上一个按钮点击一下让它重新站起来。当时松本鹰可能是在快速地写着脚本来控制宙斯,也可能就是在快速地执行着一连串的命令行命令,精细控制各个零件,让它用活塞拳做俯卧撑将自己撑起来。
在回顾了近期使用过的1000条具体命令之后,汇总出了常用的45条命令,基本覆盖了日常使用的需求。对于每个命令,会给出它的简单介绍、详细说明链接和示例运行结果,太长的运行结果会省略掉一部分。
输出终端进程当前的工作目录。
https://www.computerhope.com/unix/upwd.htm
bash-4.4# pwd
/Ada/.simageviewtrainer/rotate/toClassify
每个运行中的进程,都有一个对应的当前工作目录。
当你在终端中启动其它程序以产生对应的进程时,该进程默认会继承终端进程的当前工作目录。在进程中打开或读取以相对路径指定的文件名时,就会以当前工作目录为基准,解析出相对路径的文件名所对应的绝对路径,再确定对应的文件是否存在。
日常使用过程中,某些软件会报告某某文件找不到,其中一个可能的原因就是,进程的当前工作目录不正确,导致某些以相对路径指定的文件无法找到,此时就需要使用pwd命令来显示出当前工作目录,以确定或排除这种可能原因。
相关命令: cd
列出终端进程当前工作目录下的文件和目录。
https://en.wikipedia.org/wiki/Ls
bash-4.4# ls
AssessStockQml
AssessStockServer.emscripten
GoddessCamera.20191008.172335.290.jpg
history.GoddessCamera.20191008.172335.290.txt
Issues
相关命令:pwd
删除终端进程当前工作目录下名为的default的子目录及其中的全部文件,并且详细显示出删除的每个文件的文件名。
https://en.wikipedia.org/wiki/Rm_(Unix)
bash-4.4# rm default/ -rvf
removed directory 'default/Version'
removed directory 'default/stockshort.ConfigurationSubSystem/AssessStock'
removed directory 'default/stockshort.ConfigurationSubSystem/AssessStockServer.emscripten'
removed directory 'default/stockshort.ConfigurationSubSystem/StockCostCalculatorRuby'
removed directory 'default/stockshort.ConfigurationSubSystem/TestAssessServer.platforms'
removed directory 'default/stockshort.ConfigurationSubSystem/Issues'
这是真的删除了文件,要小心使用这种命令。
历史上的相关灾难: https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/issues/123
相关命令:ls
使用qbs编译/Poi/SoftwareDevelop/ShutDownAt2100Project/ShutDownAt2100/ShutDownAt2100.qbs文件所指定的QT代码项目,并安装到/usr目录。
https://en.wikipedia.org/wiki/Qbs_(build_tool)
bash-4.4# qbs -f /Poi/SoftwareDevelop/ShutDownAt2100Project/ShutDownAt2100/ShutDownAt2100.qbs profile:qtc_qt5 qbs.installRoot:/usr
qbs.pluginmanager: loading plugins from "/usr/lib64/qbs/plugins"
qbs.pluginmanager: plugin "/usr/lib64/qbs/plugins/libmakefilegenerator.so" loaded.
qbs.pluginmanager: plugin "/usr/lib64/qbs/plugins/libqbs_cpp_scanner.so" loaded.
qbs.pluginmanager: plugin "/usr/lib64/qbs/plugins/libclangcompilationdbgenerator.so" loaded.
qbs.pluginmanager: plugin "/usr/lib64/qbs/plugins/libvisualstudiogenerator.so" loaded.
qbs.pluginmanager: plugin "/usr/lib64/qbs/plugins/libqbs_qt_scanner.so" loaded.
qbs.buildgraph: trying to load: "/SbWeb/Temp/stockshort.183511/AssessStock/default/default.bg"
Build graph does not yet exist for configuration 'default'. Starting from scratch.
Resolving project for configuration default
qbs.moduleloader: initial search paths: ("/usr/share/qbs")
qbs.moduleloader: load "/Poi/SoftwareDevelop/ShutDownAt2100Project/ShutDownAt2100/ShutDownAt2100.qbs"
退出当前终端进程。
https://bash.cyberciti.biz/guide/Exit_command
bash-4.4# exit
exit
使用dnf在软件仓库中搜索符合以下条件的软件包:
•名字中带有mingw;
•并且,在名字或介绍中带有qt5。
https://fedoraproject.org/wiki/DNF
bash-4.4# dnf search mingw | grep qt5
mingw32-qwt-qt5.noarch : MinGW Windows Qwt library
mingw64-qwt-qt5.noarch : MinGW Windows Qwt library
mingw32-qwt-qt5.noarch : MinGW Windows Qwt library
mingw64-qwt-qt5.noarch : MinGW Windows Qwt library
相关命令:rpm
手动要求VirtualBox软件做以下动作:
•重新启动VirtualBox服务;
•编译并安装VirtualBox所需要的内核驱动。
https://www.tecmint.com/install-virtualbox-in-fedora-linux/
bash-4.4# /sbin/vboxconfig
Failed to enable unit: Unit file vboxdrv.service does not exist.
Failed to enable unit: Unit file vboxballoonctrl-service.service does not exist.
Failed to enable unit: Unit file vboxautostart-service.service does not exist.
Failed to enable unit: Unit file vboxweb-service.service does not exist.
vboxdrv.sh: Stopping VirtualBox services.
vboxdrv.sh: Starting VirtualBox services.
vboxdrv.sh: Building VirtualBox kernel modules.
输出JAVA_HOME这个环境变量的值。如果该环境变量不存在的话,什么都不会输出。
https://www.howtogeek.com/446071/how-to-use-the-echo-command-on-linux/
bash-4.4# echo $JAVA_HOME
相关命令:source
输出java虚拟机执行程序的版本号。
https://en.wikipedia.org/wiki/OpenJDK
bash-4.4# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)
列出RPM包mingw64-qt5-qmake-5.12.5-1.fc30.x86_64中的所有文件。
bash-4.4# rpm -ql mingw64-qt5-qmake-5.12.5-1.fc30.x86_64
/etc/xdg/qtchooser
/etc/xdg/qtchooser/mingw64-qt5.conf
/usr/bin/mingw64-qmake-qt5
/usr/bin/x86_64-w64-mingw32-moc-qt5
/usr/bin/x86_64-w64-mingw32-qdbuscpp2xml-qt5
/usr/bin/x86_64-w64-mingw32-qdbusxml2cpp-qt5
/usr/bin/x86_64-w64-mingw32-qmake-qt5
/usr/bin/x86_64-w64-mingw32-rcc-qt5
/usr/bin/x86_64-w64-mingw32-syncqt.pl-qt5
/usr/bin/x86_64-w64-mingw32-uic-qt5
相关命令:dnf
使用gmake工具,根据当前工作目录下的Makefile文件的内容,编译其中所引用的源代码,并安装到目标位置。
https://www.gnu.org/software/make/
bash-4.4# gmake install
/usr/bin/qmake-qt5 -install qinstall -exe CaptureReportMessageProcessorQt /usr/bin/CaptureRepo
rtMessageProcessorQt
查询sshd服务的当前状态。
https://man.linuxde.net/systemctl
bash-4.4# systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:sshd(8)
man:sshd_config(5)
将当前工作目录下的Mercurial代码仓库中所有已被提交的代码,复制到/Ada/Temp/iknownumber/Issues/PaxHeader/IknowNumberIssues.mm.unknownbeautyle1目录,用于备份。正常运行的情况下,不会有任何输出。
https://www.mercurial-scm.org/
bash-4.4# hg archive /Ada/Temp/iknownumber/Issues/PaxHeader/IknowNumberIssues.mm.unknownbeauty
le1
将终端进程的当前工作目录切换为/Poi/SoftwareDevelop/wise/BareFoot/GitSource/wvipclient/build-ConfigureModule-unknown-Debug。如果命令正常工作完成,不会有任何输出。
bash-4.4# cd /Poi/SoftwareDevelop/wise/BareFoot/GitSource/wvipclient/build-ConfigureModule-unk
nown-Debug
相关命令:pwd
将 GoddessCamera.20190630.074138.348.1180.webp图片的格式转换为png,并保存为GoddessCamera.20190630.074138.348.1180.webp.png。如果命令正常完成,不会有任何输出。
https://imagemagick.org/script/convert.php
[g@c Pictures]$ convert GoddessCamera.20190630.074138.348.1180.webp GoddessCamera.20190630.074138.348.1180.webp
.png
相关命令:ffmpeg
将 GoddessCamera.20190630.074138.348.1180.webp.png图片的格式转换为flif,并保存为GoddessCamera.20190630.074138.348.1180.webp.png.flif。如果命令正常完成,不会有任何输出。
[g@c Pictures]$ flif GoddessCamera.20190630.074138.348.1180.webp.png GoddessCamera.20190630.074138.348.1180.web
p.png.flif
相关命令:convert
使用wine来运行Windows版可执行程序game456_all.exe。
[g@c WXWork]$ wine game456_all.exe
002c:fixme:winediag:__wine_start_process Wine Staging 5.10 is a testing version containing experiment
al patches.
002c:fixme:winediag:__wine_start_process Please mention your exact version when filing bug reports on
winehq.org.
00b4:err:winediag:SECUR32_initNTLMSP ntlm_auth was not found or is outdated. Make sure that ntlm_auth
>= 3.0.25 is in your path. Usually, you can find it in the winbind package of your distribution.
00b4:fixme:dwmapi:DwmIsCompositionEnabled 00000000070E0434
00d8:fixme:iphlpapi:NotifyIpInterfaceChange (family 0, callback 0x301306d, context 0x755c570, init_no
tify 0, handle 0x803f9e0): stub
00b4:fixme:ntdll:NtQuerySystemInformation info_class SYSTEM_PERFORMANCE_INFORMATION
0130:err:winediag:SECUR32_initNTLMSP ntlm_auth was not found or is outdated. Make sure that ntlm_auth
>= 3.0.25 is in your path. Usually, you can find it in the winbind package of your distribution.
0130:fixme:dwmapi:DwmIsCompositionEnabled 0656DD14
0138:fixme:iphlpapi:NotifyIpInterfaceChange (family 0, callback 0x2cef537, context 0x6a4bd40, init_no
tify 0, handle 0x745fcd8): stub
0130:fixme:ntdll:NtQuerySystemInformation info_class SYSTEM_PERFORMANCE_INFORMATION
wine: configuration in L"/home/g/.wine" has been updated.
判断liblog4qt.a的文件类型,并输出。
https://en.wikipedia.org/wiki/File_%28command%29
[g@c build-ConfigureModule-Desktop-Debug]$ file liblog4qt.a
liblog4qt.a: current ar archive
查询并显示出近期使用过的包含qbs字样的命令。
https://www.howtogeek.com/465243/how-to-use-the-history-command-on-linux/
[g@c build-ConfigureModule-Desktop-Debug]$ history | grep qbs
1003 qbs --version
1004 history | grep qbs
启动wine的配置界面。
[g@c build-ConfigureModule-Desktop-Debug]$ winecfg
002c:fixme:winediag:__wine_start_process Wine Staging 5.10 is a testing version containing experiment
al patches.
002c:fixme:winediag:__wine_start_process Please mention your exact version when filing bug reports on
winehq.org.
输出PulseAudio的命令行控制程序pactl的详细使用说明。
https://linux.die.net/man/1/pactl
[g@c build-ConfigureModule-Desktop-Debug]$ pactl help
pactl [选项] stat
pactl [选项] info
pactl [选项] list [short] [类型]
pactl [选项] exit
输出科学上网程序expressvpn的版本号。
[g@c build-ConfigureModule-Desktop-Debug]$ expressvpn --version
expressvpn version 2.5.1.1 - Release (95c7c6b2)
启动重复文件清理工具fslint的图形界面。这个图形界面工具正常运行情况下不会在终端输出任何东西。
http://www.pixelbeat.org/fslint/
[g@c build-ConfigureModule-Desktop-Debug]$ fslint-gui
关机。
https://www.computerhope.com/unix/uhalt.htm
扫描系统已知路径中所有的共享库文件,并更新缓存。正常运行情况下不会有任何输出。
https://linux.die.net/man/8/ldconfig
[g@c build-ConfigureModule-Desktop-Debug]$ sudo ldconfig
[sudo] g 的密码:
寻找当前正在监听11013端口的进程,并输出它的信息。
https://www.lifewire.com/netstat-command-2618098
[g@c build-ConfigureModule-Desktop-Debug]$ netstat -nlp | grep 11013
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:11013 0.0.0.0:* LISTEN 178601/wvipcManager
根据终端进程当前工作目录下的?.pro QT项目文件的内容,生成对应的Makefile文件,后续可使用gmake执行该Makefile文件,编译整个项目的源代码。
https://doc.qt.io/qt-5/qmake-manual.html
[g@c AssessStockQml]$ qmake-qt5
Info: creating stash file /home/g/SoftwareDevelop/stockshort..pdf.png.jpg/AssessStockQml/.qmake.stash
使用ssh远程登录到139.162.164.8,端口号为7465,用户名为 root,密码随后输入。
https://en.wikipedia.org/wiki/Secure_Shell
[g@c AssessStockQml]$ ssh -l root -p 7465 139.162.164.8
root@139.162.164.8's password:
Last login: Fri Jul 10 23:22:32 2020 from 113.118.102.209
将JSON文件voicePackageUrlMap.json的内容以美观的格式输出。
https://stedolan.github.io/jq/
[g@c TestAssessServer.platforms]$ jq . voicePackageUrlMap.json
{
"voicePackageMapJsonItemList": [
{
"packageUrl": "https://dl.cmbimg.com/AndroidClient/CMBMobileBank.apk",
"voiceCommand": "招商银行"
},
{
"packageUrl": "https://dl001.liqucn.com/upload/2011/qita_shenghuo/cn.amazon.mshop.android_18.7.
0.600_liqucn.com.apk",
"voiceCommand": "亚马逊购物"
},
{
使用Ruby的gem工具安装一个第三方ruby库oj。
https://guides.rubygems.org/command-reference/#gem-install
[g@c VoicePackageUrlMapInternationalization]$ gem install oj
Fetching oj-3.10.6.gem
Building native extensions. This could take a while...
Successfully installed oj-3.10.6
Parsing documentation for oj-3.10.6
Installing ri documentation for oj-3.10.6
Done installing documentation for oj after 1 seconds
1 gem installed
相关命令:irb
启动Ruby的命令行交互界面,可在该界面里写Ruby代码并运行。
https://www.tutorialspoint.com/ruby/interactive_ruby.htm
[g@c VoicePackageUrlMapInternationalization]$ irb
irb(main):001:0> print('Ruby!')
Ruby!=> nil
irb(main):002:0>
输出容器化工具docker的详细使用说明。
[g@c VoicePackageUrlMapInternationalization]$ docker help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
启动图形界面的文件系统存储空间占用情况分析工具filelight,并将控制权返回到当前终端进程,使得你可以继续输入并执行其它命令。会输出被启动的进程的进程号,然后又等待你输入新的命令。
https://en.wikipedia.org/wiki/Filelight
[g@c VoicePackageUrlMapInternationalization]$ filelight &
[1] 203255
寻找并列出当前处于运行状态的所有dolphin进程。
https://en.wikipedia.org/wiki/Ps_(Unix)
[g@c VoicePackageUrlMapInternationalization]$ ps -ef | grep dolphin
g 4490 1 0 08:56 ? 00:00:01 /usr/bin/dolphin --daemon
g 6951 1 1 08:59 ? 00:04:59 /usr/bin/dolphin /run/media/g/d48fc17c-4170-47ae-
91bc-f8664a8de96b
检查本机与IP为192.168.0.102的主机之间网络是否连通。它会持续检查,直到你按Ctrl+C才会终止,并且输出检查结论。
https://en.wikipedia.org/wiki/Ping_%28networking_utility%29
[g@c VoicePackageUrlMapInternationalization]$ ping 192.168.0.102
PING 192.168.0.102 (192.168.0.102) 56(84) bytes of data.
^C
--- 192.168.0.102 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1003ms
输出图形界面的图片处理工具gimp的详细使用说明。
[g@c VoicePackageUrlMapInternationalization]$ gimp --help
用法:
gimp [OPTION…] [文件|URI…]
GNU 图像处理程序
帮助选项:
手动启动整个KF5桌面环境,并将控制权返回到当前终端进程,使得你可以继续执行其它命令。会输出被启动的进程的进程号。
https://www.ryananddebi.com/2019/07/21/restarting-kdes-plasma-shell-via-konsole-command-line/
[g@c VoicePackageUrlMapInternationalization]$ plasmashell&
[1] 234116
执行终端进程当前工作目录下emsdk_env.sh脚本的内容,并保留该脚本中的副作用,例如该脚本中设置的环境变量会在当前终端中生效。
https://en.wikipedia.org/wiki/Dot_(command)#Source
[g@c emsdk-1.39.16]$ source ./emsdk_env.sh
Adding directories to PATH:
PATH += /home/g/Temp/stockshort.104603/TestAssessServer.platforms/emsdk-1.39.16
Setting environment variables:
EMSDK = /home/g/Temp/stockshort.104603/TestAssessServer.platforms/emsdk-1.39.16
EM_CONFIG = /home/g/.emscripten
从终端进程当前工作目录下的 SBrowser.2020.06.06.18.59.42.510.log文件中,寻找出所有包含intercept字样的行,并且输出到SBrowser.2020.06.06.18.59.42.510.log.intercept.log文件中。正常运行过程中不会有任何输出。
https://www.gnu.org/software/grep/
[g@c log]$ grep intercept < SBrowser.2020.06.06.18.59.42.510.log > SBrowser.2020.06.06.18.59.42.510.l
og.intercept.log
输出本机与DNS相关的基本配置信息。
https://en.wikipedia.org/wiki/Dig_(command)
[g@c log]$ dig
; <<>> DiG 9.11.20-RedHat-9.11.20-1.fc31 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6675
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;. IN NS
;; ANSWER SECTION:
. 1700 IN NS h.root-servers.net.
. 1700 IN NS d.root-servers.net.
. 1700 IN NS a.root-servers.net.
. 1700 IN NS f.root-servers.net.
. 1700 IN NS l.root-servers.net.
. 1700 IN NS g.root-servers.net.
. 1700 IN NS k.root-servers.net.
. 1700 IN NS c.root-servers.net.
. 1700 IN NS m.root-servers.net.
. 1700 IN NS j.root-servers.net.
. 1700 IN NS b.root-servers.net.
. 1700 IN NS e.root-servers.net.
. 1700 IN NS i.root-servers.net.
;; Query time: 27 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: 一 7月 13 15:42:00 CST 2020
;; MSG SIZE rcvd: 239
输出安卓基本调试工具adb的详细使用说明。
https://developer.android.com/studio/command-line/adb
[g@c log]$ adb
Android Debug Bridge version 1.0.41
Version 30.0.3-6597393
Installed as /home/g/Program/androidSdk/platform-tools/adb
global options:
输出操作系统内核的日志内容。
https://en.wikipedia.org/wiki/Dmesg
[g@c log]$ dmesg
[ 0.459342] pci 0000:01:00.1: [1002:aae0] type 00 class 0x040300
[ 0.459358] pci 0000:01:00.1: reg 0x10: [mem 0xe2360000-0xe2363fff 64bit]
[ 0.459419] pci 0000:01:00.1: supports D1 D2
[ 0.459492] pci 0000:00:01.0: PCI bridge to [bus 01]
将终端进程当前工作目录下的 82.ts、83.ts、84.ts、85.ts文件的内容按照顺序合并起来,写入到aoLiAn.ts文件中去。正常运行过程中不会有任何终端输出。
https://en.wikipedia.org/wiki/Cat_%28Unix%29
[g@c Temp]$ cat 82.ts 83.ts 84.ts 85.ts > aoLiAn.ts
将终端进程当前工作目录下视频文件 aoLiAn.ts的音频内容提取出来,写入到aoLiAn.flac文件中。
[g@c Temp]$ ffmpeg -i aoLiAn.ts aoLiAn.flac
ffmpeg version 4.2.3 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 9 (GCC)
下载https://www.caoyuanfeng.com/up_files/jingqufenbu.gif文件,并保存到终端进程当前工作目录。
https://www.gnu.org/software/wget/
[g@c Temp]$ wget https://www.caoyuanfeng.com/up_files/jingqufenbu.gif
--2020-07-13 16:05:54-- https://www.caoyuanfeng.com/up_files/jingqufenbu.gif
正在解析主机 www.caoyuanfeng.com (www.caoyuanfeng.com)... 211.159.160.246
正在连接 www.caoyuanfeng.com (www.caoyuanfeng.com)|211.159.160.246|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:529704 (517K) [image/gif]
正在保存至: “jingqufenbu.gif”
jingqufenbu.gif 100%[==================================>] 517.29K 1.99MB/s 用时 0.3s
2020-07-13 16:05:56 (1.99 MB/s) - 已保存 “jingqufenbu.gif” [529704/529704])
HxLauncher: Launch Android applications by voice commands