| 解释 | ubuntu | centos7 |
|---|---|---|
| 用户环境变量 | ~/.profile | ~/.bash_profile |
| 监听网卡docker0收发包 | sudo tcpdump -i docker0 | ` |
| 查看收发包 | ping www.google.com | sudo ping www.google.com |
| 用户与组 | ||
| 激活root用户 | passwd | |
| 添加一个新用户 | useradd youname | |
| 设定登录密码 | sudo passwd youname | |
| 添加用户到sudoers file | sudo chmod u+w /etc/sudoers sudo vi /etc/sudoers 添加 youuser ALL=(ALL) ALL chmod u-w /etc/sudoers" |
|
"添加命令到 sudoers file |
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin | |
| 切换到root用户 | su root | |
| 切换用户和home目录 | su - postgres | |
| 添加新组 | sudo groupadd docker | |
| 添加用户到组 | sudo usermod -aG docker $USER | |
| 切换群组 | newgrp - docker | |
| 添加所有权 | sudo chown -R $USER ~/.npm | |
| 添加执行权限 | chmod u+x getdocker.sh | |
| 全部修改权限 | chmod 600 * | |
| 软件操作 | ||
| 软件包后缀 | *.deb | *.rpm |
| 软件源配置文件 | /etc/apt/sources.list | /etc/yum.conf |
| 升级系统版本 | sudo do-release-upgrade sudo apt dist-upgrade |
sudo yum update |
| 更新软件源 | sudo apt update | 每次运行yum时自动更新 |
| 安装软件选集 | sudo yum install centos-release-scl | |
| 更新已经安装的软件 | sudo apt upgrade | sudo yum update |
| 升级某个包 | sudo upgrade package | sudo yum update package |
| 安装软件 | sudo apt install package | sudo yum install package |
| 安装本地软件 | dpkg -i pkg.deb pkg --install pkg.deb |
yum install pkg.rpm rpm -i pkg.rpm |
| 源码安装 | $ tar -xvf ruby-2.6.5.tar.gz $ cd ruby-2.6.5 $ ./configure $ make $ sudo make install |
|
| 删除源码安装 | sudo make uninstall whereis ruby |
xargs -n 1 sudo rm -rf |
| 删除已安装的软件(保留配置文件) | sudo apt remove xxxxx | sudo yum erase package |
| 删除已安装软件(不保留配置文件)。 | sudo apt --purge remove xxxxx | |
| 删除为了满足其他软件包的依赖而安装的,但现在不再需要的软件包。 | sudo apt autoremove | |
| 将已经删除了的软件包的.deb安装文件从硬盘中删除掉。 | sudo apt autoclean | sudo yum clean |
| 服务管理 | ||
| 启动服务 | /etc/init.d/apache start | systemctl start postgresql-11 |
| 停止服务 | /etc/init.d/apache stop | systemctl stop postgresql-11 |
| 开机启动 | update-rc.d apache defaults | systemctl enable postgresql-11 |
| 禁止开机启动 | update-rc.d apache purge | systemctl disable postgresql-11 |
| 开机启动状态 | systemctl status postgresql-11 chkconfig --list |
|
| 进程管理 | ||
| 查看进程树 | pstree | 无 |
| 重启2235进程 | kill -1 2235 | |
| 强制杀死2236 | kill -9 2236 | |
| 杀死所有包含httpd的进程 | killall -9 httpd | |
| 暂停当前进程 | ctrl+z | |
| 终止 | ctrl+c | |
| 后台启动 | vi test & | |
| 脱离shell启动 | nohup wget site.com/file.zip | |
| 显式后台进程 | jobs -l | |
| 把工作号为1的后台任务置前台 | fg 1 | |
| 文件命令 | ||
| 切换目录 | cd home cd - last cd .. parent |
|
| 创建多级目录 | mkdir -p A/B | |
| 强制删除目录或文件 | rm -rf /dir | |
| 查看目录树 | sudo apt install tree tree . |
|
| 查看两级目录 | tree -L 2 | |
| 设置别名(临时生效) | alias ll='ls -alh --color=auto' | |
| 设置别名永久生效 | echo "alias ll='ls -alh --color=auto'" >> ~/.bashrc && source ~/.bashrc | echo "alias jupyter='jupyter notebook --no-browser'" >> ~/.bashrc && source ~/.bashrc |
| 复制文件夹 | cp -avr A B 结果B/A |
|
| Rename folder. | mv A B 结果B |
|
| move folder | mv A/B C/D 结果A, C/D/B mv C/D/B C/ 结果 C/B, D |
|
| 当前目录所有文件移动到上一级目录 | mv * ../ | |
| 解压 | tar -xvf ruby-2.6.5.tar.gz | |
| 创建软链接 | ln -s A B 结果B为新链接 B ->A |
sudo ln -s /home/yichang/cmake-3.15.4-Linux-x86_64/bin/cmake /usr/local/bin/cmake |
| 执行命令 | ||
| 清屏 | clear | |
| excute last command. | !! | |
| sudo 执行上条 | sudo !! | |
| excute #331 command of history list. | !331 | |
| 执行最近的以doc开头的指令 | !doc | |
| 常见管道命令 | ||
| writes each given STRING to standard output | echo -e '1 2 3 \n 5 6 7' | |
| 输出重定向覆盖 | echo 'hello' > info.txt | |
| 输出重定向追加 | echo 'hello' >> /etc/profile | |
| 更新用户环境变量 | echo "export NODE_PATH=$(npm root -g)" >> ~/.bashrc && source ~/.bashrc | |
| 每次取3个参数 | echo -e '1 2 3 \n 5 6 7'| xargs -n3 | |
| 取第2列输出 | echo -e '1 2 3 \n 5 6 7'| awk '{print $2}' | |
| 批量卸载 | dpkg -l | grep docker | awk '{print $2}' | xargs -n1 sudo apt -y remove | yum list installed | grep docker | awk '{print $1}' | xargs -n1 sudo yum -y remove |
| 删除文件 | whereis ruby | xargs -n 1 sudo rm -rf | |
| 删除文件 | ll | grep jupyter | awk '{print $9}'| xargs -n 1 sudo rm -rf |
Last active
February 21, 2020 09:26
-
-
Save Albert-W/c1de19ce7e2486fc8573331c47579a43 to your computer and use it in GitHub Desktop.
Linux操作命令
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment