Linux 命令梳理
待梳理命令
nohup
用户管理
useradd
新建用户
sudo useradd {user name} -s /bin/bash -d /data/{user name} -m
sudo useradd hdx -s /bin/bash -d /data/hdx -m # 创建用户 hdx,并指定bash为/bin/bash、家目录 /data/hdx
passwd
设置密码
sudo passwd {user name}
sudo passwd hdx # 为用户 hdx 设置密码
userdel
删除用户
sudo userdel {user name}
sudo userdel hdx # 删除用户 hdx
usermod
修改用户账户
sudo usermod {user name} -md {new home path}
sudo usermod hdx -md /data/hdx # 将用户 hdx 的家目录移动到 /data/hdx
tmux
session
Commands | explanation |
---|---|
tmux list-sessions / tmux ls | 列出现有的 session |
tmux new -s [session name] | 创建一个 session |
tmux attach -t [session name] | 回到一个 session |
tmux detach | 离开当前 session |
tmux kill-server | 关闭所有 session |
tmux kill-session -t [session name] | 关闭指定 session |
快捷键
在 tmux 中直接通过默认前缀 ctrl + b 之后输入对应命令来操作。例如 <b-%> 对应这样的按键顺序 ctrl + b + %
commands | explanation |
---|---|
< b - % > | 左右分屏 |
< b - " > | 上下分屏 |
< b - 方向键 > | 焦点在不同面板间移动 |
<b - d> | 脱离当前会话,可暂时返回Shell界面 |
<b - c> | 创建新窗口 |
<b - &> | 关闭当前窗口 |
<b - [0~9]> | 数字键切换到指定窗口 |
<b - z> | 最大化当前所在面板 |
<b - [ > | 启动滚屏 |
Reference:
[1] 《tmux 指南》. https://wdxtub.com/2016/03/30/tmux-guide/
sftp
几乎是比 rz sz 好用的文件传输方式。
sftp:/home/frank> help
# 与 Linux 保持一致的命令
rm # delete a file
rmdir # remove a directory on the remote server
cd # change your remote working directory
clear # clear screen
ls # list contents of a remote directory
mkdir # create a directory on the remote server
mv # move or rename a file on the remote server
pwd # print your remote working directory
# stfp 所特有的命令
lcd # change and/or print local working directory
lls # list contents of a local directory
lpwd # print your local working directory
get # download a file from the server to your local machine
put # upload a file from your local machine to the server
rename # move or rename a file on the remote server
tr
流式字符替换。
把空格符替换成换行符:
cat sogouT.utf8.txt | tr " " "\n" > sogouT.txt
sogouT.txt 中不会存在空格符了,因为已经全被替换成了换行符。
du
du can show how many disk space has been used. Such as :
du -h *
to show all of the file`s size in the current directory.
df
Show information about the file system on which each FILE resides, or all file systems by default.
df -h
7z
7z is one of a data compression format on Windows and Linux.
The command to install is :
apt-get install p7zip-full
The command to decompression is :
7z x {file name}
The command to compression is :
7z a -r {archive name}.7z {folder name}
zip
压缩
zip 压缩后文件名.zip 被压缩对象
unzip
解压至指定目录
-d 选项
unzip nmt.zip -d nmt
tar
压缩/打包
tar czvf 压缩后文件名.tar.gz 被压缩对象
解压缩
tar zxvf 被解压缩对象.tar.gz
screen
Creating a new session
screen -S SessionName
list all sessions
screen -list
resumes a detached screen session
screen -r SessionName
Kill detached screen session
screen -X -S [session you want to kill] quit
举例如下:
[root@localhost ~]# screen -ls
There are screens on:
9975.pts-0.localhost (Detached)
4588.pts-3.localhost (Detached)
2 Sockets in /var/run/screen/S-root.
[root@localhost ~]# screen -X -S 4588 quit
[root@localhost ~]# screen -ls
There is a screen on:
9975.pts-0.localhost (Detached)
1 Socket in /var/run/screen/S-root.
reference
ssh
login
ssh 用户名@IP地址
scp
upload
scp /本地文件路径 用户名@IP地址:/存放于远程主机的位置
download
scp 用户名@IP地址:/远程主机上文件路径
vim
.vimrc
syntax on
set nobackup
set noswapfile
set hlsearch
set number
set ruler
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set cindent
set smartindent
set mouse=v
set bg=dark
set encoding=utf-8
set nobomb
set cursorline
set magic
set confirm
set langmenu=zh_CN.UTF-8
set showmatch
set matchtime=1
set scrolloff=3
set completeopt=longest,menu
set t_Co=256
set wildmenu "<tab>自动不全
set wildmode=full "<tab>自动不全 zsh自动不全菜单
set history=200 "提高命令行历史记录的数目非常有价值
set undofile "un~ 文件统一存放
set undodir=~/.vimundofile
colorscheme darkblue
cnoremap <C-p> <Up> "命令行模式中 <C-p> 映射为 <Up>
cnoremap <C-n> <Down>
"加载插件的最小配置
set nocompatible
filetype plugin on
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o "禁止粘贴时自动注释
iptables 添加规则 开放 80 端口
sudo /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
Nginx 像 Apache 一样列出目录下的文件
在 nginx/conf/nginx.conf 中添加:
autoindex on;
修改为英文环境
LANG="en_US.UTF-8"
LANGUAGE="en_US:en"
Nvidia GPU 服务器安装
挂载了 Nvidia GPU 的服务器在安装操作系统以后无法正常启动,会曝出如下错误:
[11.128989] nouveau E[DEVICE][0000:03:00.0] unknown chipset, 0x118010a2
[11.129037] nouveau E[ DRM] failed to create 0x80000080, -22
主要的信息是 unknown chipset。
解决方法是进入到 grub 设置里(在开机选择界面按 e 进入 grub 页面),在里面加入:
nomodeset rdblacklist=nouveau
具体方法参照如下链接:
https://askubuntu.com/questions/38780/how-do-i-set-nomodeset-after-ive-already-installed-ubuntu