linux常用命令

**

一、关于vi/vim相关命令

1.vi filename:命令行
2.i 键:编辑模式
3.esc -> :set number:显示行号。或者:set nu
 取消行号显示为 :set nonu
4.esc ->:wq:保存退出 。esc->:q!不保存退出
5.:/reg_expression:正则匹配vi中的内容
6.:行号:定位到某一行

7.编辑文件时,vi进入后出现异常(需按e键才能清除),可用 ll 命令输出异常文件,然后删除即可。示例如下:

shaohd@wks00:~/shaohd/bert_product$ ll
total 68
drwxr-xr-x 13 shaohd jupyterhub  4096 12月  9 14:24 ./
drwxr-xr-x  3 shaohd jupyterhub  4096 12月  8 10:35 ../
drwxr-xr-x  7 shaohd jupyterhub  4096 12月  7 19:47 bert-master/
-rw-r--r--  1 shaohd jupyterhub 16384 12月  7 19:47 ~~.classifier.py.swp~~ 
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  8 20:26 conf/
drwxr-xr-x  3 shaohd jupyterhub  4096 12月  7 19:47 data/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  7 19:47 .ipynb_checkpoints/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  8 13:35 log/
drwxr-xr-x 14 shaohd jupyterhub  4096 12月  9 09:44 model/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  9 14:17 myindustry/
drwxr-xr-x 11 shaohd jupyterhub  4096 12月  9 14:23 myproduct/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  9 09:25 __pycache__/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  7 19:48 schema/
drwxr-xr-x  2 shaohd jupyterhub  4096 12月  7 19:48 script/
shaohd@wks00:~/shaohd/bert_product$ rm -rf .classifier.py.swp

vim快捷键 整行 多行 复制与粘贴

   *****vim快捷键 整行 多行 复制与粘贴*****
复制:
    1)单行复制
    在命令模式下,将光标移动到将要复制的行处,按**yy**进行复制;
    2)多行复制
    在命令模式下,将光标移动到将要复制的首行处,按**nyy**复制n行;其中n为1、2、3……
    
粘贴:
    在命令模式下,将光标移动到将要粘贴的行处,按**p**进行粘贴
    
删除:
    dd:       删除当前所在行
    5dd :    删除从当前行至其后的5行内容
vim中撤销操作:
快捷键: u

恢复刚才撤销的动作:
快捷键: ctrl+r 

切换到底线命令模式,以在最底一行输入命令 
快捷键为    :

移动光标到行首/行尾
快捷键:HOME/END

上/下翻页
快捷键:PageUp/PageDown

批量缩进:tab键
快捷键:esc——>:开始行号,结束行号>
eg:
:2,9>
**vim翻半页**
ctr-d:向后翻半页
ctr-u:向前翻半页
**vim整整页**
ctr+f:向后翻整页
ctr+b:向前翻整页

vim跳首行——:1
vim跳尾行——:$
批量注释:

使用下面命令在指定的行首添加注释:
:起始行号,结束行号s/^/注释符/g

取消注释:
:起始行号,结束行号s/^注释符//g

eg:
在10 - 20行添加 # 注释
:10,20s/^/#/g

在10 - 20行删除 # 注释
:10,20s/^#//g

批量替换字符串:
:first_row,last_row s/old_str/new_str
eg:
:1,100s/ace2005/informationextractor

下面的命令把整个文件中的old的每次出现都改为new:
:1, $s / old / new / g
我们知道%等价于1,$,所以上行命令也可以这样写:
:% s/old/new/g

#linux统计文件个数
ls -l |grep "^-"|wc -l
# vim 中删除^M字符
单个文档的话,可以用vi打开,执行 :%s/^M//g 来去掉^M(注意:^M是ctrl+v,ctrl+m。先按住ctrl,然后按v m 即可。)

#查看当前目录
pwd
/storage/huggingface/bert-base-chinese
#切换根目录
cd /storage


二、文件相关操作

