Linux Command Miscellaneous
常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
$command 3>&1 1>&2 2>&3 交换stdout和 stderr
cat -n file or cat -b file
cp --backup=t source.file target.file
find -printf "%C@ %p\n"|sort
find . -print -exec chmod 777 {} \; $command 3>&1 1>&2 2>&3 交换stdout和 stderr lshw -C display
lsusb -d 产品ID -v lsusb -s devnum -v
find -type l -xtype d
find /path/to/dir -type f | grep -o '\.[^./]*$' | sort | uniq
du -h /path | sort -h
du -d /path
free -m | awk '/cache:/ { printf("%d%\n",$3/($3+$4)*100)}' 空闲内存百分比
pgrep -f 'process.*argument.*'
ps -p $$
ps auxf
find . -name 'pattern'| xargs du -hc
find . -mtime +30 -exec mv {} old/ \;
find . -name "*.cpp" |xargs cat|wc -l
find . -name "*.cpp"|xargs cat|grep -v ^$|wc -l
find . -type f -name '*.pm' -printf '%6s %p\n' | sort -nr | head -n 50
find -iname \*.pdf -print0 | xargs -0 pdfgrep -i "my search text"
pwdx pid
ps -ef | grep [f]oo | awk '{print $2}' | xargs kill -9
du -sm /home/* | sort -n | tail -10
ls -1 | rename 's/\ /_/'
find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
sed '/^ #.*DEBUG.*/ s/^# //' $FILE
pv file1 > file2
rename -v 's/ /_/g' *
vim -c new myfile
rm **/*(-@)
function garg () { tail -n 1 ${HISTFILE} | awk "{ print \$$1 }" }
|
监控
1 2 3 4 5 6 7 8 9 10 11 12
| top -b -d 1 | sed 's/^/varName schoolId/' | awk '{print $1,$2,$3,$4,$11,$12,systime(),$14}' | grep --line-buffered firefox
tcpdump -w - |pv -bert >/dev/null
ps axu | grep [a]pache2
ifconfig -a| grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'
PID=httpd ; ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
myLongScript && echo -e '\a' || (echo -e '\a'; sleep 1; echo -e '\a')
|
awk
1 2 3 4 5
| awk -F '|' '{print "|"$2"|" "["$3"]("$5")|"$4"|"}' filename
awk 'gsub(/^ *| *$/,"")' filename
|
##关闭地址空间随机化(ASLR)
1
| echo 0 > /proc/sys/kernel/randomize_va_space
|
curl
1 2
| curl -I http://localhost curl url | egrep -o '(http|https)://[a-z0-9]*\.[a-z0-9]*\.[a-z0-9]*'|sort |uniq
|
curl–模拟post登陆
1 2 3
| ACCOUNT=xxx PASS=xxx curl -d "username=$ACCOUNT&password=$PASS" http://p.nju.edu.cn/portal_io/login
|
1 2 3 4 5 6 7 8 9 10 11
| mmv "*.txt" "#1.md" 批重命名文件夹下的所有文件的拓展名,比如把txt文件重命名为md文件
convert example.png -resize 100x100! output.png 缩放图片
ffmpeg -i initial.mkv -acodec libvorbis -ab 128k -ac 2 -vcodec libx264 -vpre max -crf 22 -threads 0 final.mkv
ffmpeg -i source.flv -vn acodec copy destination.mp3
mencoder mf://*.jpg -mf fps=50:type=jpg -ovc raw -oac copy -o out50fps.avi
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=${out}.pdf ${filename1} ${filename2} ...
|
解压命令
1 2 3 4
| tar jxvf tar -xvf bzip2 -d 解压tar.bz2
|
机器相关
1 2 3 4 5 6 7 8 9 10 11 12 13
| sudo dmidecode -s system-product-name sudo dmidecode --type=processor | grep -i -A 1 charac pacmd set-sink-volume 0 0x10000 ```
```sh 磁盘复制 dd if=/dev/sda of=/dev/sdb 刻录光盘 dd if=XXXX.iso of=/dev/sdb 烧录cd cdrecord -v dev=/dev/cdrom yourimage.iso
从磁盘中创建一个CD/DVD的ISO镜像 dd bs=1M if=/dev/scd0 of=./filename.iso OR readom -v dev='D:' f='./filename.iso' speed=2 retries=8
|
sendmail命令–cmd下发送邮件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| sendemail -s ${mail-server} -f ${my_email} -t ${dst-email} -u WTF -m "Utilize command line tools - [sendemail] to send an e-mail to you." -xu ${username} -xp ${password} -o tls=auto -a ${attatch-file} ex: sendemail -s smtp.nju.edu.cn -f mg1433094@smail.nju.edu.cn -t 1826588117@qq.com -u WTF -m "Utilize command line tools - [sendemail] to send an e-mail to you." -xu mg1433094@smail.nju.edu.cn -xp password -o tls=auto
|
MYSQL
1
| mysql -u root -p -N -e"show processlist\G;" | egrep "Host\:" | awk -F: '{ print $2 }' | sort | uniq -c
|