Linux常用命令大全

简介: 一文掌握20个命令,你,真的赚大了!

大家好,我是早九晚十二,目前是做运维相关的工作。写博客是为了积累,希望大家一起进步!

image.png

今天我们介绍一下Linux常用命令!
这次只有20个,剩余的等待下期!
只讲常用的参数,有其他的小伙伴们下来自行研究哈
(小声bb:文章很长,请耐心看完)!image.png

指导命令【2个】

man

查看命令用法,常用格式为man XXX
比如查看ls用法

[root@VM-8-9-centos ~]# man ls

image.png

help

获取内置命令的帮助,如查看cd的帮助

image.png

文件操作命令【18个】

ls

即为list,主要是查看目录下的文件及信息。

查看当前目录结构
[root@VM-8-9-centos ~]# ls 
0  1.txt  2  2.2  404.html  socialnetwork.cer  socialnetwork.key
查看隐藏文件
[root@VM-8-9-centos ~]# ls -a
.   1.txt  404.html       .bash_profile  .config   .pip              .rediscli_history  socialnetwork.key  .viminfo
..  2      .bash_history  .bashrc        .cshrc    .pki              .rnd               .ssh
0   2.2    .bash_logout   .cache         .lesshst  .pydistutils.cfg  socialnetwork.cer  .tcshrc
查看当前详细信息
[root@VM-8-9-centos ~]# ls -l
total 24
-rw-r--r-- 1 root root    2 Apr 14 11:46 0
-rw-r--r-- 1 root root   16 Apr 26 09:19 1.txt
-rw-r--r-- 1 root root    2 Dec 28 17:31 2
-rw-r--r-- 1 root root    4 Dec 28 17:29 2.2
-rw-r--r-- 1 root root    3 Feb 22 17:04 404.html
-rw-r--r-- 1 root root 1220 Jan 26 20:43 socialnetwork.cer
-rw-r--r-- 1 root root    0 Jan 26 20:43 socialnetwork.key
按时间排序查看
[root@VM-8-9-centos ~]# ls -lrst
total 24
4 -rw-r--r-- 1 root root    4 Dec 28 17:29 2.2
4 -rw-r--r-- 1 root root    2 Dec 28 17:31 2
4 -rw-r--r-- 1 root root 1220 Jan 26 20:43 socialnetwork.cer
0 -rw-r--r-- 1 root root    0 Jan 26 20:43 socialnetwork.key
4 -rw-r--r-- 1 root root    3 Feb 22 17:04 404.html
4 -rw-r--r-- 1 root root    2 Apr 14 11:46 0
4 -rw-r--r-- 1 root root   16 Apr 26 09:19 1.txt

cd

即为change directory,主要是切换目录使用

切换到家目录
[root@VM-8-9-centos ~]# cd ~  
切换到上次工作的目录
[root@VM-8-9-centos ~]# cd -
/root
切换到上级目录
[root@VM-8-9-centos ~]# cd ..
切换到当前目录
[root@VM-8-9-centos /]# cd .
[root@VM-8-9-centos /]#

cp

即为copy,用于复制文件或者文件

将ip拷贝为ip1
[root@VM-8-9-centos app]# cp ip ip1
将目录php复制到php7
[root@VM-8-9-centos app]# cp -r php php7
强制复制(忽略提示)
[root@VM-8-9-centos app]# \cp ip1 ip1

find

用于查找指定文件,目录等,可指定时间,深度等关键字,可以grep使用

查找1.txt
[root@VM-8-9-centos app]# find ./ -name 1.txt
查找1 文件格式
[root@VM-8-9-centos app]# find ./ -name 1 -type f
查找1 目录格式
[root@VM-8-9-centos app]# find ./ -name 1 -type d

mkdir

即为make directories 意思是创建目录

创建目录,名为test
[root@VM-8-9-centos app]# mkdir test
在test目录中创建test子目录
[root@VM-8-9-centos app]# mkdir test/test -p

mv

即为move,移动,也可用作重命名使用

将目录1移动到test目录
[root@VM-8-9-centos app]# mv 1 test/
将2重命名为2222
[root@VM-8-9-centos app]# mv 2 2222

pwd

用于查看当前所在路径

[root@VM-8-9-centos app]# pwd
/app

rm

即为remove,用于删除文件或者目录

删除ip1文件,需输入y
[root@VM-8-9-centos app]# rm ip1
rm: remove regular file ‘ip1’? y
强制删除2,忽略提醒
[root@VM-8-9-centos app]# rm -rf 2

rename

用于重命名文件

将1改成111,对1.sh文件操作
[root@VM-8-9-centos app]# rename  1 111 1.sh

rmdir

即为remove empty directorie。删除空目录

2222为空目录,删除成功,但是conf不是空目录,所以无法删除
[root@VM-8-9-centos app]# rmdir  2222/
[root@VM-8-9-centos app]# rmdir  conf/
rmdir: failed to remove ‘conf/’: Directory not empty

tree

查看目录结构