1.删除文件、文件夹:rm 
rm -rf ./tmp*   删除以tmp开头的文件夹
2.创建文件夹:mkdir
mkdir file_name
3.创建文件:touch
touch run_classifier.py
注意:linux的touch命令不常用,一般用来**修改文件时间戳**,或者**新建一个不存在的文件**。
4.移动文件、文件夹:mv
mv old_path new_path
5.重命名文件、文件夹:mv 
mv file
6.复制文件、文件夹:cp
cp ./a* ./myproduct/     复制a开头的文件
cp -r m* ./myproduct/   复制m开头的文件或文件夹(**要复制文件夹,必须加上-r !**)
7.删除XXX字符串开头的文件夹
rm -rf XXX*

8. 使用tar压缩文件
tar -zcvf test.tar.gz ./test/
该命令表示压缩当前文件夹下的文件夹test,压缩后缀名为test.tar.gz
如果不需要压缩成gz,只需要后缀为tar格式的,那么输入如下命令:
tar -cvf test.tar ./test/
9.使用tar解压文件
tar -xzvf test.tar.gz  
该命令表示把后缀为.tar.gz的文件解压到当前文件夹下。
如果压缩文件的后缀是.tar,没有gz,则使用命令:
tar -xvf test.tar

9.服务器文件传输
shaohd@wks00:~$ su - luckycat
Password: 
luckycat@wks00:~$ ls
triples.train.small.tsv

luckycat@wks00:~$ scp -P 10022 triples.train.small.tsv shaohd@192.168.10.198:data/
The authenticity of host '[192.168.10.198]:10022 ([192.168.10.198]:10022)' can't be established.
ECDSA key fingerprint is SHA256:Ft3f66+jL3pUw5U07qTy91b/R/c9IMt8XaUe/E2bESM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.10.198]:10022' (ECDSA) to the list of known hosts.
shaohd@192.168.10.198's password: 
triples.train.small.tsv                                        100%  225MB 191.2MB/s   00:01    

luckycat@wks00:~$ scp -r -P 22 patent_match/ luckycat@10.0.6.14:tagmaker/chinchilla/

[luckycat@node6 output]$ scp -P 22 predicate_predict.txt luckycat@10.0.6.13:/home/luckycat/

#wc用于计算字数,-c,-w,-l分别计算文件的Byte数、字数、或是列数
[jaxim@ip-172-20-9-101 notification_card]$ wc part-00000 
  109529  1091583 19445240 part-00000
[jaxim@ip-172-20-9-101 notification_card]$ wc -l part-00000 
109529 part-00000
[jaxim@ip-172-20-9-101 notification_card]$ wc -c part-00000 
19445240 part-00000
[jaxim@ip-172-20-9-101 notification_card]$ wc -w part-00000 
1091583 part-00000
[jaxim@ip-172-20-9-101 notification_card]$ 

su - luckycat:用su命令切换到luckycat身份;
scp -P 10022 triples.train.small.tsv shaohd@192.168.10.198:data/
10022为端口号,triples.train.small.tsv为文件, shaohd为用户名,192.168.10.198为ip,data/为文件夹。
scp -r -P 22 patent_match/ luckycat@10.0.6.14:tagmaker/chinchilla/
传输文件时需要将其改为scp -r.


## 三、进程相关
1、查看进程:ps (Process Status)
直接用**ps命令**,会显示所有进程的状态,通常结合**grep命令**查看某进程的状态。

2.grep:grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

