Skip to content

Latest commit

 

History

History
165 lines (109 loc) · 2.98 KB

shell.md

File metadata and controls

165 lines (109 loc) · 2.98 KB

将目录下的所有文件每行一个列出来

shell> find ./  -printf "%f\n"

快速生成大文件

sell> dd if=/dev/zero of=/tmp/my_file bs=1M count=1000

快速生成每次都不一样的大文件

shell> head -c 10M < /dev/urandom > /tmp/my_file

小写转换成大写

shell> sha1sum test | tr a-z A-Z

大写转换成小写

shell> echo 'A5F5E9413C558753025495DAF6A0A7B47E55402B' | tr A-Z a-z

删除文件名带 - 的文件

shell> rm ./-A_NNMHDB3MW3eB

tree 查看所有文件及权限

shell> tree -aup

复制所有文件(包括隐藏文件)

shell> cp -R /path/to/src/. /path/to/dest/

删除超过特定大小的文件

find . -size +100k -delete

dpkg

查看安装的所有软件

shell> dpkg -l
shell> dpkg -l | grep ftp

du

计算一个目录的大小

du -sh folder

只显示一级目录的大小

du -sh --max-depth=0

进程

后台执行进程

shell> nohup /usr/bin/php demo.php > /tmp/demo.log 2>&1 &

批量杀死进程

shell> ps -ef | grep demo.php | grep -v grep | awk '{print $2}' | xargs kill -9

查看特定端口所属进程

shell> netstat -anp | grep :4730

查找正在运行的进程

shell> ps -ef | grep php
shell> ps -aux | grep php

grep

查找包含任意一个关键字的行

shell> grep -E 'word1|word2|word3' file.txt

查找包含所有关键字的行

shell> grep word1 file.txt | grep word2 |grep word3

统计 test2 中有,test1 中没有的行

shell> grep -vFf test1.csv test2.csv

统计两个文本文件的相同行

shell> grep -Ff test1.csv test2.csv

根据前面两列的值是否相同去重

sort -u -t, -k1,2 test.txt

计算指定列的总和

awk -F',' '{sum += $4};END {print sum}' test.txt

快捷键

ctrl+a: 光标移到行首
ctrl+e: 光标移到行尾
ctrl+l: 清屏,相当于clear
ctrl+u: 清除光标前至行首间的所有内容
ctrl+shift+t: 打开 Tab 新标签