专栏名称: SegmentFault思否
SegmentFault (www.sf.gg)开发者社区,是中国年轻开发者喜爱的极客社区,我们为开发者提供最纯粹的技术交流和分享平台。
目录
相关文章推荐
程序员小灰  ·  3个令人惊艳的DeepSeek项目,诞生了! ·  13 小时前  
程序猿  ·  “我真的受够了Ubuntu!” ·  2 天前  
程序猿  ·  “未来 3 年内,Python 在 AI ... ·  3 天前  
51好读  ›  专栏  ›  SegmentFault思否

最简洁明了的 Linux 常用命令

SegmentFault思否  · 公众号  · 程序员  · 2020-02-25 11:57

正文

本文转载于 SegmentFault 社区

作者: 胜飞





1. ls 命令


查看当前目录下可见的文件、文件夹及其相关权限
常用参数:-l 列表式查看
-al 查看所有,包括隐藏的文件、文件夹
[root@qinshengfei bin]# ls --color 以彩色显示
[root@qinshengfei bin]# ls -l 详情列出目录文件
[root@qinshengfei bin]# ls -a 显示所有文件,包括隐藏文件
[root@qinshengfei bin]# ls -al 列表显示所有文件
[root@qinshengfei bin]# ls -al|more 將目录內容分布显示

2. mkdir 创建文件夹


常用参数 :直接接文件夹名称
[root@qinshengfei /home]# mkdir test

3. pwd 显示当前工作目录


[root@qinshengfei bin]# pwd
/usr/bin <== 显示当前工作目录

4. cd 切换目录


[root@qinshengfei /root]# cd .. <== 回到上一级目录
[root@qinshengfei /]# cd <== 回到home目录
[root@qinshengfei root]# cd /usr/bin <== 到 /usr/bin 目录

5. rmdir 删除指定目录


如果要删除的目录里面有文件或文件夹,是无法移动的,这时,就需要加上参数 -rf 来强制操作删除。
[root@qinshengfei /root]# rmdir ./test <== 删除目录
[root@qinshengfei /root]# rmdir ./test2 -rf <== 删除目录及子目录、文件

6. rm 删除指令文件


[root@qinshengfei /root]# rm test

7. cp 就是 copy 的意思。 例如我们要把 .bashrc 这个文件复制到/home目录下,可以:


[root@qinshengfei /root]# cp .bashrc /home

8. mv 移动文件、文件夹


[root@qinshengfei /root]# mv test.txt /home

9. cat 打印文件内容在控制台上,例如要打印 mysql 的配置文件到控制上


[root@qinshengfei /mysql.conf.d]# cat mysqld.cnf

10. tail 按行显示文件内容


[root@qinshengfei /mysql.conf.d]# tail -n 5 mysqld.cnf

11. less


less命令可查看文件。它使用起来速度更快,而且您不会无意间修改文件。使用更少的光标,您可以使用向上和向下箭头键,PgUp和PgDn键以及Home和End键在文件中前后滚动。按Q键退出。
[root@qinshengfei /mysql.conf.d]# less log.txt

12. grep 管道,输出指定文件内容


例如使用 ps -aux 查询进程,我们只需要知道 tomcat 有不有运行,就可以使用管道指令『|』加入 grep 这个命令同时操作。
[root@qinshengfei /]# ps -aux|grep tomcat

13. find 查找文件


[root@qinshengfei /]# find / -name bin

14. tar -cvf 压缩文件


[root@qinshengfei /root]# tar -zcvf app.tar.gz app

15. gzip 压缩


也是一压缩命令,跟compress 很相似,指令的用法也相同!只是压缩后缀名 .gz !
[root@qinshengfei /root]# gzip -d xxxxx.gz

16. unzip 解压文件


[root@qinshengfei /root]# unzip app.zip 解压一个叫做 'app.zip'的文件

17. exit 退出登录



[root@qinshengfei /root]# exit

18. ping 与 windows 下的 ping 一样 ,测试两台电脑之间是否连通



[root@qinshengfei /root]# ping baidu.com

19. telnet 与 windows 下的一样 ,测试目标机端口开放


[root@qinshengfei /root]# telnet 47.2.30.289 8080

20. who 查看当前登录的所有用户


[root@qinshengfei /root]# who

21. su 切换用户


[root@qinshengfei /root]# su qinshengfei

22. uname uname会显示出关于系统的重要信息,如内核名称、主机名、内核版本、处理机类型等等,使用 uname -a 可以查看所有信息。


[root@qinshengfei /]# uname -a
Linux qinshengfei 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
[root@qinshengfei /]#

23. alias


使用alias命令可以给命令或命令序列指定自己的名称。然后,您可以输入您的简称,然后Shell将为您执行命令或命令序列。
[root@qinshengfei /]# alias pf="ps -e | grep $1"
[root@qinshengfei /]# pf tomcat

24. chmod 修改文件、文件夹权限的命令


0: No permission
1: Execute permission
2: Write permission
3: Write and execute permissions
4: Read permission
5: Read and execute permissions
6: Read and write permissions
7: Read, write and execute permissions
[root@qinshengfei /]# chmod 777 app -r <== -r 连同子目录权限一起修改

25. chown


可以使用chown更改文件的所有者或组,或两者。必须提供所有者和组的名称,以:字符分隔。
[root@qinshengfei /]# chown dave:mary example.txt

26. curl


curl命令是从统一资源定位器(URL)或Internet地址检索信息和文件的工具。
[root@qinshengfei /]# curl http://www.baidu.com index.html

27. echo


echo命令将文本字符串打印(回显)到终端窗口。也可以将字符串打印到文件。
[root@qinshengfei /]# echo "hello world"
hello world
[root@qinshengfei /]#

28. free


free命令为您提供计算机内存使用情况的摘要。它对主随机存取存储器(RAM)和交换存储器都执行此操作。-h(人类)选项用于提供人类友好的数字和单位。没有此选项,数字以字节为单位。
[root@qinshengfei /]# free
total used free shared buff/cache available
Mem: 8000348 1554508 4549432 576 1896408 6194856
Swap: 0 0 0
[root@qinshengfei /]#

29. history


history命令列出了您先前在命令行上发出的命令。您可以通过键入感叹号来重复历史记录中的任何命令!以及历史记录列表中的命令编号。
[root@qinshengfei /]#
[root@qinshengfei /]# history
1 yum install docker
2 yum install nginx
3 yum -y install docker-ce

30. kill


我们将使用上面关于别名命令的部分中的 ps 和 grep 技巧。 我们可以搜索快门过程并获取其 PID,如下所示:

[root@qinshengfei /]# ps -ef|grep nginx
root 31884 22980 0 16:19 pts/0 00:00:00 grep --color=auto nginx
root 32400 1 0 Feb18 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 32401 32400 0 Feb18 ? 00:00:00 nginx: worker process
nginx 32402 32400 0 Feb18 ? 00:00:00 nginx: worker process
[root@qinshengfei /]# kill -9 32400

31. passwd


passwd命令使您可以更改用户密码。只需键入passwd即可更改您自己的密码。
[root@qinshengfei /]# sudo passwd mary

32. ssh


使用ssh命令建立与远程Linux计算机的连接并登录到您的帐户。要建立连接,您必须提供您的用户名以及远程计算机的IP地址或域名。在此示例中,用户mary以192.168.4.23登录到计算机。建立连接后,将要求她输入密码。
[root@qinshengfei /]# ssh mary@192.168.4.23
mary@192.168.4.23's password:

33. df 查看系统磁盘的使用情况


[root@qinshengfei /]# df






请到「今天看啥」查看全文