日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

Linux shell tips and tricks

發布時間:2025/3/15 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux shell tips and tricks 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

I’m using Linux shell (Bash) on daily basis, but I often forgot some useful command or shell tip. Yes, I can remember commands, but I can’t say that if I used it just once for specific task. Then I started to write Linux shell tips in text file on my Dropbox account and now I decided to share that. This list will be updated over time. Also keep in mind that for some tips you will need to install additional software on your Linux distribution.

UPDATE: November 25, 2013

Check if remote port is open with bash:

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

Suspend process:

Ctrl + z

Move process to foreground:

fg

Generate random hex number where n is number of characters:

openssl rand -hex n

Execute commands from a file in the current shell:

source /home/user/file.name

Substring for first 5 characters:

${variable:0:5}

SSH debug mode:

ssh -vvv user@ip_address

SSH with pem key:

ssh user@ip_address -i key.pem

Get complete directory listing to local directory with wget:

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

Create multiple directories:

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

List processes tree with child processes:

ps axwef

Create war file:

jar -cvf name.war file

Test disk write speed:

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

Test disk read speed:

hdparm -Tt /dev/sda

Get md5 hash from text:

echo -n "text" | md5sum

Check xml syntax:

xmllint --noout file.xml

Extract tar.gz in new directory:

tar zxvf package.tar.gz -C new_dir

Get HTTP headers with curl:

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

Modify timestamp of some file or directory (YYMMDDhhmm):

touch -t 0712250000 file

Download from ftp using wget:

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

Generate random password (16 char long in this case):

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

Quickly create a backup of a file:

cp some_file_name{,.bkp}

Access Windows share:

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

Run command from history (here at line 100):

!100

Unzip to directory:

unzip package_name.zip -d dir_name

Multiline text (CTRL + d to exit):

cat > test.txt

Create empty file or empty existing one:

> test.txt

Update date from Ubuntu NTP server:

ntpdate ntp.ubuntu.com

netstat show all tcp4 listening ports:

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

Convert image from qcow2 to raw:

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

Run command repeatedly, displaying it's output (default every two seconds):

watch ps -ef

List all users:

getent passwd

Mount root in read/write mode:

mount -o remount,rw /

Mount a directory (for cases when symlinking will not work):

mount --bind /source /destination

Send dynamic update to DNS server:

nsupdate < <EOF update add $HOST 86400 A $IP send EOF

Recursively grep all directories:

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

List ten largest open files:

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

Show free RAM in MB:

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

Open Vim and jump to end of file:

vim + some_file_name

Git clone specific branch (master):

git clone git@github.com:name/app.git -b master

Git switch to another branch (develop):

git checkout develop

Git delete branch (myfeature):

git branch -d myfeature

Git delete remote branch:

git push origin :branchName

Git push new branch to remote:

git push -u origin mynewfeature

Print out the last cat command from history:

!cat:p

Run your last cat command from history:

!cat

Find all empty subdirectories in /home/user:

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

Get all from line 50 to 60 in test.txt:

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

Run last command (if it was: mkdir /root/test, below will run: sudo mkdir /root/test):

sudo !!

Create temporary RAM filesystem - ramdisk (first create /tmpram directory):

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

Grep whole words:

grep -w "name" test.txt

Append text to a file that requires raised privileges:

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

List all supported kill signals:

kill -l

Generate random password (16 characters long in this case):

openssl rand -base64 16

Do not log last session in bash history:

kill -9 $$

Scan network to find open port:

nmap -p 8081 172.20.0.0/16

Set git email:

git config --global user.email "me@example.com"

To sync with master if you have unpublished commits:

git pull --rebase origin master

Move all files with "txt" in name to /home/user:

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

Put the file lines side by side:

paste test.txt test1.txt

Progress bar in shell:

pv data.log

Send the data to server with netcat:

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

Convert tabs to spaces:

expand test.txt > test1.txt

Skip bash history:

< <space>>cmd

Go to the previous working directory:

cd -

Split large tar.gz archive (100MB each) and put it back:

split b 100m /path/to/large/archive /path/to/output/files cat files* > archive

Get HTTP status code with curl:

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

When Ctrl + c not works:

Ctrl + \

Get file owner:

stat -c %U file.txt

List block devices:

lsblk -f

Find files with trailing spaces:

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

Find files with tabs indentation:

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

Print horizontal line with "=":

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

UPDATE: November 25, 2013

轉載于:https://my.oschina.net/zungyiu/blog/180664

總結

以上是生活随笔為你收集整理的Linux shell tips and tricks的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 奇米网久久 | 日本一区二区三区中文字幕 | 午夜影院在线免费观看 | 韩国一区二区在线播放 | 国产免费a级片 | 视频1区2区| 日韩av中文 | 91精品国产色综合久久不卡电影 | 国产一级二级毛片 | 久草超碰在线 | 秋霞视频在线观看 | 欧美日韩亚洲在线观看 | 日韩欧美三区 | 色婷婷视频在线 | 精品人体无码一区二区三区 | 在线看毛片网站 | 高潮一区 | 精品国产乱码久久久久久88av | 国产顶级毛片 | 亚洲va在线 | 玖玖在线 | 国产精品女主播 | 成人性做爰片免费视频 | 黄色一级小说 | 欧美综合自拍亚洲综合图片区 | 蜜桃久久av一区 | 久久视奸 | 国产一区二区三区四区五区六区 | 成人黄色大片 | 国产日韩激情 | 久久蜜桃av一区二区天堂 | 日韩精品在线观看一区 | 国产三级按摩推拿按摩 | 免费看黄色漫画 | 一区二区亚洲视频 | 欧美成人91 | 亚洲素人 | 精品视频免费在线观看 | 青娱乐福利视频 | 做爰视频毛片视频 | 成年人免费小视频 | 日韩偷拍一区 | 欧美激情五月 | 国产精品人人爽人人爽 | 欧美69精品久久久久久不卡 | 看av在线 | 成人国产欧美 | 欧美体内谢she精2性欧美 | 91大奶| 精品产国自在拍 | www.在线观看麻豆 | 原创露脸88av | 极品销魂美女一区二区三区 | 国产国语videosex另类 | 毛片女人 | 2021国产精品视频 | 亚洲在线观看视频 | 中文字幕无码毛片免费看 | 免费观看美女裸体网站 | 国语对白做受欧美 | 国产乱叫456在线 | 国产福利免费观看 | 天堂а在线中文在线新版 | 奇米色在线 | 中文字幕在线视频网 | 黄色av中文字幕 | 乳女教师の诱惑julia | 在线免费观看h片 | 精品国产福利 | 在线视频免费观看一区 | 久色资源 | 日韩在线免费视频 | www日本免费| 亚洲午夜精品一区二区三区他趣 | www.伊人久久 | 草草视频网站 | 成人精品免费视频 | 成人免费xxxxxx视频 | 精品久久免费视频 | 国产一线在线观看 | 99久久视频| 无码久久精品国产亚洲av影片 | 久章操| www一级片 | 一级全黄毛片 | 玉女心经是什么意思 | 欧美日韩一区二区在线视频 | 欧美整片第一页 | 久久国产欧美日韩精品 | 一区二区三区视频免费在线观看 | 中文写幕一区二区三区免费观成熟 | 欧美成年人在线视频 | avtt在线| 亚洲xx网站 | 播放灌醉水嫩大学生国内精品 | 亚洲一区二区观看 | 视频一区二区三区四区五区 | 国产伦精品一区二区三区照片91 | 色综合av在线 |