好男人视频社区,久久99国产精品尤物,大宫凉香电影,国外巨g乳熟妇av无码,天天日天天舔天天操,久久综合久色综合97婷婷,99久久久成人国产精品 ,4438亚洲最大色情网

Linux shell 常用【轉(zhuǎn)載】

/ 2評 / 0贊

使用Linux shell是我每天的基本工作,但我經(jīng)常會忘記一些有用的shell命令和l技巧。當(dāng)然,命令我能記住,但我不敢說能記得如何用它執(zhí)行某個特定任務(wù)。于是,我開始在一個文本文件里記錄這些用法,并放在我的Dropbox里,現(xiàn)在,向大家分享這個文件。這個文件我會不斷的更新。需要注意一點的是,有些用法需要在你的Linux系統(tǒng)里安裝額外的軟件。

UPDATE: November 25, 2013

檢查遠程端口是否對bash開放:

 

echo?>/dev/tcp/8.8.8.8/53?&&?echo?"open"

讓進程轉(zhuǎn)入后臺:

 

Ctrl + z

將進程轉(zhuǎn)到前臺:

fg

產(chǎn)生隨機的十六進制數(shù),其中n是字符數(shù):

 

openssl rand -hex n

在當(dāng)前shell里執(zhí)行一個文件里的命令:

 

source?/home/user/file.name

截取前5個字符:

 

${variable:0:5}

SSH debug 模式:

 

ssh?-vvv user@ip_address

SSH with pem key:

 

ssh?user@ip_address -i key.pem

用wget抓取完整的網(wǎng)站目錄結(jié)構(gòu),存放到本地目錄中:

 

wget -r --no-parent --reject?"index.html*"?http://hostname/?-P?/home/user/dirs

一次創(chuàng)建多個目錄:

 

mkdir?-p?/home/user/{test,test1,test2}

列出包括子進程的進程樹:

 

ps?axwef

創(chuàng)建 war 文件:

 

jar -cvf name.war?file

測試硬盤寫入速度:

 

dd?if=/dev/zero?of=/tmp/output.img bs=8k count=256k;?rm?-rf?/tmp/output.img

測試硬盤讀取速度:

 

hdparm -Tt?/dev/sda

獲取文本的md5 hash:

 

echo?-n?"text"?| md5sum

檢查xml格式:

 

xmllint --noout?file.xml

將tar.gz提取到新目錄里:

 

tar?zxvf package.tar.gz -C new_dir

使用curl獲取HTTP頭信息:

 

curl -I http://www.example.com

修改文件或目錄的時間戳(YYMMDDhhmm):

 

touch?-t 0712250000?file

用wget命令執(zhí)行ftp下載:

 

wget -m ftp://username:password@hostname

生成隨機密碼(例子里是16個字符長):

 

LANG=c <?/dev/urandom?tr?-dc?_A-Z-a-z-0-9 |?head?-c${1:-16};echo;

快速備份一個文件:

 

cp?some_file_name{,.bkp}

訪問Windows共享目錄:

 

smbclient -U?"DOMAIN\user"?//dc.domain.com/share/test/dir

執(zhí)行歷史記錄里的命令(這里是第100行):

 

!100

解壓:

 

unzip package_name.zip -d dir_name

輸入多行文字(CTRL + d 退出):

 

cat?>?test.txt

創(chuàng)建空文件或清空一個現(xiàn)有文件:

 

> test.txt

與Ubuntu NTP server同步時間:

 

ntpdate ntp.ubuntu.com

用netstat顯示所有tcp4監(jiān)聽端口:

 

netstat?-lnt4 |?awk?'{print $4}'?|?cut?-f2 -d: |?grep?-o?'[0-9]*'

qcow2鏡像文件轉(zhuǎn)換:

qemu-img convert -f qcow2 -O raw precise-server-cloudimg-amd64-disk1.img \

precise-server-cloudimg-amd64-disk1.raw

重復(fù)運行文件,顯示其輸出(缺省是2秒一次):

 

watch?ps?-ef

所有用戶列表:

 

getent?passwd

Mount root in read/write mode:

 

mount?-o remount,rw /

