文章轉發自專業的Laravel開發者社區,原始連接: https://learnku.com/laravel/t...
我很高興你在這裏!幾年前我從事生物信息學方面的研究工做。對那些簡單的 bash 命令感到驚訝,他們比個人枯燥腳本快不少。經過學習命令行的快捷方式和腳本幫助我節省了不少時間。近年來,我從事雲計算相關的工做,並在這裏繼續記錄那些有用的命令。而且我在努力的使他們簡短並且迅速。我主要使用 Ubuntu,RedHat ,Linux Mint 以及 CentOS 系統,若是命令在您的系統上不生效,那麼我很抱歉。php
該博客將重點介紹我從工做以及 LPIC 的考試中得到的用於解析數據和 Linux 系統維護的簡單命令,可是他們可能來自於親愛的 Google 和 Stackoverflow。html
英語和 bash 並非個人母語,請隨時糾正我,謝謝。若是你知道其餘有趣的命令,請教教我。node
這是更新潮的版本Bash-Oneliner~python
Ctrl + n : 相似向下的鍵 Ctrl + p : 相似向上的鍵 Ctrl + r : 反向搜索命令的歷史記錄(按住 Ctrl + r ) Ctrl + s : 終端中止輸出.(譯者注:如 apt / yum,nload,watch 等,按 Enter 繼續輸出) Ctrl + q : 在 Ctrl + s 以後從新恢復以前的 terminal. Ctrl + a : 移動光標到行的開始處 Ctrl + e : 移動光標到行的結尾處 Ctrl + d : 若是當前的 terminal 命令行有輸入,Ctrl + d 或刪除光標處的字符,不然會退出當前的 terminal Ctrl + k : 刪除從當前光標到結尾的全部字符 Ctrl + x + backspace : 刪除當前光標到行開始的全部字符 Ctrl + t : 交換當前光標下的字符和其前面字符的位置。Esc + t 交換光標前面的兩個單詞 Ctrl + w : 剪切光標以前的單詞,而後 Ctrl + y 粘貼它 Ctrl + u : 剪切光標以前的行; 而後 Ctrl + y 粘貼它 Ctrl + _ : 撤銷以前的操做 Ctrl + l : 至關於清除 Ctrl + x + Ctrl + e : 召喚起 $EDITOR 環境變量設置的編輯器程序,對多行命令有效
Esc + u # 將文本從光標的開始到結尾的單詞轉換爲大寫 Esc + l # 將文本從光標的開始到結尾的單詞轉換爲小寫 Esc + c # 將光標下的字母轉換爲大寫
!53
!!
#最後的一條命令: echo 'aaa' ^aaa^bbb #echo 'bbb' #bbb #注意只有惟一的第一個 aaa 將會被替代,若是你想替代全部的 aaa,使用「:&」替代: ^aaa^bbb^:& #或者 !!:gs/aaa/bbb/
!cat # 或者 !c #再次運行cat文件名
# '*' 用做文件名擴展的 "通配符" 。 /b?n/?at #/bin/cat # '?' 用做文件名擴展的單字符 "通配符" 。 /etc/pa*wd #/etc/passwd # ‘[]’ 用於匹配範圍內的字符。 ls -l [a-z]* #列出全部文件名中帶有字母的文件。 # ‘{}’ 可用於匹配多個模式的文件名 ls {*.sh,*.py} #列出全部.sh和.py文件
$0 :shell或shell腳本的名稱。 $1, $2, $3, ... :位置參數。 $# :位置參數的數量。 $? :最新的管道退出狀態。 $- :爲shell設置的當前選項。 $$ :當前shell(不是subshell)的pid。 $! :最新後臺命令的PID。 $DESKTOP_SESSION 當前顯示管理器 $EDITOR 首選文本編輯器。 $LANG 當前語言。 $PATH 搜索可執行文件的目錄列表(即準備運行的程序) $PWD 當前目錄 $SHELL 當前 shell $USER 當前用戶名 $HOSTNAME 當前主機名
[返回頂部]linux
grep = grep -G # Basic Regular Expression (BRE) fgrep = grep -F # fixed text, ignoring meta-charachetrs egrep = grep -E # Extended Regular Expression (ERE) pgrep = grep -P # Perl Compatible Regular Expressions (PCRE) rgrep = grep -r # recursive
grep -c "^$"
grep -o '[0-9]*' #or grep -oP '\d'
grep ‘[0-9]\{3\}’ # or grep -E ‘[0-9]{3}’ # or grep -P ‘\d{3}’
grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' # or grep -Po '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
grep -w 'target' #or using RE grep '\btarget\b'
# return also 3 lines after match grep -A 3 'bbo' # return also 3 lines before match grep -B 3 'bbo' # return also 3 lines before and after match grep -C 3 'bbo'
grep -o 'S.*'
grep -o -P '(?<=w1).*(?=w2)'
grep -v bbo filename
grep -v '^#' file.txt
grep "$boo" filename #remember to quote the variable!
grep -m 1 bbo filename
grep -c bbo filename
grep -o bbo filename |wc -l
grep -i "bbo" filename
grep --color bbo filename
grep -R bbo /path/to/directory # or grep -r bbo /path/to/directory
grep -rh bbo /path/to/directory
grep -rl bbo /path/to/directory
grep 'A\|B\|C\|D'
grep 'A.*B'
grep 'A.B'
grep ‘colou?r’
grep -f fileA fileB
grep $'\t'
$echo "$long_str"|grep -q "$short_str" if [ $? -eq 0 ]; then echo 'found'; fi #grep -q will output 0 if match found #remember to add space between []!
grep -oP '\(\K[^\)]+'
grep -o -w "\w\{10\}\-R\w\{1\}" # \w 文字字符 [0-9a-zA-Z_] \W 非文字字符
grep -d skip 'bbo' /path/to/files/*
[返回頂部]ios
sed 1d filename
sed 1,100d filename
sed "/bbo/d" filename - case insensitive: sed "/bbo/Id" filename
sed -E '/^.{5}[^2]/d' #aaaa2aaa (you can stay) #aaaa1aaa (delete!)
sed -i "/bbo/d" filename
# e.g. add >$i to the first line (to make a bioinformatics FASTA file) sed "1i >$i" # notice the double quotes! in other examples, you can use a single quote, but here, no way! # '1i' means insert to first line
# 使用反斜槓 $ 符,同時使用雙引號來標記變量 sed -e "\$s/\$/\n+--$3-----+/"
sed '/^\s*$/d' # 或 sed '/^$/d'
sed '$d'
sed -i '$ s/.$//' filename
sed -i '1s/^/[/' file
sed -e '1isomething -e '3isomething'
sed '$s/$/]/' filename
sed '$a\'
sed -e 's/^/bbo/' file
sed -e 's/$/\}\]/' filename
sed 's/.\{4\}/&\n/g'
sed -s '$a,' *.json > all.json
sed 's/A/B/g' filename
sed "s/aaa=.*/aaa=\/my\/new\/path/g"
sed -n '/^@S/p'
sed '/bbo/d' filename
sed -n 500,5000p filename
sed -n '0~3p' filename # catch 0: start; 3: step
sed -n '1~2p'
sed -n '1p;0~3p'
sed -e 's/^[ \t]*//' # Notice a whitespace before '\t'!!
sed 's/ *//' # 注意'*'前的空格!!
sed 's/,$//g'
sed "s/$/\t$i/" # $i 是你要添加的值 # 將文件名添加到文件的最後一列 for i in $(ls);do sed -i "s/$/\t$i/" $i;done
for i in T000086_1.02.n T000086_1.02.p;do sed "s/$/\t${i/*./}/" $i;done >T000086_1.02.np
sed ':a;N;$!ba;s/\n//g'
sed -n -e '123p'
sed -n '10,33p' <filename
sed 's=/=\\/=g'
A-1-e
、 A-2-e
或者 A-3-e
....)sed 's/A-.*-e//g' filename
sed '$ s/.$//'
sed -r -e 's/^.{3}/&#/' file
[返回頂部]laravel
awk -F $'\t'
awk -v OFS='\t'
a=bbo;b=obb; awk -v a="$a" -v b="$b" "$1==a && $10=b" filename
awk '{print NR,length($0);}' filename
awk '{print NF}'
awk '{print $2, $1}'
awk '$1~/,/ {print}'
awk '{split($2, a,",");for (i in a) print $1"\t"a[i]}' filename
awk -v N=7 '{print}/bbo/&& --N<=0 {exit}'
ls|xargs -n1 -I file awk '{s=$0};END{print FILENAME,s}' file
awk 'BEGIN{OFS="\t"}$3="chr"$3'
awk '!/bbo/' file
awk 'NF{NF-=1};1' file
# 例如如下2個文件: # fileA: # a # b # c # fileB: # d # e awk 'print FILENAME, NR,FNR,$0}' fileA fileB # fileA 1 1 a # fileA 2 2 b # fileA 3 3 c # fileB 4 1 d # fileB 5 2 e
# 好比下面這兩個文件: # 文件 A: # 1 0 # 2 1 # 3 1 # 4 0 # 文件 B: # 1 0 # 2 1 # 3 0 # 4 1 awk -v OFS='\t' 'NR=FNR{a[$1]=$2;next} NF {print $1,((a[$1]=$2)? $2:"0")}' fileA 文件 B # 1 0 # 2 1 # 3 0 # 4 0
awk '{while (match($0, /[0-9]+\[0-9]+/)){ \printf "%s%.2f", substr($0,0,RSTART-1),substr($0,RSTART,RLENGTH) \$0=substr($0, RSTART+RLENGTH) \} \print \}'
awk '{printf("%s\t%s\n",NR,$0)}'
#例如分開一下內容: # David cat,dog # into # David cat # David dog awk '{split($2,a,",");for(i in a)print $1"\t"a[i]}' file # 詳情介紹請點擊這裏: http://stackoverflow.com/questions/33408762/bash-turning-single-comma-separated-column-into-multi-line-string
awk '{s+=$1}END{print s/NR}'
awk '$1 ~ /^Linux/'
awk ' {split( $0, a, "\t" ); asort( a ); for( i = 1; i <= length(a); i++ ) printf( "%s\t", a[i] ); printf( "\n" ); }'
awk '{$6 = $4 - prev5; prev5 = $5; print;}'
[回到頂部]git
xargs -d\t
echo 1 2 3 4 5 6| xargs -n 3 # 1 2 3 # 4 5 6
echo a b c |xargs -p -n 3
xargs -t abcd # bin/echo abcd # abcd
find . -name "*.html"|xargs rm # when using a backtick rm `find . -name "*.html"`
find . -name "*.c" -print0|xargs -0 rm -rf
xargs --show-limits
find . -name "*.bak" -print 0|xargs -0 -I {} mv {} ~/old # or find . -name "*.bak" -print 0|xargs -0 -I file mv file ~/old
ls |head -100|xargs -I {} mv {} d1
time echo {1..5} |xargs -n 1 -P 5 sleep # a lot faster than: time echo {1..5} |xargs -n1 sleep
find /dir/to/A -type f -name "*.py" -print 0| xargs -0 -r -I file cp -v -p file --target-directory=/path/to/B # v: verbose| # p: keep detail (e.g. owner)
ls |xargs -n1 -I file sed -i '/^Pos/d' filename
ls |sed 's/.txt//g'|xargs -n1 -I file sed -i -e '1 i\>file\' file.txt
ls |xargs -n1 wc -l
ls -l| xargs
echo mso{1..8}|xargs -n1 bash -c 'echo -n "$1:"; ls -la "$1"| grep -w 74 |wc -l' -- # "--" 信號選項結束,並進一步進行選項的處理
ls|xargs wc -l
cat grep_list |xargs -I{} grep {} filename
grep -rl '192.168.1.111' /etc | xargs sed -i 's/192.168.1.111/192.168.2.111/g'
[返回頂部]程序員
find .
find . -type f
find . -type d
find . -name '*.php' -exec sed -i 's/www/w/g' {} \; # 若是沒有子目錄 replace "www" "w" -- * # a space before *
find mso*/ -name M* -printf "%f\n"
find . -name "*.mso" -size -74c -delete # M 表明 MB, 等等
[返回頂部]github
# 使用 if 和 else 來進行條件判斷 if [[ "$c" == "read" ]]; then outputdir="seq"; else outputdir="write" ; fi # 判斷myfile是否包含字符串「test」 if grep -q hello myfile; then … # 判斷mydir 是不是一個目錄, 修改 mydir 的內容 而且 執行其餘操做: if cd mydir; then echo 'some content' >myfile else echo >&2 "Fatal error. This script requires mydir." fi # 判斷 variable(變量) 是否爲空 if [ ! -s "myvariable" ] #返回指定對象的長度 若是是 "字符串" 返回 0. # 判斷文件是否存在 if [ -e 'filename' ] then echo -e "file exists!" fi # 判斷 myfile 文件是否存在 或者 myfile 鏈接是否存在 if [ -e myfile ] || [ -L myfile ] then echo -e "file exists!" fi # 判斷 變量 x 是否大於 等於 5 if [ "$x" -ge 5 ]; then … # 在 bash/ksh/zsh 中 判斷 變量 x 是否大於等於 5,: if ((x >= 5)); then … # 使用 (( ))(雙括號) 進行數學運算 將u+2的計算結果賦值給 j if ((j==u+2)) # 使用 [[ ]](雙中括號) 進行數值比較 在[[]] 中 會將 特殊符號 自動轉換爲 比較符號 (例如 = 轉換爲 == ) if [[ $age -gt 21 ]]
for i in $(ls); do echo file $i;done #或者 for i in *; do echo file $i; done # 按任意鍵繼續執行遍歷 for i in $(cat tpc_stats_0925.log |grep failed|grep -o '\query\w\{1,2\}');do cat ${i}.log; read -rsp $'Press any key to continue...\n' -n1 key;done # 當按下一個鍵會逐行打印文件 oifs="$IFS"; IFS=$'\n'; for line in $(cat myfile); do ...; done while read -r line; do ...; done <myfile # If only one word a line, simply ( 遍歷文件內容 一行一行的遍歷) for line in $(cat myfile); do echo $line; read -n1; done #遍歷一個數組 for i in "${arrayName[@]}"; do echo $i;done
# 文件的列減法 (例如 a 3 columns file) while read a b c; do echo $(($c-$b));done < <(head filename) #在兩個 "<" 的中間有個空格 # 彙總 列 減法 i=0; while read a b c; do ((i+=$c-$b)); echo $i; done < <(head filename) # 繼續檢查正在運行的進程(例如perl),並在啓動後當即啓動另外一個新進程(例如python)。 (最好使用wait命令!Ctrl + F " wait") while [[ $(pidof perl) ]];do echo f;sleep 10;done && python timetorunpython.py
read type; case $type in '0') echo 'how' ;; '1') echo 'are' ;; '2') echo 'you' ;; esac
# foo=bar echo "'$foo'" #'bar' # 單引號/雙引號 quotes around single quotes make the inner single quotes expand variables(在單引號內使用變量 變量會被解析)
var="some string" echo ${#var} # 11
var=string echo "${var:0:1}" #s # or echo ${var%%"${var#?}"}
var="some string" echo ${var:2} #me string
var="0050" echo ${var[@]#0} #050
{var/a/,}
# 使用 grep test="god the father" grep ${test// /\\\|} file.txt # turning the space into 'or' (\|) in grep (在grep 的空間中將 替換 or 和 (\|) )
var=HelloWorld echo ${var,,} helloworld
cmd="bar=foo" eval "$cmd" echo "$bar" # foo
#總結: a++ 先運算a,後a的值加1;++a,則相反,先加一,再參與運算。同理a--,與--a echo $(( 10 + 5 )) #15 x=1 echo $(( x++ )) #1 , 注意它仍然是1,由於它是後遞增的 echo $(( x++ )) #2 echo $(( ++x )) #4 , 注意,它不是3,由於它是預增量 echo $(( x-- )) #4 echo $(( x-- )) #3 echo $(( --x )) #1 x=2 y=3 echo $(( x ** y )) #8
factor 50
seq 10|paste -sd+|bc
awk '{s+=$1} END {print s}' filename
cat file| awk -F '\t' 'BEGIN {SUM=0}{SUM+=$3-$2}END{print SUM}'
expr 10+20 #30 expr 10\*20 #600 expr 30 \> 20 #1 (true)
# 小數位數/有效數字 echo "scale=2;2/3" | bc #.66 # 指數運算符 echo "10^2" | bc #100 # 使用變量 echo "var=5;--var"| bc #4
time echo hi
sleep 10
TMOUT=10 # 一旦你設置了這個變量,註銷計時器開始運行!
# 僅僅運行 `sleep 10` 一秒。 timeout 1 sleep 10
at now + 1min # 時間單位能夠是 minutes, hours, days, 或 weeks ⚠️: 命令將使用 /bin/sh at> echo hihigithub >~/itworks at> <EOT> # 按 Ctrl + D 退出 job 1 at Wed Apr 18 11:16:00 2018
curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -f markdown -t man | man -l - # 或者 w3m (一種基於文本的瀏覽器和呼叫器) curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc | w3m -T text/html # 或者使用emacs (在emac文本編輯器中) emacs --eval '(org-mode)' --insert <(curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -t org) # 或者使用 emacs (在終端上先按Ctrl+x,再按Ctrl+c退出) emacs -nw --eval '(org-mode)' --insert <(curl https://raw.githubusercontent.com/onceupon/Bash-Oneliner/master/README.md | pandoc -t org)
wget -r -l1 -H -t1 -nd -N -np -A mp3 -e robots=off http://example.com # -r: recursive and download all links on page遞歸併下載頁面上全部連接 # -l1: only one level link僅一級連接 # -H: span host, visit other hosts跨越主機,訪問其餘主機 # -t1: numbers of retries重試次數 # -nd: don't make new directories, download to here不要建立新目錄,下載到這裏 # -N: turn on timestamp打開時間戳 # -nd: no parent沒有父級 # -A: type (separate by ,)類型(以,豆號分隔) # -e robots=off: ignore the robots.txt file which stop wget from crashing the site, sorry example.com忽略robots.txt文件,該文件阻止wget使網站崩潰,抱歉example.com
# 上傳文件 (例如: filename.txt): curl --upload-file ./filename.txt https://transfer.sh/filename.txt # 上面的命令將返回一個url,例如:https://transfer.sh/tG8rM/filename.txt # 接下來您能夠經過如下方式下載它: curl https://transfer.sh/tG8rM/filename.txt -o filename.txt
data=file.txt url=http://www.example.com/$data if [ ! -s $data ];then echo "downloading test data..." wget $url fi
wget -O filename "http://example.com"
wget -P /path/to/directory "http://example.com"
curl -L google.com
sudo apt install pwgen pwgen 13 5 #sahcahS9dah4a xieXaiJaey7xa UuMeo0ma7eic9 Ahpah9see3zai acerae7Huigh7
shuf -n 100 filename
for i in a b c d e; do echo $i; done| shuf
shuf -i 0-100 -n 15
echo $RANDOM
echo $((RANDOM % 10))
echo $(((RANDOM %10)+1))
X11 GUI 應用程序! 若是你對純文本的環境感到厭煩,這裏有一些適合你的 GUI 工具。
ssh -X user_name@ip_address # 或者經過 xhost 設置 # --> Install the following for Centos: # xorg-x11-xauth # xorg-x11-fonts-* # xorg-x11-utils
xclock xeyes xcowsay
1\. ssh -X user_name@ip_address 2. apt-get install eog 3. eog picture.png
1\. ssh -X user_name@ip_address 2. sudo apt install mpv 3. mpv myvideo.mp4
1\. ssh -X user_name@ip_address 2. apt-get install gedit 3. gedit filename.txt
1\. ssh -X user_name@ip_address 2. apt-get install evince 3. evince filename.pdf
1\. ssh -X user_name@ip_address 2. apt-get install libxss1 libappindicator1 libindicator7 3. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 4. sudo apt-get install -f 5. dpkg -i google-chrome*.deb 6. google-chrome
journalctl -u <service_name> -f
# 殭屍進程已經死了,因此你不能殺死它。您能夠消除經過殺死其父進程。 # 首先,找到殭屍進程的PID ps aux| grep 'Z' # 接下來發現殭屍的父進程的PID pstree -p -s <zombie_PID> # 而後你能夠殺死它的父進程,你會發現殭屍進程已經不見了。 sudo kill 9 <parent_PID>
free -c 10 -mhs 1 # 每隔1秒打印10次
#每秒刷新一次 iostat -x -t 1
iftop -i enp175s0f0
uptime
if [ "$EUID" -ne 0 ]; then echo "Please run this as root" exit 1 fi
chsh -s /bin/sh bonnie # /etc/shells: valid login shells
chroot /home/newroot /bin/bash # To exit chroot exit
stat filename.txt
ps aux
pstree
cat /proc/sys/kernel/pid_max
dmesg
$ip add show # or ifconfig
runlevel #或者 who -r
init 5 #或者 telinit 5
chkconfig --list # 至關於 ubntu 中 chkconfig 的 update-rc.d
cat /etc/*-release
man hier
# 檢查 cron 的狀態 systemctl status cron.service # 中止一個 cron 服務 systemctl stop cron.service
jobs -l
# 較好的值在 -20 (最有利)到 19 之間調整 # 應用程序越好,優先級越低 # 默認值:10 ,默認優先級:80 nice -10 ./test.sh
export PATH=$PATH:~/path/you/want
chmod +x filename # 如今你能夠執行 ./filename
uname -a # 檢查系統硬件平臺 (x86-64) uname -i
links www.google.com
useradd username passwd username
1\. joe ~/.bash_profile 2. export PS1='\u@\h:\w\$' # $PS1 是一個定義命令提示符外觀和樣式的變量 3\. source ~/.bash_profile
1\. joe ~/.bash_profile 2. alias pd="pwd" //no more need to type that 'w'! 3\. source ~/.bash_profile
alias -p
unalias ls
# 打印全部的 shell 選項 shopt # 取消(或者中止)別名 shopt -u expand_aliases # 設置(或者開始)別名 shopt -s expand_aliases
echo $PATH #用冒號分隔的目錄列表
env
unset MYVAR
lsblk
partprobe
ln -s /path/to/program /home/usr/bin # 必須是程序的絕對路徑
hexdump -C filename.class
rsh node_name
netstat -tulpn
readlink filename
type python # python 是 /usr/bin/python # 這裏有5中不一樣的類型,使用 'type -f' 標誌進行檢查 # 1\. alias (shell alias) # 2\. function (shell function, 也會打印函數主體) # 3\. builtin (shell builtin) # 4\. file (disk file) # 5\. keyword (shell reserved word) # 你也可使用 `which` which python # /usr/bin/python
declare -F
du -hs . # or du -sb
cp -rp /path/to/directory
pushd . # then pop popd #或着使用dirs顯示當前所在目錄的列表。 dirs -l
df -h # 或者 du -h #或者 du -sk /var/log/* |sort -rn |head -10
runlevel
init 3 #或者 telinit 3
1\. edit /etc/init/rc-sysinit.conf 2. env DEFAULT_RUNLEVEL=2
su
su somebody
repquota -auvs
getent database_name # (e.g. 'passwd' 數據庫) getent passwd # 列出全部用戶賬戶(全部本地賬戶和LDAP) # (e.g. 獲取用戶組列表) getent group # 在 'group' 數據庫保存
chown user_name filename chown -R user_name /path/to/directory/ # 改變用戶組名稱
# 例如 掛載 /dev/sdb 到 /home/test mount /dev/sdb /home/test # 例如 取消掛載 /home/test umount /home/test
mount # 或者 df
cat /etc/passwd
getent passwd| awk '{FS="[:]"; print $1}'
compgen -u
compgen -g
group username
id username
if [ $(id -u) -ne 0 ];then echo "You are not root!" exit; fi # 'id -u' output 0 if it's not root
more /proc/cpuinfo # 或者 lscpu
setquota username 120586240 125829120 0 0 /home
quota -v username
ldconfig -p
ldd /bin/ls
lastlog
joe /etc/environment #編輯這個文件
ulimit -u
nmap -sT -O localhost #notice that some companies might not like you using nmap
nproc --all
1\. top 2. press '1'
jobs -l
service --status-all
shutdown -r +5 "Server will restart in 5 minutes. Please save your work."
shutdown -c
wall -n hihi
pkill -U user_name
kill -9 $(ps aux | grep 'program_name' | awk '{print $2}')
# 你可能須要去安裝如下軟件: apt-get install libglib2.0-bin; # 或者 yum install dconf dconf-editor; yum install dbus dbus-x11; # 檢查列表 gsettings list-recursively # 修改一些設置 gsettings set org.gnome.gedit.preferences.editor highlight-current-line true gsettings set org.gnome.gedit.preferences.editor scheme 'cobalt' gsettings set org.gnome.gedit.preferences.editor use-default-font false gsettings set org.gnome.gedit.preferences.editor editor-font 'Cantarell Regular 12'
sudo gpasswd -a nice docker
1\. pip 安裝 --用戶 package_name 2. 你可能須要將 ~/.local/bin/ 導出到 PATH: export PATH=$PATH:~/.local/bin/
1\. uname -a #檢查當前內核,哪些是不能移除的 2\. sudo apt-get purge linux-image-X.X.X-X-generic #替代掉舊的版本
sudo hostname your-new-name #若是不起做用,也能夠: hostnamectl set-hostname your-new-hostname # 而後檢查: hostnamectl # 或者檢查 /etc/hostname # 若是一直不工做....,編輯: /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-ensxxx #增長 主機名="你的新主機名稱"
apt list --installed # 或者在 Red Hat: yum list installed
lsof /mnt/dir
killall pulseaudio # 而後按下 Alt-F2 並輸入 pulseaudio
killall pulseaudio
lsscsi
http://onceuponmine.blogspot....
http://onceuponmine.blogspot....
http://onceuponmine.blogspot....
telnet 192.168.2.106 53
ifconfig eth0 mtu 9000
pidof python # 或者 ps aux|grep python
# Start ntp: ntpd # 檢查 ntp: ntpq -p
sudo apt-get autoremove sudo apt-get clean sudo rm -rf ~/.cache/thumbnails/* # 刪除舊的內核 sudo dpkg --list 'linux-image*' sudo apt-get remove linux-image-OLDER_VERSION
pvscan lvextend -L +130G /dev/rhel/root -r # 添加 -r 將在調整卷大小後增長到文件系統
sudo dd if=~/path/to/isofile.iso of=/dev/sdc1 oflag=direct bs=1048576
sudo dpkg -l | grep <package_name> sudo dpkg --purge <package_name>
ssh -f -L 9000:targetservername:8088 root@192.168.14.72 -N #-f: 在後臺運行; -L: 監聽; -N: 什麼也不作 # 你計算機的9000端口如今已經鏈接上了目標服務器名字192.168.14.72的8088端口 # 因此你如今能夠去打開瀏覽器輸入localhost:9000去查看你的目標計算機的8088端口了
#pidof 獲取進程id pidof sublime_text #pgrep, 你沒必要鍵入整個程序名 pgrep sublim #pgrep, 若是找到進程,則返回1;若是沒有此類進程,則返回0 pgrep -q sublime_text && echo 1 || echo 0 #top, 須要更長的時間 top|grep sublime_text
aio-stress - AIO benchmark. bandwidth - memory bandwidth benchmark. bonnie++ - hard drive and file system performance benchmark. dbench - generate I/O workloads to either a filesystem or to a networked CIFS or NFS server. dnsperf - authorative and recursing DNS servers. filebench - model based file system workload generator. fio - I/O benchmark. fs_mark - synchronous/async file creation benchmark. httperf - measure web server performance. interbench - linux interactivity benchmark. ioblazer - multi-platform storage stack micro-benchmark. iozone - filesystem benchmark. iperf3 - measure TCP/UDP/SCTP performance. kcbench - kernel compile benchmark, compiles a kernel and measures the time it takes. lmbench - Suite of simple, portable benchmarks. netperf - measure network performance, test unidirectional throughput, and end-to-end latency. netpipe - network protocol independent performance evaluator. nfsometer - NFS performance framework. nuttcp - measure network performance. phoronix-test-suite - comprehensive automated testing and benchmarking platform. seeker - portable disk seek benchmark. siege - http load tester and benchmark. sockperf - network benchmarking utility over socket API. spew - measures I/O performance and/or generates I/O load. stress - workload generator for POSIX systems. sysbench - scriptable database and system performance benchmark. tiobench - threaded IO benchmark. unixbench - the original BYTE UNIX benchmark suite, provide a basic indicator of the performance of a Unix-like system. wrk - HTTP benchmark.
lastb
who
w
users
tail -f --pid=<PID> filename.txt # 用程序的進程 ID 替換 <PID>
systemctl list-unit-files|grep enabled
lshw -json >report.json # 其餘的選項: [ -html ] [ -short ] [ -xml ] [ -json ] [ -businfo ] [ -sanitize ] ,etc
sudo dmidecode -t memory
dmidecode -t 4 # 類型 信息 # 0 BIOS # 1 系統 # 2 基板 # 3 機殼 # 4 處理器 # 5 內存控制器 # 6 內存模塊 # 7 緩存 # 8 端口鏈接器 # 9 系統槽 # 11 OEM 字符串 # 13 BIOS 語言 # 15 系統事件日誌 # 16 物理內存數組 # 17 存儲設備 # 18 32位內存錯誤 # 19 存儲映射地址 # 20 存儲設備映射地址 # 21 內置定位設備 # 22 便攜式電池 # 23 系統重置 # 24 硬件安全性 # 25 系統電源控制 # 26 電壓探頭 # 27 冷卻裝置 # 28 溫度探測器 # 29 電流探頭 # 30 待外遠程訪問 # 31 引導完整性服務 # 32 系統啓動 # 34 管理裝置 # 35 管理設備組件 # 36 管理設備閾值數據 # 37 內存通道 # 38 IPMI 設備 # 39 電力供應
lsscsi|grep SEAGATE|wc -l # 或者 sg_map -i -x|grep SEAGATE|wc -l
blkid /dev/sdb
lsblk -io KNAME,TYPE,MODEL,VENDOR,SIZE,ROTA #其中 ROTA 表示旋轉設備/旋轉硬盤 (1 爲真, 0 爲假)
lspci # 列出關於 NIC 信息 lspci | egrep -i --color 'network|ethernet'
lsusb
# 顯示 Linux 內核中模塊狀態 lsmod # 從 Linux 內核中增長或者移除模塊 modprobe # 或者 # Remove a module rmmod # 插入模塊 insmod
# 遠程查看服務器的電源狀態 ipmitool -U <bmc_username> -P <bmc_password> -I lanplus -H <bmc_ip_address> power status # 遠程開啓服務器 ipmitool -U <bmc_username> -P <bmc_password> -I lanplus -H <bmc_ip_address> power on # 打開面板識別燈(默認 15秒) ipmitool chassis identify 255 #或者服務器傳感器溫度 ipmitool sensors |grep -i Temp # 重置 BMC ipmitool bmc reset cold # Prnt BMC 網絡 ipmitool lan print 1 # 設置 BMC 網絡 ipmitool -I bmc lan set 1 ipaddr 192.168.0.55 ipmitool -I bmc lan set 1 netmask 255.255.255.0 ipmitool -I bmc lan set 1 defgw ipaddr 192.168.0.1
ip a
ip r
ip n
ip address add 192.168.140.3/24 dev eno16777736
sudo vi /etc/sysconfig/network-scripts/ifcfg-enoxxx # 而後編輯字段: BOOTPROT, DEVICE, IPADDR, NETMASK, GATEWAY, DNS1 etc
sudo nmcli c reload
sudo systemctl restart network.service
hostnamectl
hostnamectl set-hostname "mynode"
完成 -W "now tomorrow never" dothis # ~$ dothis # 從不 如今 明天 # 輸入「n」或者「t」以後,再次按「tab」 鍵以自動完成
printf 'hello world\n%.0s' {1..5}
echo test|base64 #dGVzdAo=
username=`echo -n "bashoneliner"`
dirname `pwd`
tee <fileA fileB fileC fileD >/dev/null
tr --delete '\n' <input.txt >output.txt
tr '\n' ' ' <filename
tr /a-z/ /A-Z/
echo 'something' |tr a-z a # aaaaaaaaa
diff fileA fileB # a: 被增長; d:刪除; c:被修改 # 或者 sdiff fileA fileB # 文件差別的並排合併
diff fileA fileB --strip-trailing-cr
nl fileA #或者 nl -nrz fileA # add leading zeros #也能夠 nl -w1 -s ' ' # making it simple, blank separate
# 文件 A 和文件 B 應該有相同的行順序 join -t '\t' fileA fileB # 使用指定字段加入 (例如 文件 A 的第三列和文件 B 的第五列) join -1 3 -2 5 fileA fileB
paste fileA fileB fileC # 默認選項分開
echo 12345| rev
zmore filename # 或者 zless filename
some_commands &>log & # 或者 some_commands 2>log & # 或者 some_commands 2>&1| tee logfile # 或者 some_commands |& tee logfile # 還能夠 some_commands 2>&1 >>outfile #0: 標準輸入; 1: 標準輸出; 2: 標準錯誤
# 按順序運行 (sleep 2; sleep 3) & #並行運行 sleep 2 & sleep 3 &
# 例如即使註銷也會運行 myscript.sh 腳本 nohup bash myscript.sh
下面是郵件的內容 -a /path/to/attach_file.txt -s 'mail.subject' me@gmail.com # use -a flag to set send from (-a "From: some@mail.tld")
xls2csv filename
echo 'hihi' >>filename
speaker-test -t sine -f 1000 -l1
(speaker-test -t sine -f 1000) & pid=$!;sleep 0.1s;kill -9 $pid
~/.bash_history #或者 history -d [line_number]
# list 5 previous command (similar to `history |tail -n 5` but wont print the history command itself) fc -l -5
head !$
clear # 或者 Ctrl+l
cat /directory/to/file echo 100>!$
unxz filename.tar.xz # 而後 tar -xf filename.tar
pip install packagename
Ctrl+U # 或者 Ctrl+C # 或者 Alt+Shift+# # 成爲歷史
# addmetodistory # just add a "#" before~~
sleep 5;echo hi
rsync -av filename filename.bak rsync -av directory directory.bak rsync -av --ignore_existing directory/ directory.bak rsync -av --update directory directory.bak rsync -av directory user@ip_address:/path/to/directory.bak #跳過接收器上更新的文件 (我更喜歡這個!)
mkdir -p project/{lib/ext,bin,src,doc/{html,info,pdf},demo/stat} # -p: 設置爲父目錄 # 這將製造 project/doc/html/; project/doc/info; project/lib/ext ,etc
cd tmp/ && tar xvf ~/a.tar
cd tmp/a/b/c ||mkdir -p tmp/a/b/c
tar xvf -C /path/to/directory filename.gz
cd tmp/a/b/c \ > || \ >mkdir -p tmp/a/b/c
VAR=$PWD; cd ~; tar xvf -C $VAR file.tar # PWD 必須是大寫字母
file /tmp/ # tmp/: directory
#!/bin/bash file=${1#*.} # remove string before a "."
python -m SimpleHTTPServer # 或者你使用 python3 的時候: python3 -m http.server
read input echo $input
seq 10
i=`wc -l filename|cut -d ' ' -f1`; cat filename| echo "scale=2;(`paste -sd+`)/"$i|bc
echo {1,2}{1,2} # 1 1, 1 2, 2 1, 2 2
set = {A,T,C,G} group= 5 for ((i=0; i<$group; i++));do repetition=$set$repetition;done bash -c "echo "$repetition""
foo=$(<test1)
echo ${#foo}
echo -e ' \t '
declare -a array=() # 或者 declare array=() # 或者關聯數組 declare -A array=()
scp -r directoryname user@ip:/path/to/send
# 按行分割 (e.g. 1000 lines/smallfile) split -d -l 1000 largefile.txt # 按字節分割而不會在文件間斷行 split -C 10 largefile.txt
#1\. 建立文件 dd if=/dev/zero of=bigfile bs=1 count=1000000 #2\. 將大文件拆分爲100000個10字節文件 split -b 10 -a 10 bigfile
rename 's/ABC//' *.gz
basename filename.gz .gz zcat filename.gz> $(basename filename.gz .gz).unpacked
# 不要在家嘗試這個 # 它是一個每次調用都會調用兩次的函數,直到系統資源耗盡爲止 # 爲了安全起見在前面加了一個 #,當你真正測試的時候,請移除它 # :(){:|:&};:
rename s/$/.txt/ * # 你可使用重命名 -n s/$/.txt/ * 首先去檢查結果,若是它僅僅打印這些: # rename(a, a.txt) # rename(b, b.txt) # rename(c, c.txt)
tr -s "/t" < filename
echo -e 'text here \c'
!$
echo $?
head -c 50 file
# 例如 # AAAA # BBBB # CCCC # DDDD cat filename|paste - - # AAAABBBB # CCCCDDDD cat filename|paste - - - - # AAAABBBBCCCCDDDD
cat file.fastq | paste - - - - | sed 's/^@/>/g'| cut -f1-2 | tr '\t' '\n' >file.fa
cat file|rev | cut -d/ -f1 | rev
((var++)) # 或者 var=$((var+1))
>filename
tar xvfj file.tar.bz2
unxz file.tar.xz tar xopf file.tar
# 'y': yes # 或者 'n': yes n # 或者 'anything': yes anything # 例如:
yes | rm -r large_directory
##### [](https://github.com/onceupon/Bash-OneLiner#create-dummy-file-of-certain-size-instantly-eg-200mb) ##### 當即建立必定大小的虛擬文件 (例如 200mb)
dd if=/dev/zero of=//dev/shm/200m bs=1024k count=200
dd if=/dev/zero of=//dev/shm/200m bs=1M count=200
##### [](https://github.com/onceupon/Bash-OneLiner#cat-to-a-file)把文件歸檔
cat >myfile
讓我在這補充一下
exit by control + c
^C
##### [](https://github.com/onceupon/Bash-OneLiner#keep-repeatedly-executing-the-same-command-eg-repeat-wc--l-filename-every-1-second)保持重複執行同一個命令 (例如 每一秒重複一次 'wc -l filename' )
watch -n 1 wc -l filename
##### [](https://github.com/onceupon/Bash-OneLiner#print-commands-and-their-arguments-when-execute-eg-echo-expr-10--20-)執行時打印命令以及其參數(例如 echo `expr 10 + 20 `)
set -x; echo expr 10 + 20
##### [](https://github.com/onceupon/Bash-OneLiner#print-some-meaningful-sentences-to-you-install-fortune-first)爲你打印一些有意義的句子(首先安裝 fortune )
fortune
##### [](https://github.com/onceupon/Bash-OneLiner#colorful-and-useful-version-of-top-install-htop-first)豐富多彩的 (有用的) top 版本(首先安裝 htop)
htop
##### [](https://github.com/onceupon/Bash-OneLiner#press-any-key-to-continue)按任意鍵繼續
read -rsp $'Press any key to continue...n' -n1 key
##### [](https://github.com/onceupon/Bash-OneLiner#run-sql-like-command-on-files-from-terminal)從終端中運行相似 sql 的命令
q -d "," "select c3,c4,c5 from /path/to/file.txt where c3='foo' and c5='boo'"
##### [](https://github.com/onceupon/Bash-OneLiner#using-screen-for-multiple-terminal-sessions)將 Screen 用於多個終端回話
screen
screen -S foo -d -m
screen: ^a^d
screen -ls
screen -r
screen -r foo
screen -r foo -X quit
點擊屏幕前綴組合 (C-a / control+A),而後按下 Escape.
上下移動方向鍵(↑ and ↓).
(C-a / control+A), then hit 'H'
Ctrl+A, Shift+H
##### [](https://github.com/onceupon/Bash-OneLiner#using-tmux-for-multiple-terminal-sessions)使用 ##### 將 Tmux用於多個終端回話
tmux
tmux attach -t foo
^bd
tmux ls
tmux attach
tmux kill-session -t foo
tmux new -s foo -d
Ctrl-B
:setw synchronize-panes
Ctrl-B
select-layout even-vertical
Ctrl+b, Alt+2
select-layout even-horizontal
Ctrl+b, Alt+1
Ctrl-b 而後 [ 而後你可使用你的正常方向鍵來滾動
Press q to quit scroll mode.
##### [](https://github.com/onceupon/Bash-OneLiner#cut-the-last-column)剪切最後一行
cat filename|rev|cut -f1|rev
##### [](https://github.com/onceupon/Bash-OneLiner#pass-password-to-ssh)將密碼傳輸給 ssh
sshpass -p mypassword ssh root@10.102.14.88 "df -h"
##### [](https://github.com/onceupon/Bash-OneLiner#wait-for-a-pid-job-to-complete)等待一個 pid (任務)完成
wait %1
wait $PID
wait ${!}
##### [](https://github.com/onceupon/Bash-OneLiner#convert-pdf-to-txt)將 pdf 轉換爲 txt
sudo apt-get install poppler-utils
pdftotext example.pdf example.txt
##### [](https://github.com/onceupon/Bash-OneLiner#list-only-directory)只列出目錄
ls -ld -- */
##### [](https://github.com/onceupon/Bash-OneLiner#capturerecordsave-terminal-output-capture-everything-you-type-and-output)捕獲/j記錄/保存終端輸出(捕獲你輸入和輸出的全部內容)
script output.txt
##### 以樹狀格式列出目錄的內容。
tree
tree -L 1
##### [](https://github.com/onceupon/Bash-OneLiner#set-up-virtualenvsandbox-for-python)爲 Python設置 virtualenv(sandbox)
sudo apt-get install virtualenv
virtualenv .venv
source .venv/bin/activate
type pip
pip install -r requirements.txt
##### [](https://github.com/onceupon/Bash-OneLiner#working-with-json-data)使用 json 數據
jq '.url'
##### [](https://github.com/onceupon/Bash-OneLiner#editing-your-history)編輯 history
history -w
vi ~/.bash_history
history -r
##### [](https://github.com/onceupon/Bash-OneLiner#decimal-to-binary-eg-get-binary-of-5)十進制轉換爲二進制(例如,獲取 5 的二進制 )
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1}{0..1})
echo -e ${D2B[5]}
echo -e ${D2B[255]}
##### [](https://github.com/onceupon/Bash-OneLiner#wrap-each-input-line-to-fit-in-specified-width-eg-4-integers-per-line)把輸入的行換行以適應指定的寬度(例如每行 4 個整數)
echo "00110010101110001101" | fold -w4
##### [](https://github.com/onceupon/Bash-OneLiner#sort-a-file-by-column-and-keep-the-original-order)按列對文件進行排序,並保持原始順序
sort -k3,3 -s
##### [](https://github.com/onceupon/Bash-OneLiner#right-align-a-column-right-align-the-2nd-column)列右對齊(第二列右對齊)
cat file.txt|rev|column -t|rev
##### [](https://github.com/onceupon/Bash-OneLiner#to-both-view-and-store-the-output)查看和存儲輸出
echo 'hihihihi' | tee outputfile.txt
##### [](https://github.com/onceupon/Bash-OneLiner#show-non-printing-ctrl-characters-with-cat)使用 cat 顯示非打印(Ctrl)字符
cat -v filename
##### [](https://github.com/onceupon/Bash-OneLiner#convert-tab-to-space)將製表符轉換爲空格
expand filename
##### [](https://github.com/onceupon/Bash-OneLiner#convert-space-to-tab)將空格轉換爲製表符
unexpand filename
##### [](https://github.com/onceupon/Bash-OneLiner#display-file-in-octal--you-can-also-use-od-to-display-hexadecimal-decimal-etc)以八進制顯示文件(您也可使用 od 顯示十六進制,十進制等)
od filename
##### [](https://github.com/onceupon/Bash-OneLiner#reverse-cat-a-file)反轉 `cat` 的結果
tac filename
##### [](https://github.com/onceupon/Bash-OneLiner#reverse-the-result-from-uniq--c)反轉 `uniq -c` 的結果
while read a b; do yes $b |head -n $a ;done <test.txt
> 將來還有更多!