常用命令

新建

1
2
# 在当前目录下新建 test 文件夹
$mkdir test

查找

简单查找

1
2
3
4
5
6
7
8
9
$ls -l 
- 简写为ll -查看目录下文件

$less file
? 向上查找
/ 向下查找

n 使用查找后,跳到下个匹配位置
N 跳至上一个匹配位置

正则表达式搜索文件

1
2
3
4
5
6
7
8
9
$egrep -i -a1 'loadWithdrawalacc[a-zA-Z -]+0324'  2goportal.log
-i 忽略大小写
-b1 匹配前一行
-a1 包含被匹配后一行

egrep -i 'action.*K00660232' 2goportal.log > K00660232.log
-i 忽略大小写
* 匹配任意字符
> K00660232.log #意思是按前面的正则匹配出来的所有行,另存为一份文件(名称:K00660232.log)
1
2
3
4

su #进入root权限
exit #退出su 进入的root权限
su test #切换用户为 test

复制

1
2
3
4
5
6
Linux命令,复制文件夹
$cp -r MR BOUAT27
将 MR文件夹所有文件 复制到 BOUAT27(BOUAT27 不存在)

如果BOUAT27 已经存在
$cp -r MR/. BOUAT27

复制 A Linux 到 B Linux

1
2
3
4
linux 复制命令:scp -r user@remotehost:/home/backups /home/slynux
- 远程机A目录:user@remotehost:/home/backups
- 本机A 目录: /home/slynux
*从远程机目录A 复制到 本机 目录A,或者调换 目录,前后顺序,即从本机复制到远程机
1
2
3
4
5
6
7
8
9
$rsync -chavzP --stats  --exclude-from="./exclude_path.txt" tomcat@192.168.1.40:/home/tomcat/levana-test test2022

#./exclude_path.txt 文件内容如下
tttt //被忽略的指定目录


$rsync -chavzP --stats --exclude="test*" tomcat@192.168.1.40:/home/tomcat/levana-test test2022

test* // 被忽略文件夹名称规则 -正则表达式

压缩/解压

ZIP

1
2
3
4
5
6
7
8
9
10
11
12
zip all.zip *.jpg   #将所有.jpg的文件压缩成一个zip包

unzip all.zip #将all.zip中的所有文件解压到当前目录中

unzip all.zip -d all #将all.zip 中的所有文件解压到当前目录中的all文件夹中

zip -r hy.zip hy #将当前目录下的hy文件夹压缩为hy.zip

zip -r hy.zip hy 123.txt #将当前目录下的hy文件夹和123.txt压缩为hy.zip

tar -zxvf ×××.tar.gz
tar -jxvf ×××.tar.bz2

编辑

1
2
vi /test.txt
:%s/aaa/bbb/g #批量替换 aaa 为 bbb

比较文件内容

1
diff a.txt b.txt

文件下载

1
rsync -avc Administrator@192.168.2.122:/cygdrive/d/Log/$1_goxml/$2_GoXML_*_$3_*.tgz /home/goxml/temp/

Linux 授权脚本执行权限,文件所有者可以自行授权执行权限

1
2

$chmod +x *.sh

授权

1
2
3
4
5
6
#授权用户组 (组名 users)(dir 目录名)
$chgrp -R users dir
#授权所有者(用户名 user)
$chown -R users dir

chmod u+x ./sh_start.sh

运维

文件sha412/md5 校验

1
2
3
4
5
6
7
8
// linux
sha512sum <filepath>
md5sum <filepath>

//window
CertUtil -hashfile <filepath> SHA512
CertUtil -hashfile <filepath> MD5
Get-FileHash <filepath> -Algorithm MD5

Windows 上传文件到 Linux

Windows 系统通过 WinSCP 上传文件到 Linux 云服务器:https://cloud.tencent.com/document/product/213/2131