掛載一個目錄(這是不能使用鏈接的情況):

 

mount?--bind?/source?/destination

動態(tài)更新DNS server:

 

 

nsupdate < <EOF

update add $HOST 86400 A $IP

send

EOF

遞歸grep所有目錄:

 

grep?-r?"some_text"?/path/to/dir

列出前10個最大的文件:

 

lsof?/ |?awk?'{ if($7 > 1048576) print $7/1048576 "MB "$9 }'?|?sort?-n -u |?tail

顯示剩余內(nèi)存(MB):

 

free?-m |?grep?cache |?awk?'/[0-9]/{ print $4" MB" }'

打開Vim并跳到文件末:

 

vim + some_file_name

Git 克隆指定分支(master):

 

git clone [email protected]:name/app.git -b master

Git 切換到其它分支(develop):

 

git checkout develop

Git 刪除分支(myfeature):

 

git branch -d myfeature

Git 刪除遠程分支:

 

git push origin :branchName

Git 將新分支推送到遠程服務(wù)器:

 

git push -u origin mynewfeature

打印歷史記錄中最后一次cat命令:

 

!cat:p

運行歷史記錄里最后一次cat命令:

 

!cat

找出/home/user下所有空子目錄:

 

find /home/user -maxdepth?1?-type d -empty

獲取test.txt文件中第50-60行內(nèi)容:

 

< test.txt sed -n?'50,60p'

運行最后一個命令(如果最后一個命令是mkdir /root/test, 下面將會運行: sudo mkdir /root/test):

 

sudo !!

創(chuàng)建臨時RAM文件系統(tǒng) – ramdisk (先創(chuàng)建/tmpram目錄):

 

mount?-t tmpfs tmpfs?/tmpram?-o size=512m

Grep whole words:

 

grep -w?"name"?test.txt

在需要提升權(quán)限的情況下往一個文件里追加文本:

 

echo?"some text"?| sudo tee -a /path/file

列出所有kill signal參數(shù):

 

kill -l

在bash歷史記錄里禁止記錄最后一次會話:

 

kill?-9 $$

掃描網(wǎng)絡(luò)尋找開放的端口:

 

nmap -p 8081 172.20.0.0/16

設(shè)置git email:

 

git config --global user.email?"[email protected]"

To sync with master if you have unpublished commits:

 

git pull --rebase origin master

將所有文件名中含有”txt”的文件移入/home/user目錄:

 

find -iname?"*txt*"?-exec mv -v {} /home/user \;

將文件按行并列顯示:

 

paste?test.txt test1.txt

shell里的進度條:

 

pv data.log

使用netcat將數(shù)據(jù)發(fā)送到Graphite server:

 

echo?"hosts.sampleHost 10 `date +%s`"?| nc?192.168.200.2?3000

將tabs轉(zhuǎn)換成空格:

 

expand?test.txt > test1.txt

Skip bash history:

 

< space >cmd

去之前的工作目錄:

 

cd -

拆分大體積的tar.gz文件(每個100MB),然后合并回去:

 

 

split?–b 100m?/path/to/large/archive?/path/to/output/files

cat?files* > archive

使用curl獲取HTTP status code:

 

curl -sL -w?"%{http_code}\\n"?www.example.com -o?/dev/null

設(shè)置root密碼,強化MySQL安全安裝:

 

/usr/bin/mysql_secure_installation

當(dāng)Ctrl + c不好使時:

 

Ctrl + \

獲取文件owner:

 

stat -c %U?file.txt

block設(shè)備列表:

 

lsblk -f

找出文件名結(jié)尾有空格的文件:

 

find . -type f -exec egrep -l?" +$"?{} \;

找出文件名有tab縮進符的文件:

 

find?. -type?f -exec?egrep?-l $'\t'?{} \;

用”=”打印出橫線:

 

printf?'%100s\n'?|?tr?' '?=

建偉

  1. 這文章看的有那么點蛋疼。

  2. 這文章看的有那么點蛋疼。

發(fā)表評論

您的電子郵箱地址不會被公開。

這個站點使用 Akismet 來減少垃圾評論。了解你的評論數(shù)據(jù)如何被處理。