Unix常用命令
常用命令
- 
查看系统版本
cat /proc/version - 
查看内核版本
uname -a - 
wget下载
wget xxx.com/xxx.txt如下载miniconda3wget https://mirrors.bfsu.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh - 
下载安装miniconda3
cd ~mkdir downloads && cd downloadswget https://mirrors.bfsu.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.shbash Miniconda3-latest-Linux-x86_64.sh一路按ENTER,输入yes即可,默认安装在~/miniconda3目录下source ~/.bashrc - 
每次登录都需要
source ~/.bashrc的解决办法 创建文件~/.bash_profile,添加如下内容1 2 3 4 5 6# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ] ; then source ~/.bashrc fi`` 然后
source ~/.bash_profile - 
显示当前目录下前 100 个文件
ls | head -n 100 - 
断开terminal后后台保持程序运行
nohup xxx &其中xxx为正常的执行程序的命令: 如 shell 脚本执行./hello.sh如 python 脚本执行python hello.py整体为:nohup python hello.py &参考链接 - 
下载和上传 从服务器下载到本地:
sftp get server_path local_path从本地上传到服务器:sftp put local_path server_path如果需要操作文件夹,加上-r参数 - 
shell 脚本实现自动化下载和上传
1 2 3 4 5#!/bin/bash sftp hostname<<EOF get -r /home/username/myfiles/ /Users/username/Desktop/myfiles/ quit EOF``
 - 
vim中的内容与系统剪贴板交互
vim内容粘贴到系统剪贴板
1 2 3 41. 选择好要复制的内容,比如选中文件所有内容 gg+v+G # ", +, y 三个字符分别按下 2. "+y # 系统外可以使用 ctrl+v系统剪贴板内容粘贴到vim
1 2# ", *, p 三个字符分别按下 1. "*p - 
关于 terminal 配置的问题
 
- zsh 参考链接
 - bash
sudo hostnamectl set-hostname <yourhostname>yourhostname自己指定 
- 查看 gcc 和 g++ 默认使用的 C和C++标准
 
- 
查看 C 标准
gcc -E -dM - </dev/null | grep "STDC_VERSION"得到的结果为#define __STDC_VERSION__ 201710L说明是 C17 的标准 - 
查看 C++ 标准
g++ -dM -E -x c++ /dev/null | grep -F __cplusplus得到的结果为#define __cplusplus 201402L说明是 C++14 的标准 
- 
查看当前目录下所有文件的大小之和
du -sh - 
清空终端 Linux
clear或者ctrl + pmac terminalcommand + k - 
查找当前目录下带有 “xxx” 的文件名
find . -name "*xxx*" - 
添加自己的脚本到系统终端 假设在
/home/username/myutils目录下有脚本test.sh首先给该脚本添加执行权限chmod +x test.sh然后在~/.bashrc文件中添加export PATH="$PATH:/home/username/myutils"并保存 再更新一下即可source ~/.bashrc,每次重新打开终端时,系统会自动执行~/.bashrc如此就可以在系统终端的任意目录下输入test.sh执行脚本了 - 
Linux 下压缩和解压文件
- 压缩:
tar -czvf <archive_name.tar.gz> <folder_to_compress>如压缩文件夹test为test.tar.gz:tar -czvf test.tar.gz test - 解压:
tar -xzvf <archive_name.tar.gz>如解压文件夹test.tar.gz:tar -xzvf test.tar.gz 
 - 压缩:
 - 
查看文件夹所在文件系统的剩余空间 如 查看
/home/username目录所在文件系统的剩余空间df -h /home/username - 
创建文件夹并进入到该文件夹
mkdir test && cd $_,其中$_表示上一个命令的最后一个参数 - 
pip 下载 package 换国内源加速
1 2 3 4 5 6 7# 单次换源 python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple <package name> # 永久换源 pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple pip install <package name> 
.bashrc 配置
 | 
 |