> 文档中心 > Linux常用命令大全【一】

Linux常用命令大全【一】


大家好,我是早九晚十二,目前是做运维相关的工作。写博客是为了积累,希望大家一起进步!
我的主页:早九晚十二
Linux常用命令大全【一】

首先祝大家端午快乐!!!
你们吃粽子和大闸蟹了吗???
Linux常用命令大全【一】

今天我们介绍一下Linux常用命令!
这次只有20个,剩余的等待下期!
只讲常用的参数,有其他的小伙伴们下来自行研究哈

文章目录

    • 指导命令【2个】
      • man
      • help
    • 文件操作命令【18个】
      • ls
      • cd
      • cp
      • find
      • mkdir
      • mv
      • pwd
      • rm
      • rename
      • rmdir
      • tree
      • touch
      • basename
      • dirname
      • chattr
      • lsattr
      • file
      • md5sum

(小声bb:文章很长,请耐心看完)Linux常用命令大全【一】

指导命令【2个】

man

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

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

Linux常用命令大全【一】

help

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

Linux常用命令大全【一】

文件操作命令【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 .ssh0   2.2    .bash_logout   .cache  .lesshst  .pydistutils.cfg  socialnetwork.cer  .tcshrc查看当前详细信息[root@VM-8-9-centos ~]# ls -ltotal 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 -lrsttotal 244 -rw-r--r-- 1 root root    4 Dec 28 17:29 2.24 -rw-r--r-- 1 root root    2 Dec 28 17:31 24 -rw-r--r-- 1 root root 1220 Jan 26 20:43 socialnetwork.cer0 -rw-r--r-- 1 root root    0 Jan 26 20:43 socialnetwork.key4 -rw-r--r-- 1 root root    3 Feb 22 17:04 404.html4 -rw-r--r-- 1 root root    2 Apr 14 11:46 04 -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 ip1rm: 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 testtest|-- 1`-- test2 directories, 0 files

touch

用于创建文件

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

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

今天我们的Linux 常用命令大全[上],20个指令就说完了,后面还会接着讲二、三…N,你们的点赞越多,我就更的越快。
Linux常用命令大全【一】
我就是我,一个专心工作的搬砖人!