命令和常见问题

网站问题

hexo command can not found

  • hexo包没有安装或者意外被卸载,按照以下步骤即可重新安装:
    • npm uninstall -g hexo-cli
    • npm install -g hexo-cli
    • hexo -v

ssh

连接远程主机

  • ssh -p 22 root@host
  • 其中-p后面是端口号,root是远程主机上的用户名,host是远程主机的ip地址。以组里的服务器为例,则为:ssh -p 22 123@10.181.83.26

如果连接不上

  • 检查是否启动:sudo systemctl status sshd如果显示activate,则表明ssh服务已经启动
  • 启动命令:sudo systemctl start sshd
  • 设置开机自启动命令:sudo systemctl enable sshd
  • 也有可能时防火墙不允许指定端口通过,检查防火墙规则:sudo ufw status
  • 允许端口22通过:sudo ufw allow 22/tcp
  • 检查防护墙是否是开机自启动:sudo systemctl is-enabled ufw
  • 设置防火墙开机自启动:sudo systemctl enable ufw

git

  • git add .
  • git commit -m “first commit”
  • git status
  • git remote -v 查看所有远端仓库
  • git remote add name git@…… 添加远端仓库
  • git remote remove name 移除远端仓库

linux

  • mv /root/path/ /root/path2
    移动第一个路径下的某一个文件至第二个路径
  • cd:cd /path/dic cd .. 上一个目录
  • ls: ls 查看目录下的文件 ls -l 列出文件详细信息
  • cat: cat test.txt 终端打印文件内容
  • cp: cp test1.txt test2.txt 复制文件1的内容到文件2
  • rm: rm file.txt 删除文件
  • touch: touch file.txt 创建一个新的文件
  • pwd: 显示当前位置
  • mkdir: mkdir file 创建新的目录
  • rmdir: 删除空的目录
  • tar:
    • tar -cvf archive.tar /path/to/directory 创建一个名为 archive.tar 的归档文件
    • tar -xvf archive.tar -C /path/to/extract 解压 archive.tar 到指定目录
  • ping: ping google.com 测试网络联通性
  • ipconfig: 显示所有网络信息的接口
  • wget: wget 是一个命令行工具,用于从网络上下载文件。它支持 HTTP、HTTPS 和 FTP 协议,并且可以递归下载整个网站。
    • wget https://example.com/file.zip下载单个文件
    • wget -O myfile.zip https://example.com/file.zip 下载文件并保存为指定名称
  • 硬盘挂载:
    • sudo umount /path/file:取消挂载在这个文件下的硬盘
    • mount /dev/sdb /data:将硬盘sdb挂载在/data文件夹下
    • mount:查看是否挂载成功
    • vim /etc/fstab:编辑这个文件可以设置系统开机自动挂载
  • 重启:
    • reboot:重新启动
    • shutdown -r now:现在重启
    • sudo shutdown -r +10:10分钟后重启
    • sudo shutdown -r 22:00:晚上10点重启
  • 硬盘分区:
    • fdisk -l:查看当前所有磁盘的分区情况
    • lsblk(老师不离开):查看所有磁盘所有分区的挂载情况
    • blkid:查看UUID
  • vim文本编辑:
    • 一般要使用sudo,因为一些文件只有root用户能编辑
    • 进入文件后,首先点insert开始插入模式开始编辑
    • 编辑完成后点esc退出插入模式,按:wq退出
  • uptime:记录当前时间,从上次系统启动开始系统运行时间, 目前连接的用户数,过去1,5,15分钟系统的平均负载
  • man:在所有命令加上man,会在终端打开一个手册,展示这个命令的功能和可选参数
  • lscpu:查看CPU的数量和其他信息
  • netstat -nat | grep 'ESTABLISHED' | grep ':22 ' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c:显示当前ssh连接到服务器的用户数及其ip地址
  • ls -l :查看当前目录下所有文件的详细信息包括
  • 权限解释:drwxr-xr-- 2 user group 4096 Jan 1 10:00 myfolder:
    • 第一个字符表示文件类型,d表示目录,-表示普通文件,l表示符号链接等。
    • 接下来的9个字符分为三组,每组三个字符,分别表示所有者、所属组和其他用户的权限。
    • 每组中的三个字符分别表示读(r)、写(w)和执行(x)权限。如果某个权限没有被授予,则用-表示。
    • drwxr-xr–:表示这是一个目录,所有者有读、写和执行权限,所属组有读和执行权限,其他用户只有读权限。
  • chmod -R u+rwx /path/folder:
    • -R:递归地对文件夹及其内部的所有文件和子文件夹应用权限更改
    • u:表示用户(所有者)
    • +rwx:表示添加读、写和执行权限。
    • /path/to/folder:替换为你要设置权限的文件夹的实际路径
  • chown test:test /data:将data文件的所有者和所属组都设置为test
  • export http_proxy=http://ip:端口:为linux系统设置代理,ip为win的ipv4地址,端口为代理软件的的监听端口一般为7890或者7897,设置好后可以使用curl google.com来检测是否可以访问google,如果返回内容则设置成功。还需要设置export https_proxy=http://192.168.1.2:7890

Authentication failure

  • 刚安装没有设置root密码,运行sudo passwd,设置密码,再运行su即可

服务器桌面环境挂掉了

  • systemctl status gdm或者systemctl status lightdm查看桌面环境运行状态
  • sudo systemctl restart gdm重启桌面环境即可
  • 重启GDM导致界面死机:按住alt+prtsc,依次按下 r e i s u b,即可重启电脑。
  • 如果gdm一直重启不了,可以使用lightgdm作为显示管理器,运行以下命令即可设置lightgdm为默认显示管理器:
    • sudo dpkg-reconfigure lightdm
    • sudo systemctl restart lightdm

