---
title: Linux commands
date: 2021-04-19 04:40:11
updated: 2021-07-28 03:40:11
tags:
- command
- linux
- cheatsheet
categories:
- computer
---
#command on using Linux.
For the footnotes: [^1]
for the usage, info, reference of a command; [^command_name]
for the official website of a command.
See also tips & what to do on [[Setup Linux machine]].
#cheatsheet Use lower case on filename ^[@see: 为什么文件名要小写? - 阮一峰的网络日志 ]
ip addr
ifconfig
hostname -I
uname -a
. Check it, after [[Upgrade Linux kernel]].uname -r
cat /proc/version
dmesg | grep Linux
nproc
- and use it in make:
make -j $(nproc)
(@see [[Upgrade Linux kernel]])
- and use it in make:
- Use the
taskset
utility, which allows us to control the affinity of a process. 1
Check it with Python 1
# Python 2.6+
try:
import multiprocessing
return multiprocessing.cpu_count()
except (ImportError, NotImplementedError):
pass
import psutil
psutil.cpu_count()
Check it with Go 2
if runtime.NumCPU() < 10 && os.Getenv("CI") \== "" { // don't bother on slow hardware
t.Skip("this is slow")
}
https://play.golang.org/p/cuaf2ZHLIx
package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Println(runtime.NumCPU())
}
linux freeze process is useful when hdd out of space when plotting.
Q: What can I do when hard drive run out of space when half a way during plotting? -> Google: linux freeze process https://superuser.com/questions/485884/can-a-process-be-frozen-temporarily-in-linux/485888
Simply kill a process with htop
or kill it with kill
+<pid>.
kill -15 <pid>
>>kill -9 <pid>
- Let process to settle resources with R.I.P. (-> -15 >> -9)
pkill -f pattern
to kill a process by process patternfor pid in $(ps -ef | awk '/some-search/ {print $2}'); do kill -15 $pid; done
Recover deleted commands in Linux: busybox, coreutils 3 4, moreutils 5
#convenient
bat
>>cat
tmux
>> GNUscreen
find
grep
ps
->ps aux
uname
hostname
to see ->hostnamectl
to editalias
6lsblk
lsusb
lspci
lsof
to list open file
& more in Coreutils - GNU core utilities
powerline
7tmux
tldr
syncthing
ansible
for DSC
pv
, acronym of pipe viewer, to monitor the progress of data through a pipe 8progress
cmatrix
screenfetch
neofetch
man
info
tldr
9 10apropos
The fuck
11 12- install:
sudo pip3 install thefuck
- install:
eg
(install:pip install eg
) 13
cheat.sh
14- https://cheat.sh/ for online search
cheat
15- Devhints : Devhints — TL;DR for developer documentation #cheatsheet
how2
whatis
locate
whereis
which
history
&!!
(bash)search <command>
(fish)find
fd
ssh
- mount remote server file system (in [[FUSE]]) with
sshfs
24 25- Create sshfs mount dir:
sudo mkdir /mnt/remote_machine
- mount it:
sshfs <user>@<ip addr> : /home/<user> /mnt/remote_machine
- check mount point with
df -hT
- Finally, unmount it:
unmount /mnt/remote_machine
- Create sshfs mount dir:
- wget
- curl
- aria2c
- httpie
rename
by Larry Wall 26rename
that node-rename-cli 27mmv
26renameutils
26Vimv
is a command line utility to bulk rename files using Vim editor 26 28- F2 https://mp.weixin.qq.com/s/CA1HQtDiHU_l1nMSRYJxRg
vim
https://mp.weixin.qq.com/s/NbgxpapUkKf30VNQOoBKlQ- cheatsheet: Vim cheatsheet
nano
code
for [[VS Code]] /code-insiders
hexyl
30
md5sum FILE
openssl dgst -sha256 FILE
-
md2 MD2 Digest md5 MD5 Digest mdc2 MDC2 Digest rmd160 RMD-160 Digest sha SHA Digest sha1 SHA-1 Digest sha224 SHA-224 Digest sha256 SHA-256 Digest sha384 SHA-384 Digest sha512 SHA-512 Digest```
cat /etc/shells
to see what shells are available on the system.bash
- cheatsheet: [Bash scripting cheatsheet](Bash scripting cheatsheet)
zsh
andoh-my-zsh
31 32- Powerlevel9k to theming zsh
- chatsheet: 终极 Shell | MacTalk-池建强的随想录
fish
and 'on-my-fish'omf
33- pysh 34
cpulimit
35 36 to prevent overheat with long-run processes, such as [[Cryptomining]] -> [[Limit CPU usage]]nice
value.cputhrottle
37- Google: linux gpu limit
ps aux
pstree
pgrep
pkill
ssh
->mosh
Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes.
<command> &
- 使用
nohup
或disown
使一個後臺程序持續運行。 ctrl-z
ctrl-c
kill
kill -t <pid>
jobs
fg
bg
usermod
to change user name 38
- Shell bomb / Fork bomb:
fork() { fork | fork & } fork
->:(){ :|:& };:
[^fork bomb] - Delete it forever:
rm -f /
htop
top
atop
vtop
gtop
ctop
glances
bpytop
(former:bashtop
) (install:pip install bpytop
)cockpit
Cockpit project by Redhat 39nmon
psutil
40Prometheus
sar
vmstat
uptime
strace
iotop
nethogs
iostat
mpstat
free
shows memory usage.uptime
dmesg
shows info of Linux booting.bind
shows keyboard key binding.dstat
free
vmstat
- cockpit,pydash,linux-dash,Scout_Realtime https://mp.weixin.qq.com/s/jBWq_pEva-uHiBW4kn8QpQ
time
to see how long a command takes.hyperfine
benchmarks commands throught the command line.44sysbench
to benchmark CPU, memory, I/O 457z b
- https://zhuanlan.zhihu.com/p/348894047
- duplicati
restic
46 47rsync
-> Full system backup with rsync
Storage Concepts And Technologies Explained In Detail - OSTechNix
rsync
>>cp
fsck
on an unmount partition to fix error 48 49- Check bad sector with
badblocks
when using a failure hard drive 50 -> [[Fix a hard drive]]- -> Use info from
badblocks
withfsck
51
- -> Use info from
diskscan
52samba
iometer
du
to show file & directory usage.dd
to backup & restore of block devices.df
to show info of disks.smartmontools
&smartctl
for SSD endurance [^SSD Endurance].- 你可以通過 “hdparm -tT /dev/hda” 來測試 “/dev/hda” 硬碟的訪問速度 53
ifconfig
ip
dig
- ping,tracert,nslookup
- mtr 全称 my traceroute,是一个把 ping 和 traceroute 合并到一个程序的网络诊断工具。https://mp.weixin.qq.com/s/_7liuv3_U57VLzVHJstIcg
route
netstat
iptraf
&iptraf-ng
iftop
ntop
nload
nmap
54netcat
https://github.com/herrbischoff/awesome-command-line-apps#automation
psensor
55
sshd
dhcpd
mysqld
httpd
is Apachersyncd
for rsynclsyncd
(Live Syncing Daemon) for sync local and remote directories 56
at
for one shot.crontab
for cron job (regular scheduling). 57
- Wine, a free and open-source compatibility layer that helps us to install and run applications and games developed for Windows on Linux and Unix-like operating systems.
- Dosbox, to run good-old MS-DOS games and defunct C++ compilers like Turbo C++ in Linux.
- Anbox, for Android apps. 58
- Darling is a translation layer that lets you run macOS software on Linux 59
Browser Automation: selenlum GUI automation: Pyautogui
youtube-dl
(install: python3 -m pip intall youtube-dl
)coursera-dl
- Fabric
- is a tool used for automating routine shell commands over SSH,
- is a deployment management framework written in Python which makes remotely managing multiple servers incredibly easy
ssh <user>@<ip addr> <command to be issued>
tig
GitUI
62 63- github1s - https://github.com/conwnet/github1s
- pre-commit 64
pip
for Python languagepython39 -m pip
with use of Python3.9python -m
with use of a virtual environment activated of Python
npm
for Javascript & node.jscargo
for Rust language
venv
is a package shipped with Python 3, which you can run usingpython3 -m venv
It serves the same purpose as virtualenv, but only has a subset of its features. 65python3 -m venv <project-venv>
->source ./project-venv/bin/activate
->pip install <package> -> ``deactivate
virtualenv
&virtualenvwrapper
65
pyenv
is a bit different to virtual envo ->pyenv
is used to isolate Python versions. -> manages different python versions. 65 是 requests 作者 Kenneth Reitz 大神写的一个 python 虚拟环境管理工具, 结合了 pip 和 virtualenv 的功能
mycli
usql
Ansible is a configuration management and orchestration tool. It works as an IT automation engine.
- [[Manage machine with Ansible]]
Docker is a docker to provide isolated envo: ensure dev envo & production envo are the same.
https://mp.weixin.qq.com/s/KJZn-y4PBU2rnjE3g7AbIQ Docker 架構 https://mp.weixin.qq.com/s/1uDn4CKitQhU04OTA9F_ZA
https://mp.weixin.qq.com/s/eSLunx8-4XGlA-FOzyoZrw
Reference:
- Linux administration: Google: xxx handbook, xxx wiki
- Google: Art of command-line -> - https://github.com/jlevy/the-art-of-command-line
- https://github.com/topics/ls -> https://github.com/jaywcjlove/linux-command
- Google: Awesome command-line -> https://github.com/agarrharr/awesome-cli-apps
- https://github.com/alebcay/awesome-shell
- https://www.reddit.com/r/linuxquestions/comments/ntdm7m/good_linux_networking_tutorial/ -> https://www.billdietrich.me/LinuxNetworking.htmlhttps://www.reddit.com/r/linuxquestions/comments/ntdm7m/good_linux_networking_tutorial/ -> https://www.billdietrich.me/LinuxNetworking.html
- to alias: 10 个 Linux 中超方便的 Bash 别名 - 奇妙的 Linux 世界
- 30 Linux System Monitoring Tools Every SysAdmin Should Know - nixCraft
- Monitoring Tools Archives - OSTechNix
- Category System monitors - ArchWiki
- Linux Hint - Exploring and Master Linux Ecosystem
- "How To Add Route on Linux – devconnected" https://devconnected.com/how-to-add-route-on-linux/
- 2021-07-01 给你的终端加点料 —— 7 个让终端更好用的小工具 - 少数派
--EOF
Footnotes
-
system information - How to find out the number of CPUs using python - Stack Overflow ↩ ↩2
-
How To Restore Or Recover Deleted Commands In Linux - OSTechNix ↩
-
man cp | grep coreutils
-> Coreutils - GNU core utilities ↩ -
How To Restore Or Recover Deleted Commands In Linux - OSTechNix -> Moreutils - A Collection Of More Useful Unix Utilities - OSTechNix -> https://joeyh.name/code/moreutils/ ↩
-
https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html ↩
-
How To Use Pv Command To Monitor The Progress Of Data In Linux ↩
-
Good Alternatives To Man Pages Every Linux User Needs To Know ↩
-
Google: awesome command-line -> https://github.com/agarrharr/awesome-cli-apps ↩
-
How To Display Linux Commands Cheatsheets Using Eg - OSTechNix ↩
-
25 个 Linux 下的炫酷又强大的命令行神器,你用过其中哪几个呢? - 奇妙的 Linux 世界 ↩ ↩2 ↩3 ↩4
-
25 个 Linux 下的炫酷又强大的命令行神器,你用过其中哪几个呢? - 奇妙的 Linux 世界 -> https://github.com/ogham/exa ↩
-
https://github.com/sharkdp/fd -> https://github.com/sharkdp/bat ↩
-
2021-04-26 40 Linux Server Hardening Security Tips [2019 edition] - nixCraft -> Redhat Enterprise Linux securely mount remote Linux _ UNIX directory or file system using SSHFS - nixCraft -> https://github.com/libfuse/sshfs ↩
-
2021-04-26 Google: linux remote file system -> How to Mount Remote Linux Filesystem or Directory Using SSHFS Over SSH ↩
-
6 Methods To Rename Multiple Files At Once In Linux ↩ ↩2 ↩3 ↩4
-
Google: awesome command-line -> https://github.com/agarrharr/awesome-cli-apps -> -> https://github.com/jhotmann/node-rename-cli ↩
-
https://github.com/learnbyexample/Command-line-text-processing ↩ ↩2
-
https://github.com/sharkdp/fd -> https://github.com/sharkdp/hexyl ↩
-
Google: theming zsh -> https://github.com/ohmyzsh/ohmyzsh/wiki/Themes ↩
-
Google: theming fish -> https://github.com/oh-my-fish/oh-my-fish/blob/master/docs/Themes.md ↩
-
https://github.com/sharkdp/fd -> https://github.com/sharkdp/pysh ↩
-
cpulimit
attempts to limit the cpu usage of a process (expressed in percentage, not in cpu time). This is useful to control batch jobs, when you don't want them to eat too much cpu. It does not act on the nice value or other scheduling priority stuff, but on the real cpu usage. ↩ -
https://cockpit-project.org/guide/latest/ [^fork bomb]: https://zh.wikipedia.org/wiki/Fork%E7%82%B8%E5%BC%B9 ↩
-
https://github.com/topics/command-line -> https://github.com/sqshq/sampler ↩
-
https://github.com/sharkdp/fd -> https://github.com/sharkdp/hyperfine ↩
-
How to Use Sysbench for Linux Performance Testing? – Linux Hint ↩
-
https://github.com/topics/deduplication -> https://github.com/restic/restic [^SSD Endurance]: https://github.com/Chia-Network/chia-blockchain/wiki/SSD-Endurance ↩
-
2021-04-20 Google: linuxmint initramfs -> Linux Mint initramfs prompt at boot, #Linux | How to fix Linux Mint initramfs Prompt at Boot. I run
fsck
with a live USB on/dev/sda
on a notebook computer to fix Linux not boot due to sector corruption on partition . ↩ -
Google: linux hdd low level format -> Low level format of hard drive - Ask Ubuntu -> https://github.com/baruch/diskscan/ ↩
-
https://www.debian.org/doc/manuals/debian-reference/ch09.zh-tw.html#_optimization_of_hard_disk ↩
-
https://www.cyberciti.biz/networking/nmap-command-examples-tutorials/ ↩
-
Google: rslsync -> 使用 Resilio Sync 进行同步 | Memo -> Ubuntu Memo | Memo ↩
-
How To Synchronize Local And Remote Directories In Linux - OSTechNix ↩
-
Google: alternative to cloc -> A fast cloc replacement written in rust programming -> https://github.com/cgag/loc ↩
-
python - What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? - Stack Overflow ↩ ↩2 ↩3