**查看相应文件中是否包含相应正则匹配内容的数据**
```powershell
shaohd@wks00:~$ grep model batch_tagging_patent.py
"""Interact with a model"""
    with open('./model/kc_0.7_model.pickle', 'rb') as file:
        with open('./model/log/batch_tagging.log', "a", encoding="utf-8") as f:
        
shaohd@wks00:~$ grep model* batch_tagging_patent.py 
"""Interact with a model"""
    with open('./model/kc_0.7_model.pickle', 'rb') as file:
        with open('./model/log/batch_tagging.log', "a", encoding="utf-8") as f:
        
shaohd@wks00:~$ grep *model batch_tagging_patent.py 
"""Interact with a model"""
    with open('./model/kc_0.7_model.pickle', 'rb') as file:
        with open('./model/log/batch_tagging.log', "a", encoding="utf-8") as f:

ps是显示当前状态处于running的进程,grep表示在这些里搜索,而ps aux是显示所有进程和其状态。
ps aux输出格式:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
格式说明:
USER: 行程拥有者
PID: pid
%CPU: 占用的 CPU 使用率
%MEM: 占用的记忆体使用率
VSZ: 占用的虚拟记忆体大小
RSS: 占用的记忆体大小
TTY: 终端的次要装置号码 (minor device number of tty)

STAT: 该行程的状态,linux的进程有5种状态:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
注: 其它状态还包括W(无驻留页), <(高优先级进程), N(低优先级进程), L(内存锁页).

START: 行程开始时间
TIME: 执行的时间
COMMAND:所执行的指令

[luckycat@node5 shd]$ ps aux |grep python
root       1607  0.0  0.0 567644 17584 ?        Ssl   2019  66:31 /usr/bin/python -Es /usr/sbin/tuned -l -P
luckycat 106262  107  1.8 44232148 4794740 pts/1 Sl  10:49 328:49 python3 run_classifier.py --task_name=myproduct --data_dir=./data/ --output_dir=./model/output --do_train=true --do_eval=true --do_predict=true --vocab_file=./bert-master/chinese_L-12_H-768_A-12/vocab.txt --bert_config_file=./bert-master/chinese_L-12_H-768_A-12/bert_config.json --init_checkpoint=./bert-master/chinese_L-12_H-768_A-12/bert_model.ckpt --max_seq_length=300 --train_batch_size=6 --learning_rate=1e-5 --num_train_epochs=5
luckycat 120944  0.0  0.0 112720   972 pts/6    R+   15:56   0:00 grep --color=auto python

四、硬件资源

1.查看内存:free
显示系统内存的使用情况,包括物理内存、交换内存(swap)和内核缓冲区内存。

[luckycat@node5 shd]$ free
              total        used        free      shared  buff/cache   available
Mem:      263570040    25662804    14954612     6240264   222952624   229960900
Swap:             0           0           0

[luckycat@node5 shd]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           251G         24G         14G        6.0G        212G        219G
Swap:            0B          0B          0B

#每隔 3 秒输出一次内存的使用情况,直到你按下 ctrl + c
[luckycat@node5 shd]$ free -h -s 3
              total        used        free      shared  buff/cache   available
Mem:           251G         24G         14G        6.0G        212G        219G
Swap:            0B          0B          0B

              total        used        free      shared  buff/cache   available
Mem:           251G         24G         14G        6.0G        212G        219G
Swap:            0B          0B          0B

              total        used        free      shared  buff/cache   available
Mem:           251G         24G         14G        6.0G        212G        219G
Swap:            0B          0B          0B

              total        used        free      shared  buff/cache   available
Mem:           251G         24G         14G        6.0G        212G        219G
Swap:            0B          0B          0B

输出简介
下面先解释一下输出的内容:
Mem 行(第二行)是内存的使用情况。
Swap 行(第三行)是交换空间的使用情况。
total 列显示系统总的可用物理内存和交换空间大小。
used 列显示已经被使用的物理内存和交换空间。
free 列显示还有多少物理内存和交换空间可用使用。
shared 列显示被共享使用的物理内存大小。
buff/cache 列显示被 buffer 和 cache 使用的物理内存大小。
available 列显示还可以被应用程序使用的物理内存大小。

2.查看GPU: nvidia-smi

[luckycat@node5 shd]$ nvidia-smi
Mon Dec 21 16:27:21 2020       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.129      Driver Version: 410.129      CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla T4            Off  | 00000000:18:00.0 Off |                    0 |
| N/A   75C    P0    71W /  70W |  14499MiB / 15079MiB |     99%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0    106262      C   python3                                    14485MiB |
+-----------------------------------------------------------------------------+

五、xshell多屏显示

鼠标拖动相应的模块到右侧侧边栏处,出现淡蓝色时释放鼠标,即可实现双屏展示。效果图如下:
在这里插入图片描述

六、跳转登录服务器

ssh 10.0.6.14

然后输入密码即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值