CyanHall.com 创建于 2020-11-11, 上次更新:2021-04-30。
👉  github shields 如果有用请点赞。
如果想查询 Shell 命令每个参数的含义复制粘贴到 explainshell 查询。

1. 更改默认的Shell

    chsh -s /bin/zsh
  

2. 查看文件/目录的大小

    du -sh [filePath/Directory]
  

3. 强制删除目录内的文件

    rm -rf dir
# -f for force, -r for recursive
  

4. 查找具有特定模式的文件

    find / -name filename.xx
  

5. 移除具有指定模式的文件

    find . -name '*.pyc' -delete # remove all .pyc files from a project
  

6. 找到所有某名字的进程

    ps aux | grep [name]
  

7. 关闭所有某名字的进程

    kill $(ps aux | grep [name] | awk '{print $2}')
  

8. 实时查看日志

    tail -f filename.log
  

9. 检查网络的连接性

    nc -z -v [ip] [port]
nc -vz -w 2 domain.com 22
  

10. 检查端口占用

    sudo lsof -i:[port number]
  

11. 断电续传下载文件

    wget -c [url]
  

12. 从远程服务器下载文件

    scp -i ssh-key-file [user]@[ip]:remote/file/path local/file/path
  

13. 上传文件到远程服务器

    scp -i ssh-key-file [file/to/send] [user]@[ip]:[dest/path]
  

14. 给脚步执行的权限

    chmod +x ./script.sh
  

15. 生成新的SSH密钥文件

    ssh-keygen -t rsa -C "remark"
  

16. 启动 SSH 客户端

    eval `ssh-agent -s`
  

17. 限制 SSH 密钥文件的访问

    chmod 400 [key-path]
  

18. 启用 SSH 密钥

    ssh-add [key-path] # without .pub
  

19. 用SSH创建一个socks v5代理

    ssh -i ssh-key-file -o IdentitiesOnly=yes [username]@[ip]  -D 127.0.0.1:1007
  

20. Shell 循环

    for i in `seq -w 000 3`;do echo test_"${i}";done
# Output:
#  test_000
#  test_001
#  test_002
#  test_003
  

21. macOS

    say hello world
# list all langs
say -v '?'
# list all file format
say --file-format=?
say -v Ting-Ting -o test.aac hello world
  

22. Add Swap Space on Ubuntu

    # From https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-18-04
# Check
sudo swapon --show
free -h

# Creating a Swap File
sudo fallocate -l 4G /swapfile
ls -lh /swapfile # check
sudo chmod 600 /swapfile
sudo mkswap /swapfile

# Enabling the Swap File
sudo swapon /swapfile
sudo swapon --show # check

# Making the Swap File Permanent
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

sudo sysctl vm.swappiness=10
sudo vi /etc/sysctl.conf # add to the end of file
	vm.swappiness=10

# Adjusting the Cache Pressure Setting
sudo sysctl vm.vfs_cache_pressure=50
sudo vi /etc/sysctl.conf # add to the end of file
	vm.vfs_cache_pressure=50
  

1. 更改默认的Shell

    chsh -s /bin/zsh
  

3. 强制删除目录内的文件

    rm -rf dir
# -f for force, -r for recursive
  

5. 移除具有指定模式的文件

    find . -name '*.pyc' -delete # remove all .pyc files from a project
  

7. 关闭所有某名字的进程

    kill $(ps aux | grep [name] | awk '{print $2}')
  

9. 检查网络的连接性

    nc -z -v [ip] [port]
nc -vz -w 2 domain.com 22
  

11. 断电续传下载文件

    wget -c [url]
  

13. 上传文件到远程服务器

    scp -i ssh-key-file [file/to/send] [user]@[ip]:[dest/path]
  

15. 生成新的SSH密钥文件

    ssh-keygen -t rsa -C "remark"
  

17. 限制 SSH 密钥文件的访问

    chmod 400 [key-path]
  

19. 用SSH创建一个socks v5代理

    ssh -i ssh-key-file -o IdentitiesOnly=yes [username]@[ip]  -D 127.0.0.1:1007
  

21. macOS

    say hello world
# list all langs
say -v '?'
# list all file format
say --file-format=?
say -v Ting-Ting -o test.aac hello world
  

2. 查看文件/目录的大小

    du -sh [filePath/Directory]
  

4. 查找具有特定模式的文件

    find / -name filename.xx
  

6. 找到所有某名字的进程

    ps aux | grep [name]
  

8. 实时查看日志

    tail -f filename.log
  

10. 检查端口占用

    sudo lsof -i:[port number]
  

12. 从远程服务器下载文件

    scp -i ssh-key-file [user]@[ip]:remote/file/path local/file/path
  

14. 给脚步执行的权限

    chmod +x ./script.sh
  

16. 启动 SSH 客户端

    eval `ssh-agent -s`
  

18. 启用 SSH 密钥

    ssh-add [key-path] # without .pub
  

20. Shell 循环

    for i in `seq -w 000 3`;do echo test_"${i}";done
# Output:
#  test_000
#  test_001
#  test_002
#  test_003
  

22. Add Swap Space on Ubuntu

    # From https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-18-04
# Check
sudo swapon --show
free -h

# Creating a Swap File
sudo fallocate -l 4G /swapfile
ls -lh /swapfile # check
sudo chmod 600 /swapfile
sudo mkswap /swapfile

# Enabling the Swap File
sudo swapon /swapfile
sudo swapon --show # check

# Making the Swap File Permanent
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

sudo sysctl vm.swappiness=10
sudo vi /etc/sysctl.conf # add to the end of file
	vm.swappiness=10

# Adjusting the Cache Pressure Setting
sudo sysctl vm.vfs_cache_pressure=50
sudo vi /etc/sysctl.conf # add to the end of file
	vm.vfs_cache_pressure=50
  


Maitained by Cyanhall.com, Copy Rights @ CC BY-NC-SA 4.0