本文大部分命令在 macOS 上同样适用,对于系统没有内置的命令可能需要你先用 brew 安装
nmap -p 80 qq.com
file.sh >> file.log 2>&1
# 将当前目录下所有 .js 文件重命名为 .ts ( 包括子孙目录 )
find . -depth -name "*.js" -exec sh -c 'mv "$1" "${1%.js}.ts"' _ {} \;
Use find:
find . -name "*.bak" -type f -delete
But use it with precaution. Run first:
find . -name "*.bak" -type f
to see exactly which files you will remove.
Also, make sure that -delete is the last argument in your command. If you put it before the -name *.bak argument, it will delete everything.
# 删除 dist 目录下包含的所有 __tests__ 目录
find dist -name "__tests__" -type d -exec rm -rf {} +
可用于备份前删除自动生成的文件,例如 node_modules、.idea、.node
find . -mindepth 2 -maxdepth 2 -type d \( -name "node_modules" -o -name ".idea" -o -name ".node" \) -exec rm -rf {} +
# 显示用户自己的进程树
ps -auf
# 显示所有进程
ps -ef
在脚本开头设置 PATH 变量可以决定后面的命令和子 shell 中的命令去哪里查找可执行程序
使用 export 命令导出环境变量可以确保后面执行的程序和子 shell 中可以读取到这个环境变量,在 shell 脚本中使用 export 命令导出的环境变量仅在这个脚本的执行过程中有效,并不会影响到外部环境
最好在脚本开头加上一行 set -eux,可以打印出执行步骤,出错后会立即退出
当后面执行的程序需要读取这个变量,或者子 shell 中需要使用这个变量
当你在 .zshrc 里声明了某个变量,例如 http_proxy。那么在 zsh 里执行所有命令的时候都可以读取到这个环境变量。
如果执行某个特定命令的时候临时不想让它读取到这个环境变量,可以这么做:
env -u http_proxy sh -c 'echo $http_proxy'
用 env -u 变量名称 隐藏对应的环境变量,将你想执行的命令放在 sh -c 参数里即可。
如果要隐藏多个变量,可以多次使用 -u 参数:
env -u http_proxy -u https_proxy sh -c 'env | grep http'
env -u 和 unset 命令的区别是,它不会删除全局 shell 环境的变量。
本文原载于:baiyun.me
本文大部分命令在 macOS 上同样适用,对于系统没有内置的命令可能需要你先用 brew 安装
nmap -p 80 qq.com
file.sh >> file.log 2>&1
# 将当前目录下所有 .js 文件重命名为 .ts ( 包括子孙目录 )
find . -depth -name "*.js" -exec sh -c 'mv "$1" "${1%.js}.ts"' _ {} \;
Use find:
find . -name "*.bak" -type f -delete
But use it with precaution. Run first:
find . -name "*.bak" -type f
to see exactly which files you will remove.
Also, make sure that -delete is the last argument in your command. If you put it before the -name *.bak argument, it will delete everything.
# 删除 dist 目录下包含的所有 __tests__ 目录
find dist -name "__tests__" -type d -exec rm -rf {} +
可用于备份前删除自动生成的文件,例如 node_modules、.idea、.node
find . -mindepth 2 -maxdepth 2 -type d \( -name "node_modules" -o -name ".idea" -o -name ".node" \) -exec rm -rf {} +
# 显示用户自己的进程树
ps -auf
# 显示所有进程
ps -ef
在脚本开头设置 PATH 变量可以决定后面的命令和子 shell 中的命令去哪里查找可执行程序
使用 export 命令导出环境变量可以确保后面执行的程序和子 shell 中可以读取到这个环境变量,在 shell 脚本中使用 export 命令导出的环境变量仅在这个脚本的执行过程中有效,并不会影响到外部环境
最好在脚本开头加上一行 set -eux,可以打印出执行步骤,出错后会立即退出
当后面执行的程序需要读取这个变量,或者子 shell 中需要使用这个变量
当你在 .zshrc 里声明了某个变量,例如 http_proxy。那么在 zsh 里执行所有命令的时候都可以读取到这个环境变量。
如果执行某个特定命令的时候临时不想让它读取到这个环境变量,可以这么做:
env -u http_proxy sh -c 'echo $http_proxy'
用 env -u 变量名称 隐藏对应的环境变量,将你想执行的命令放在 sh -c 参数里即可。
如果要隐藏多个变量,可以多次使用 -u 参数:
env -u http_proxy -u https_proxy sh -c 'env | grep http'
env -u 和 unset 命令的区别是,它不会删除全局 shell 环境的变量。
本文原载于:baiyun.me