记录常用的Linux命令(持续更新)

1,540 阅读1分钟

强烈建议Linux命令行重度用户安装zsh或fish,安装插件后真香。

  • zsh的安装和插件安装可以参考这里 blog.csdn.net/I_lost/arti…
    注意不管是安装zsh还是oh-my-zsh后都需要执行reboot
  • zsh必装插件
  1. incr 自动补全
mkdir ~/.oh-my-zsh/plugins/incr
wget http://mimosa-pudica.net/src/incr-0.2.zsh -O ~/.oh-my-zsh/plugins/incr/incr.plugin.zsh
  1. zsh-syntax-highlighting 语法高亮
  2. zsh-autosuggestions 历史记录

常用Linux命令

端口

  • ss -lnt 查询所有开启的端口

Linux信息

  • lsb_release -a 即可列出所有版本信息

sudo

  • su git 切换到git账号
  • sudo -i 为了频繁的执行某些只有超级用户才能执行的权限,而不用每次输入密码,可以使用该命令。提示输入密码时该密码为当前账户的密码。没有时间限制。执行该命令后提示符变为“#”而不是“$”。想退回普通账户时可以执行“exit”或“logout” 。
    参考链接

ls

  • ls -lh h文件大小

历史命令

  • history 打印历史命令
  • Ctrl + r 搜索历史命令,输入关键词后,可以再按Ctrl + r 继续搜索匹配命令
  • !! 输入后按Tab显示上一条命令
  • !git 输入后按Tab显示最近一条以git开头的命令
  • !2901 输入后按Tab显示history列表中第2901条命令
  • 按上下方向键

批量创建

  • mkdir 202004{01..30} 批量创建30个目录

删除文件或目录

  • rm -rf test 删除test目录
  • rm -f test.h 删除test.h文件

-f:强制删除;-r:递归删除

判断终端是否走了代理服务器

  • curl cip.cc
  • curl www.google.com

给终端设置代理

  • 将下面的脚本添加到.bash_profile中
function proxy_off(){
        unset http_proxy
        unset https_proxy
        unset ftp_proxy
        unset rsync_proxy
        echo -e "已关闭代理"
}
 
function proxy_on() {
        export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
        export http_proxy="http://127.0.0.1:8001"
        export https_proxy=$http_proxy
        export ftp_proxy=$http_proxy
        export rsync_proxy=$http_proxy
        export HTTP_PROXY=$http_proxy
        export HTTPS_PROXY=$http_proxy
        export FTP_PROXY=$http_proxy
        export RSYNC_PROXY=$http_proxy
        echo -e "已开启代理"
}
  • 执行source .bash_profile
  • 执行proxy_on
  • 执行curl cip.cc,通过输出的信息判断是否设置成功