huggingface

下载模型或者数据

  • pip install -U “huggingface_hub[cli]” 下载huggingface_hub
  • huggingface-cli login 登录,使用token,在hf界面设置access token
  • $env:HF_ENDPOINT = “https://hf-mirror.com“ 使用国内镜像
  • huggingface-cli download –resume-download gpt2 –local-dir gpt2 下载模型
  • 下载数据集 huggingface-cli download –repo-type dataset –resume-download wikitext –local-dir wikitext
  • token存储地址:C:\Users\123.cache\huggingface\stored_tokens

excalidraw(linux)

  • cd excalidraw
  • yarn
  • yarn start
  • AI-MO/aimo-validation-amc

python自带虚拟环境(linux)

  • python 创建虚拟环境:
    python3 -m venv name
  • 进入虚拟环境:
    source name/bin/activate
  • 进入项目文件:
    cd /path/to/project
  • 打开vscode:
    code .

sftp(类似于ssh但命令更简单)

上传文件到服务器

  1. 连接服务器:sftp root@host
  2. cd远程服务器到指定路径:cd path/to/dict
  3. 上传本地路径下的文件到远程服务器:put local\path\doc.exe

kaggle

使用kaggle api在本地下载kaggle上的数据,模型等

  1. 在kaggle上的setting中,创建token,会自动下载一个kaggle.json
  2. C/user/name/下创建文件夹.kaggle,将json文件放入其中
  3. 在终端中运行命令:kaggle competitions download -c AI-Mathematical-Olympiad-Progress-Prize-2注意要将赛事名称中间的空格用-代替
  4. 使用命令:tar -xf archive.zip -C target_folder将下载好的zip文件解压到指定文件夹

open resume

  • D盘打开project文件夹
  • 右键打开git
  • 运行npm run dev
  • 第一次安装:
    • cd open-resume
    • npm install
    • npm run dev
  • 打开localhost:3000即可

git连接github失败

  • 配置Git使用代理
  • git config --global http.proxy http://代理ip:7897
  • git config --global https.proxy http://代理ip:7897
  • 其中端口号和IP地址可以打开设置->网络与Internet->代理来得到
  • 配置完后可以查看是否配置成功git config --global -l
  • 这将列出当前的 Git 配置信息,确保其中的 http.proxy 和 https.proxy 设置为你刚刚配置的端口。

cmd命令

  • msinfo32:可以查看主板信息

windows代理作用于WSL

  • .sh文件已经保存在github,下载下来bash 运行即可,脚本如下:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    function proxy_on() {
    ## 这里的代理ip即为windows_ip,即wsl通过windows的ip的7897端口(为windows上代理软件的使用端口)来访问外网
    export http_proxy="http://代理ip:7897"
    export https_proxy=$http_proxy
    export HTTP_PROXY=$http_proxy
    export HTTPS_PROXY=$http_proxy
    echo -e "终端代理已开启,windows ip 为 代理ip。"
    if curl --silent --head --max-time 3 https://www.google.com/ | grep "HTTP.*200" > /dev/null; then
    echo "Google 连通性正常。"
    else
    echo "无法连接到 Google。"
    unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
    echo -e "终端代理已关闭。"
    fi
    }


    function proxy_off(){
    unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
    echo -e "终端代理已关闭。"
    }
    ## 以下代码要删掉,不然导致source ~/.bashrc的时候,bashrc中继续source ~/.bashrc从而不停循环,导致卡死
    if [ -f ~/.bashrc ]; then
    source ~/.bashrc
    fi

wsl终端打不开

在source ~/.bashrc时发现没有反应,关掉终端后再打开,就无法打开终端了,这是由于.bashrc中的代码存在错误,造成了打开终端时候,source ~/.bashrc发生错误,遵循以下步骤:

  • 安全模式进入WSL:wsl --exec bash --noprofile --norc
  • mv ~/.bashrc ~/.bashrc.bak (将原来的bashrc文件变成bashrc.bak文件,这样再打开终端会自动创建一个全新的,空白的bashrc文件)
  • 运行exit退出安全模式,运行wsl --shutdown,然后打开终端,会自动启动wsl
  • 查看bashrc.bak文件,修改错误,然后运行mv ~/.bashrc.bak ~/.bashrc,就能将修改后的bashrc正常使用了

配置Linux使用代理

本方法同样适用于wsl

  • sudo vim ~/.bashrc
  • 在文件的末尾添加函数如下:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    function proxy_on() {
    # 代理服务器配置
    local proxy_server="192.168.1.2" # 代理服务器地址
    local proxy_port="7890" # 代理服务器端口
    local proxy="http://${proxy_server}:${proxy_port}"

    # 设置代理环境变量
    export http_proxy=$proxy
    export https_proxy=$proxy
    export HTTP_PROXY=$proxy
    export HTTPS_PROXY=$proxy

    # 设置无需代理的地址
    export no_proxy="localhost,127.0.0.1/8,::1,192.168.0.0/23,*.local"

    echo -e "终端代理已开启,代理服务器为 ${proxy_server}:${proxy_port}。"

    # 检查 Google 连通性
    if curl --silent --head --max-time 3 https://www.google.com/ | grep "HTTP.*200" > /dev/null; then
    echo "Google 连通性正常。"
    else
    echo "无法连接到 Google。"
    # 如果无法连接,关闭代理
    unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
    echo -e "终端代理已关闭。"
    fi
    }

    function proxy_off() {
    # 关闭代理
    unset http_proxy HTTP_PROXY https_proxy HTTPS_PROXY
    unset no_proxy
    echo -e "终端代理已关闭。"
    }