No title
你必须要知道的30个 Linux 命令
- pwd
列出当前所在目录
2
/mnt/c/Users/Matthew/Desktop
- cd
文件夹切换
2
root@matthew:/mnt/c/Users/Matthew/Downloads$快捷方式:
2
3
cd # 直接到home目录
cd - # 退回到上一次目录
- ls
列出当前文件夹内容
2
Captures desktop.ini快捷方式
2
3
ls -a # 列出隐藏文件
ls -al # 列出当前文件夹内容以及详情,包括文件权限,大小,拥有者等等
- cat
通过标准输出查看文件内容
2
123如何使用
2
3
cat 1.txt 2.txt>3.txt # 把1.txt和2.txt文件内容拼接起来输出到新文件3.txt
cat 1.txt | tr a-z A-Z >3.txt # 将1.txt文件内容小写转大写,然后输出到3.txt
- cp
把当前文件夹下文件复制到其他文件夹下
- mv
主要用于移动文件,也可以用来重命名文件
2
root@matthew:/mnt/c/Users/Matthew/Desktop/test$ mv 1.txt out.txt # 将当前文件夹下1.txt文件名改为out.txt
- mkdir
创建文件夹
快捷方式
2
mkdir -p p1/parentDir/p2 # 在已经创建的文件夹p1和p2之间创建新文件夹parentDir, p2成为parentDir的子文件夹
- rmdir
删除文件夹,但是只允许你删除空文件夹
- rm
删除文件夹以及文件夹内容
常用命令
2
rm -rf dir2 ## 强制删除文件夹dir2以及内容
- touch
创建新文件
- locate
搜索文件
2
3
4
5
/usr/lib/python3/dist-packages/twisted/python/_pydoctortemplates/index.html
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel.other/index.html /usr/share/doc/gdisk/index.html
/usr/share/doc/python3/python-policy.html/index.html
/usr/share/doc/shared-mime-info/shared-mime-info-spec.html/index.html注意
locate 与 find 不同: find 是去硬盘找,locate 只在 /var/lib/slocate 资料库中找
locate 的速度比 find 快,它并不是真的查找,而是查数据库
- find
在给定的文件夹内搜索文件或文件夹
2
./3.txt常用命令
2
3
find . -iname tran.txt # 在当前文件夹下寻找tran.txt文件,并且不区分大小写
find . -type d -name dir # 在当前文件夹下找dir文件夹
- grep
文件内容搜索
常用命令
2
grep -E -i -w '123|hello' index.js # index.js文件里搜索123或者hello,区分大小写,并且使用正则匹配
- sudo
以管理员权限运行
- df
查看系统磁盘使用情况,展示单位为%或者KB,使用
df -m以MB展示磁盘使用情况
- du
查看文件夹和文件的磁盘占用情况
注意:磁盘占用情况不等于文件大小
2
3
4
5
6
7
8
9
16 jquery-ui-table/.git/hooks
0 jquery-ui-table/.git/inf
108 jquery-ui-table/.git/objects/pack
108 jquery-ui-table/.git/objects
124 jquery-ui-table/.git
40 jquery-ui-table/src
40 jquery-ui-table/test
204 jquery-ui-table常用命令
- head
展示文件前几行内容,默认前10行
2
...常用命令
- tail
和head类似,展示后面几行
- diff
文件内容逐行对比
2
3
5d4
< world
- chmod
修改文件的读写可执行权限
- chown
修改文件的所有权
- kill
终止进程
- ping
测试与服务器连接状况
2
3
4
5
PING baidu.com (39.156.69.79) 56(84) bytes of data. 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=1 ttl=52
time=28.0ms 64 bytes from 39.156.69.79 (39.156.69.79): icmp_seq=2 ttl=52 time=30.9ms 64 bytes from 39.156.69.79 (
39.156.69.79): icmp_seq=3 ttl=52 time=123 ms ... --- baidu.com ping statistics --- 34 packets transmitted, 34 received,
0% packet loss, time 33235ms rtt min/avg/max/mdev = 27.417/39.384/123.661/22.443 ms
- wget
下载文件
2
3
4
5
6
7
8
9
10
11
12
--2021-04-16 18:27:05-- https://baidu.com.cn/
Resolving baidu.com.cn (baidu.com.cn)... 39.156.69.79, 220.181.38.148
Connecting to baidu.com.cn (baidu.com.cn)|39.156.69.79|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://www.baidu.com/ [following]
--2021-04-16 18:27:06-- http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 36.152.44.95, 36.152.44.96
Connecting to www.baidu.com (www.baidu.com)|36.152.44.95|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’
- uname
打印Unix系统名称
2
Linux
- top
持续监听进程运行状态
- history
查询输入记录
2
3
268 ping baidu.com 269 wget htts://baidu.com.cn 270 wget https://baidu.com.cn
279 history | grep baidu
- man
查看Linux中的指令帮助、配置文件帮助和编程帮助等信息
- echo
输出指定的字符串
常用命令
2
3
root@matthew:/mnt/c/Users/Matthew/Desktop/test$ cat name.txt
Hello, my name is John
- zip, unzip
压缩,解压文件
2
3
4
5
6
7
8
9
root@matthew:/mnt/c/Users/Matthew/Desktop/test$ zip -r out.zip .
adding: 2.txt (deflated 4%)
adding: 3.txt (deflated 6%)
adding: dir/ (stored 0%)
adding: dir/index.html (stored 0%)
adding: dir/index.js (deflated 41%)
adding: dir/name.txt (stored 0%)
adding: dir/ss.tex (stored 0%)
- hostname
查看主机名
2
matthew
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
 Comment


