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

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

相关文章
|
12天前
|
Shell Linux 程序员
【Linux】Shell 命令以及运行原理
【Linux】Shell 命令以及运行原理
|
4天前
|
Linux 应用服务中间件 nginx
linux小技巧: 可以补全命令 别名永久有效
linux小技巧: 可以补全命令 别名永久有效
|
4天前
|
缓存 关系型数据库 MySQL
linux 基本知识与命令
linux 基本知识与命令
|
4天前
|
网络协议 Linux 数据库
蓝易云 - Linux常用命令dhcpd命令
在使用dhcpd命令之前,需要确保已经正确配置了dhcpd.conf文件,该文件定义了DHCP服务器的行为和要分配的IP地址范围等信息。
10 0
|
4天前
|
Linux Docker 容器
蓝易云 - 【Linux】如何在linux系统重启或启动时执行命令或脚本(也支持docker容器内部)
以上就是在Linux系统和Docker容器中设置启动时运行命令或脚本的方法。希望对你有所帮助。
18 0
|
5天前
|
Linux 开发工具
蓝易云 - Linux虚拟机常用命令
以上就是一些常用的Linux命令,希望对你有所帮助。
17 0
|
6天前
|
存储 Linux 开发工具
Linux 基础(从环境搭建到基础命令)
Linux 基础(从环境搭建到基础命令)
|
8天前
|
存储 Linux 网络安全
在 Linux 中通过 SSH 执行远程命令时,无法自动加载环境变量(已解决)
SSH远程执行命令时遇到“命令未找到”问题,原因是Linux登录方式不同导致环境变量加载差异。解决方案:将环境变量写入`/etc/profile.d/`下的文件,或手动在命令前加载环境变量,如`source /etc/profile`。
|
9天前
|
关系型数据库 MySQL Java
1.Linux常用命令
1.Linux常用命令
35 1
|
13天前
|
Linux
【超全】Linux命令思维导图总结 值得收藏
【超全】Linux命令思维导图总结 值得收藏
17 0

热门文章

最新文章