常见命令

创建文件夹然后进入

  1. $ mkdir my-project && cd "$_"

$_ 保存的是上一条命令的最后一个参数

查看文件夹的大小

  1. $ du -sh project-name

-sh 表示以可读单位显示目录的大小

对目标文件内容进行筛选

  1. $ cat package.json | grep lodash -A 5

-A-B 分别表示 after 和 before,显示筛选之后的行数数量的文件

从头/尾显示内容

  1. $ head -n 10 package.json
  2. $ tail -n 10 package.json

-n 后面跟文件的行数

输出之后显示行号

  1. $ cat -n package.json

运行文件中的命令

  1. $ source ~/.zshrc

运行上述指令会自动执行文件中的内容

向文件中追加内容

  1. $ mkdir temp.txt
  2. $ echo 'hello' >> temp.txt

这个操作符会向 temp.txt 文件的尾部追加内容

向文件中添加内容

  1. $ mkdir temp.txt
  2. $ echo 'hello' > temp.txt

替换文件中的整个内容为 hello

查看进程

  1. # 查看所有运行中的进程
  2. $ ps aux
  3. # 查看特定的进程
  4. $ ps aux | grep string

显示运行进程的动态实时信息

  1. $ top

查找文件

以某个类型来进行文件查找

  1. $ find root_path -type d

这里的 type 可以有三个参数:

  • -type d: 文件夹
  • -type f: 文件
  • -type l: symlinks

以文件名来进行查找

  1. $ find root_path -name '*.py'
  2. # 不考虑大小写
  3. $ find root_path -type d -iname '*lib*'

以某个时间为节点进行查找

  1. # 查找过去7天进行修改的文件
  2. $ find root_path -mtime -7

以文件尺寸为筛选项

  1. $ find root_path -size +500K -size -10M

去除某个文件夹

  1. fint root_path -name '*.js' -not -path './node_modules/*'

扩展