查看test树结构,两个目录,零文件
[root@VM-8-9-centos app]# tree test
test
|-- 1
`-- test

2 directories, 0 files

touch

用于创建文件

创建一个test3的文件
[root@VM-8-9-centos app]# touch test3
[root@VM-8-9-centos app]# ls test3
test3

basename

用于查看目录名或文件名,常用于shell脚本

查看test3目录名称
[root@VM-8-9-centos app]# basename test3 
test3

dirname

用于查看文件或目录路径,常用于shell脚本

查看test2路径,.代表当前
[root@VM-8-9-centos app]# dirname test2
.

chattr

用于改变文件的扩展属性

更改1.txt为可追加状态,只允许追加,不允许删除或更改
[root@VM-8-9-centos app]# chattr +a 1.txt 
[root@VM-8-9-centos app]# rm -f 1.txt 
rm: cannot remove ‘1.txt’: Operation not permitted
[root@VM-8-9-centos app]# echo 1111 > 1.txt 
-bash: 1.txt: Operation not permitted
[root@VM-8-9-centos app]# echo 1111 >> 1.txt
撤销a属性,可删除
[root@VM-8-9-centos app]# chattr -a 1.txt 
[root@VM-8-9-centos app]# rm -f 1.txt

可选参数

i 无法对文件进行修改;若对目录设置了该参数,则仅能修改其中的子文件内容而不能新建或删除文件
a 仅允许补充(追加)内容,无法覆盖/删除内容(Append Only)
S 文件内容在变更后立即同步到硬盘(sync)
s 彻底从硬盘中删除,不可恢复(用0填充原文件所在硬盘区域)
A 不再修改这个文件或目录的最后访问时间(atime)
b 不再修改文件或目录的存取时间
D 检查压缩文件中的错误
d 使用dump命令备份时忽略本文件/目录 c 默认将文件或目录进行压缩
u 当删除该文件后依然保留其在硬盘中的数据,方便日后恢复
t 让文件系统支持尾部合并(tail-merging)
x 可以直接访问压缩文件中的内容

lsattr

用于查看文件扩展属性

[root@VM-8-9-centos app]# lsattr 1.txt 
-------------e-- 1.txt
[root@VM-8-9-centos app]# chattr +a 1.txt 
[root@VM-8-9-centos app]# lsattr 1.txt 
-----a-------e-- 1.txt
[root@VM-8-9-centos app]#

file

显示文件的类型

未输入内容显示空,输入后显示为ASCII格式的txt文本文件
[root@VM-8-9-centos app]# file 1.txt 
1.txt: empty
[root@VM-8-9-centos app]# echo 1111 >> 1.txt 
[root@VM-8-9-centos app]# file 1.txt 
1.txt: ASCII text

md5sum

查看或者计算md5值

文件产生更改后,md5值一定会变化,目录同理
[root@VM-8-9-centos app]# md5sum 1.txt 
1f18348f32c9a4694f16426798937ae2  1.txt
[root@VM-8-9-centos app]# echo 111.1111>> 1.txt 
[root@VM-8-9-centos app]# md5sum 1.txt 
a1bedceb11eae6f435a7b88a70043d0c  1.txt

我就是我,一个专心工作的搬砖人!

相关文章
|
3月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
475 1
二、Linux文本处理与文件操作核心命令
|
3月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
325 137
|
3月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
760 57
|
6月前
|
JSON 自然语言处理 Linux
linux命令—tree
tree是一款强大的Linux命令行工具,用于以树状结构递归展示目录和文件,直观呈现层级关系。支持多种功能,如过滤、排序、权限显示及格式化输出等。安装方法因系统而异常用场景包括:基础用法(显示当前或指定目录结构)、核心参数应用(如层级控制-L、隐藏文件显示-a、完整路径输出-f)以及进阶操作(如磁盘空间分析--du、结合grep过滤内容、生成JSON格式列表-J等)。此外,还可生成网站目录结构图并导出为HTML文件。注意事项:使用Tab键补全路径避免错误;超大目录建议限制遍历层数;脚本中推荐禁用统计信息以优化性能。更多详情可查阅手册mantree。
584 143
linux命令—tree
|
2月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
545 2
|
3月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
342 0
Linux内存问题排查命令详解
|
3月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
322 16
|
5月前
|
监控 Linux 网络安全
Linux命令大全:从入门到精通
日常使用的linux命令整理
936 13
|
6月前
|
Linux 网络安全 数据安全/隐私保护
使用Linux系统的mount命令挂载远程服务器的文件夹。
如此一来,你就完成了一次从你的Linux发车站到远程服务器文件夹的有趣旅行。在这个技术之旅中,你既探索了新地方,也学到了如何桥接不同系统之间的距离。
1137 21
|
6月前
|
监控 Linux
Linux系统中使用df命令详解磁盘使用情况。
`df`命令是Linux系统管理员和用户监控和管理磁盘空间使用的重要工具。掌握它的基本使用方法和选项可以帮助在必要时分析和解决空间相关问题。简洁但功能丰富,`df`命令确保了用户可以快速有效地识别和管理文件系统的空间使用情况。
483 13

热门文章

最新文章