知识库
系统管理
Ubuntu

Ubuntu命令

环境变量类

  • 修改可见显卡

常用于没有显示指定显卡的python程序

os.environ["CUDA_VISIBLE_DEVICES"] = "1"

命令类

系统监视/文件管理

  • 查看显卡:nvidia-smi

  • 查看cpu信息:cat /proc/cpuinfo

  • 查看磁盘IO:iostat -x 1 10

  • 查看磁盘:df -h

  • 查找进程-以jutpyer为例(可查进程号):ps -ef | grep jupyter

  • 查找文件-以inception开头的文件为例:find . -name "inception*"

  • 查看文件夹下文件数量:

    • 统计子文件夹:ls -lR | grep "^-" | wc -l

    • 不统计子文件夹:ls -l | grep "^-" | wc -l

  • 查看当前文件夹大小:du -sh

系统管理

  • 设置密码:passwd

  • apt更新:

    apt update
    apt intall xxx
  • 待机:sudo pm-suspend (如果找不到命令就先安装: apt -y install pm-utils)

  • 防火墙配置

    • 添加规则以允许进入的连接:sudo iptables -A INPUT -p tcp --dport 8080 -j ACCEPT

      这条命令的意思是向INPUT链添加(-A)一个规则,允许(-j ACCEPT)通过TCP协议(-p tcp)目标端口(--dport)为8080的进入的连接。

    • 添加规则来允许发出的连接:sudo iptables -A OUTPUT -p tcp --sport 8080 -j ACCEPT

      这允许从服务器端口8080发出的TCP连接。

    • 检查规则是否已经生效:sudo iptables -L -v

软件/服务

  • 后台启动:nohup [command] > nohup.out 2>&1 &

    • jupyter notebook后台进程启动:nohup jupyter notebook 2>&1 &

    • Clash for windows后台进程启动:nohup /home/xr/clash/cfw > cfw.out 2>&1 &

    • qbittorrent后台进程启动:nohup qbittorrent 2>&1 &qbittorrent-nox -d

  • 查看正在运行的后台任务:jobs

  • 启动ssh:/etc/init.d/ssh start

  • ssh配置文件

    vi /etc/ssh/sshd_config:
    Port 9777
    PermitRootLogin yes
    MaxStartups 10:30:600

Screen

  • screen -S yourname -> 新建一个叫yourname的session

  • screen -ls -> 列出当前所有的session

  • screen -r yourname -> 回到yourname这个session

  • screen -d yourname -> 远程detach某个session