Linux常用命令实例带注释

简介: Linux常用命令实例带注释

Linux命令


ls命令

# 查看当前目录下文件
[root@bogon ~]# ls
anaconda-ks.cfg
# 查看隐藏文件
[root@bogon ~]# ls -a
.  ..  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  .lesshst  .tcshrc
# 查看详细信息
[root@bogon ~]# ls -l
总用量 4
-rw-------. 1 root root 1413 12月  8 00:38 anaconda-ks.cfg
# 简写
[root@bogon ~]# ll
总用量 4
-rw-------. 1 root root 1413 12月  8 00:38 anaconda-ks.cfg
# 组合使用 
[root@bogon ~]# ls -la
总用量 32
dr-xr-x---.  2 root root  151 12月 11 13:15 .
dr-xr-xr-x. 17 root root  224 12月 11 10:56 ..
-rw-------.  1 root root 1413 12月  8 00:38 anaconda-ks.cfg
-rw-------.  1 root root 1789 12月 11 21:40 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-------.  1 root root   48 12月 11 13:15 .lesshst
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
# -h 参数作用:以较人性化的方式显示文件
[root@bogon ~]# ls -lah
总用量 32K
dr-xr-x---.  2 root root  151 12月 11 13:15 .
dr-xr-xr-x. 17 root root  224 12月 11 10:56 ..
-rw-------.  1 root root 1.4K 12月  8 00:38 anaconda-ks.cfg
-rw-------.  1 root root 1.8K 12月 11 21:40 .bash_history
-rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
-rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
-rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
-rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
-rw-------.  1 root root   48 12月 11 13:15 .lesshst
-rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
# 查看其它目录下文件
[root@bogon ~]# ls /tmp
ks-script-rGMaou                                                         vmware-root_653-4013264490  vmware-root_662-2689143848
systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt  vmware-root_654-2688750646  vmware-root_664-2722697761
test1                                                                    vmware-root_660-2697467306  vmware-root_682-2697467275
test2                                                                    vmware-root_661-4013919860  yum.log
# 配合-l参数使用
[root@bogon ~]# ls -l /tmp
总用量 4
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
drwx------. 2 root root   6 12月  8 09:07 vmware-root_653-4013264490
drwx------. 2 root root   6 12月 10 23:53 vmware-root_654-2688750646
drwx------. 2 root root   6 12月 11 09:30 vmware-root_660-2697467306
drwx------. 2 root root   6 12月 15 00:04 vmware-root_661-4013919860
drwx------. 2 root root   6 12月 11 19:23 vmware-root_662-2689143848
drwx------. 2 root root   6 12月 11 18:07 vmware-root_664-2722697761
drwx------. 2 root root   6 12月  8 00:39 vmware-root_682-2697467275
-rw-------. 1 root root   0 12月  8 00:34 yum.log
[root@bogon tmp]# ll /
总用量 16
lrwxrwxrwx.   1 root root    7 12月  8 00:34 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 12月  8 00:38 boot
drwxr-xr-x.  19 root root 3100 12月 15 09:26 dev
drwxr-xr-x.  75 root root 8192 12月 16 00:25 etc
drwxr-xr-x.   3 root root   23 12月  8 00:37 home
lrwxrwxrwx.   1 root root    7 12月  8 00:34 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 12月  8 00:34 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 4月  11 2018 media
drwxr-xr-x.   2 root root    6 4月  11 2018 mnt
drwxr-xr-x.   2 root root    6 4月  11 2018 opt
dr-xr-xr-x. 126 root root    0 12月 15 09:26 proc
dr-xr-x---.   2 root root  151 12月 11 13:15 root
drwxr-xr-x.  25 root root  740 12月 16 00:25 run
lrwxrwxrwx.   1 root root    8 12月  8 00:34 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 4月  11 2018 srv
dr-xr-xr-x.  13 root root    0 12月 15 09:26 sys
drwxrwxrwt.   9 root root  156 12月 16 00:26 tmp
drwxr-xr-x.  13 root root  155 12月  8 00:34 usr
drwxr-xr-x.  19 root root  267 12月  8 00:39 var
[root@bogon tmp]# ls -ld
drwxrwxrwt. 9 root root 156 12月 16 00:26 .
# 参数-d
[root@bogon tmp]# ls -d
.

mkdir

# 以相对路径创建文件夹
[root@bogon tmp]# mkdir haha
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 2 root root   6 12月 15 00:45 haha
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log
# 以绝对路径创建文件夹
[root@bogon tmp]# mkdir /tmp/haha1
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 2 root root   6 12月 15 00:45 haha
drwxr-xr-x. 2 root root   6 12月 15 00:46 haha1
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log
# 同时创建多个文件夹
[root@bogon tmp]# mkdir dir1 dir2
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir1
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir2
drwxr-xr-x. 2 root root   6 12月 15 00:45 haha
drwxr-xr-x. 2 root root   6 12月 15 00:46 haha1
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log
# -p参数作用对比
[root@bogon tmp]# mkdir haha2/haha3
mkdir: 无法创建目录"haha2/haha3": 没有那个文件或目录
# 递归创建文件
[root@bogon tmp]# mkdir -p haha2/haha3 
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir1
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir2
drwxr-xr-x. 2 root root   6 12月 15 00:45 haha
drwxr-xr-x. 2 root root   6 12月 15 00:46 haha1
drwxr-xr-x. 3 root root  19 12月 15 00:50 haha2
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log
[root@bogon tmp]# ll haha2
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 00:50 haha3

rmdir

[root@bogon tmp]# rmdir
rmdir: 缺少操作数
Try 'rmdir --help' for more information.
[root@bogon tmp]# rmdir haha2
rmdir: 删除 "haha2" 失败: 目录非空
# 只能删除空目录,不常用
[root@bogon tmp]# rmdir haha1
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir1
drwxr-xr-x. 2 root root   6 12月 15 00:49 dir2
drwxr-xr-x. 2 root root   6 12月 15 00:45 haha
drwxr-xr-x. 3 root root  19 12月 15 00:50 haha2
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log

cp

[root@bogon tmp]# cp haha2/haha3 haha
cp: 略过目录"haha2/haha3"
# 复制文件夹需加上参数 -r
[root@bogon tmp]# cp -r haha2/haha3 haha
[root@bogon tmp]# ll haha2
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 00:50 haha3
[root@bogon tmp]# ll haha
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 00:56 haha3  # 注意:两个文件时间不相同
# 保留目录属性复制,比如时间
[root@bogon tmp]# cp -rp haha2/haha3 dir1 
[root@bogon tmp]# ll dir1
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 00:50 haha3
[root@bogon tmp]# ll haha2
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 00:50 haha3  # 注意:两个文件时间相同
# 同时复制多个文件
[root@bogon tmp]# cp -r dir1 dir2 haha
[root@bogon tmp]# ll haha
总用量 0
drwxr-xr-x. 3 root root 19 12月 15 01:02 dir1
drwxr-xr-x. 2 root root  6 12月 15 01:02 dir2
drwxr-xr-x. 2 root root  6 12月 15 00:56 haha3
# 复制到 haha/ 目录下并 改名为 rename
[root@bogon tmp]# cp -r dir1 haha/rename
[root@bogon tmp]# ll haha
总用量 0
drwxr-xr-x. 3 root root 19 12月 15 01:02 dir1
drwxr-xr-x. 2 root root  6 12月 15 01:02 dir2
drwxr-xr-x. 2 root root  6 12月 15 00:56 haha3
drwxr-xr-x. 3 root root 19 12月 15 01:06 rename

rm

# -r删除目录
[root@bogon tmp]# rm -r dir1
rm:是否进入目录"dir1"? y
rm:是否删除目录 "dir1/haha3"?y
rm:是否删除目录 "dir1"?y
# -f 直接删除,不再询问
[root@bogon tmp]# rm -f dir2
rm: 无法删除"dir2": 是一个目录
[root@bogon tmp]# rm -rf dir2
[root@bogon tmp]# ll
总用量 4
drwxr-xr-x. 6 root root  57 12月 15 01:06 haha
drwxr-xr-x. 3 root root  19 12月 15 00:50 haha2
-rwx------. 1 root root 836 12月  8 00:38 ks-script-rGMaou
drwx------. 3 root root  17 12月 15 00:04 systemd-private-7ba72f0aad2a4bf0acb2fee2d9025397-chronyd.service-iMXRBt
drwxr-xr-x. 3 root root  82 12月 11 13:23 test1
drwxr-xr-x. 2 root root   6 12月 11 11:06 test2
-rw-------. 1 root root   0 12月  8 00:34 yum.log
# 清空 /tmp/目录  通配符*
[root@bogon tmp]# rm -rf /tmp/*
[root@bogon tmp]# ll
总用量 0
[root@192 tmp]# rm -rf .
rm: refusing to remove "." or ".." directory: skipping "."
# 清空当前目录
[root@192 tmp]# rm -rf ./*
[root@192 tmp]# ll
总用量 0

mv

[root@192 tmp]# rm -rf /tmp/*
[root@192 tmp]# ll
总用量 0
[root@192 tmp]# mkdir test1
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:41 test1
# 重命名
[root@192 tmp]# mv test1 test2
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:41 test2
[root@192 tmp]# mkdir dir
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:42 dir
drwxr-xr-x. 2 root root 6 12月 15 09:41 test2
# 剪切/移动 文件 并改名
[root@192 tmp]# mv dir test2/dir1
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 3 root root 18 12月 15 09:42 test2
[root@192 tmp]# ll test2
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:42 dir1
# 移动dir1 到当前目录
[root@192 tmp]# mv test2/dir1 .
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:42 dir1
drwxr-xr-x. 2 root root 6 12月 15 09:44 test2

touch

# 创建文件   
[root@192 tmp]# touch typroa
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:42 dir1
drwxr-xr-x. 2 root root 6 12月 15 09:44 test2   # 文件夹为"d"
-rw-r--r--. 1 root root 0 12月 15 09:49 typroa   # 文件前缀为"-"
[root@192 tmp]# touch p~`!@#$%^&*()_+=-{}
-bash: !@#$%^: event not found
[root@192 tmp]# touch %$#&~
[1] 15878
-bash: /root: 是一个目录
[1]+  完成                  touch %$#
# 同时创建多个文件 
[root@192 tmp]# touch haha1 haha2
[root@192 tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 6 12月 15 09:42 dir1
-rw-r--r--. 1 root root 0 12月 15 09:58 haha1
-rw-r--r--. 1 root root 0 12月 15 09:58 haha2
drwxr-xr-x. 2 root root 6 12月 15 09:44 test2
-rw-r--r--. 1 root root 0 12月 15 09:49 typroa

cat/tac

# 正序查看
[root@192 etc]# cat issue
\S
Kernel \r on an \m
# 反序查看
[root@192 etc]# tac issue
Kernel \r on an \m
\S

more

# 回车换行,空格翻页,q退出 ,可显示当前进度
[root@192 etc]# more services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
......

less


  • 下键、回车 【向下换行】
  • f键、空格、pageDown 【向下翻页】
  • PageUp 【向上翻页】
  • 上键 【向上换行】
  • “:/关键字” 【冒号后输入斜杠“/",进入搜索状态,输入关键字查询】
  • n键 【跳转下一个匹配项】
  • 区别: 不显示进度百分比
  • q键 【退出浏览】

head/tail

# 指定查看前3行内容
[root@192 etc]# head -n 3 services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# 参数与指定行数不加空格
[root@192 etc]# head -n2 services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
# 默认10行,不写参数 -n
[root@192 etc]# head services
# /etc/services:
# $Id: services,v 1.55 2013/04/14 ovasik Exp $
#
# Network services, Internet style
# IANA services version: last updated 2013-04-10
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# 指定查看后两行内容
[root@192 etc]# tail -n2 services
iqobject        48619/udp               # iqobject
matahari        49000/tcp               # Matahari Broker
[root@192 etc]# tail -n3 services
iqobject        48619/tcp               # iqobject
iqobject        48619/udp               # iqobject
matahari        49000/tcp               # Matahari Broker
# 默认后10行
[root@192 etc]# tail services
3gpp-cbsp       48049/tcp               # 3GPP Cell Broadcast Service Protocol
isnetserv       48128/tcp               # Image Systems Network Services
isnetserv       48128/udp               # Image Systems Network Services
blp5            48129/tcp               # Bloomberg locator
blp5            48129/udp               # Bloomberg locator
com-bardac-dw   48556/tcp               # com-bardac-dw
com-bardac-dw   48556/udp               # com-bardac-dw
iqobject        48619/tcp               # iqobject
iqobject        48619/udp               # iqobject
matahari        49000/tcp               # Matahari Broker
  • tail -f动态显示文件内容


ln

[root@192 tmp]# touch test.list
[root@192 tmp]# mkdir dir1
# 在dir1的目录下创建test.list的软连接  参数-s  创建软链接
[root@192 tmp]# ln -s test.list dir1
[root@192 tmp]# ll dir1
总用量 0
lrwxrwxrwx. 1 root root 9 12月 15 10:27 test.list -> test.list
# 在dir1
[root@192 tmp]# ln test.list dir1/yinlianjie
[root@192 tmp]# ll dir1
总用量 0
lrwxrwxrwx. 1 root root 9 12月 15 10:27 test.list -> test.list
-rw-r--r--. 2 root root 0 12月 15 10:26 yinlianjie
# 创建软连接并改名
[root@192 tmp]# ln -s test.list dir1/ruan
[root@192 tmp]# ll dir1
总用量 0
lrwxrwxrwx. 1 root root 9 12月 15 10:28 ruan -> test.list    # "l"开头,表示文件类型为软链接
lrwxrwxrwx. 1 root root 9 12月 15 10:27 test.list -> test.list
-rw-r--r--. 2 root root 0 12月 15 10:26 yinlianjie

chmod


更改文件权限,限制可使用者

  • 文件所有者
  • root管理员

用户分类

  • u user 所有人
  • g group 所属组
  • o other 其他人

删除文件权限

  • 对文件所在目录拥有w写权限,对文件拥有w权限只代表可以修改文件内容

权限继承

  • 只有拥有了文件目录的权限,才可真正拥有其子目录下相关权限. 即使拥有文件的权限为7,但是对文件所在目录的权限为0,也是无法读写的.
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
-rw-r--r--. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
[root@bogon tmp]# chmod u+x test.list
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
# 注意对比:权限已从"rw-"变为了"rwx"
-rwxr--r--. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
[root@bogon tmp]# chmod u-x test.list 
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
# "x"执行权限被移除
-rw-r--r--. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
# 设置为"r",只读权限
[root@bogon tmp]# chmod u=r test.list 
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
#  "r--"成功!
-r--r--r--. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
# 同时更改多个用户类型的权限
[root@bogon tmp]# chmod u=rw,g=rw,o=rw test.list 
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
-rw-rw-rw-. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219

权限的数字表示(一个用户的权限在0~7之间)

  • r — 4
  • w — 2
  • x — 1

例:把test.list文件的权限更改为 r--rw----

  • r-- == 4
  • rw- == 6
  • --- == 0
[root@bogon tmp]# chmod 460 test.list 
[root@bogon tmp]# ll
总用量 0
drwxr-xr-x. 2 root root 53 12月 15 10:28 dir1
-r--rw----. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
[root@bogon tmp]# ll dir1/changemod/
总用量 0
drwxr-xr-x. 2 root root 6 12月 16 01:05 mode
[root@bogon tmp]# ll dir1
总用量 0
drwxr-xr-x. 3 root root 18 12月 16 01:05 changemod
-r--rw----. 2 root root  0 12月 15 10:26 yinlianjie
# 递归更改,将目录dir1及目录下所有文件权限全部更改为`777`
[root@bogon tmp]# chmod -R 777 dir1
[root@bogon tmp]# ll dir1
总用量 0
drwxrwxrwx. 3 root root 18 12月 16 01:05 changemod
-rwxrwxrwx. 2 root root  0 12月 15 10:26 yinlianjie
[root@bogon tmp]# ll dir1/changemod/
总用量 0
drwxrwxrwx. 2 root root 6 12月 16 01:05 mode
[root@bogon tmp]# ll
总用量 0
drwxrwxrwx. 3 root root 41 12月 16 01:04 dir1
-rwxrwxrwx. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219

chown

更改文件所有者,限制:只有管理员root可用

# tiam用户 使用
[tiam@bogon tmp]$ chown tiam dir1
chown: 正在更改"dir1" 的所有者: 不允许的操作
# root使用
[root@bogon tmp]# chown tiam dir1
[root@bogon tmp]# ll
总用量 0
# 注意文件 所有者 已经变化
drwxrwxrwx. 3 tiam root 41 12月 16 01:04 dir1
drwx------. 3 root root 17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root  0 12月 15 10:26 test.list
drwx------. 2 root root  6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root  6 12月 16 20:17 vmware-root_673-3988556249

chgrp

更改所属组

groupadd

添加所属组

# 创建 组
[root@bogon tmp]# groupadd softwareclass
# 更改 dir1 文件的所属组
[root@bogon tmp]# chgrp softwareclass dir1
[root@bogon tmp]# ll
总用量 0
# 注意!!!
drwxrwxrwx. 3 tiam softwareclass 41 12月 16 01:04 dir1
drwx------. 3 root root          17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root           0 12月 15 10:26 test.list
drwx------. 2 root root           6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root           6 12月 16 20:17 vmware-root_673-3988556249

useradd

添加用户用户名

passwd

添加用户密码 -f 强制执行

[root@bogon tmp]# useradd tiam
[root@bogon tmp]# passwd tiam
更改用户 tiam 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码包含用户名在某些地方
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
抱歉,密码不匹配。
passwd: 已经超出服务重试的最多次数

su root

切换root登录

exit/logout

退出登录

shutdown -h now

关机

umask

缺省组

  • 每个用户可属于多个组,但是当用户创建文件时,只会显示一个组,即缺省组
# 查看文件缺省权限
[root@bogon tmp]# umask -S
u=rwx,g=rx,o=rx
[root@bogon tmp]# mkdir lamp
[root@bogon tmp]# ls -l lamp
总用量 0
# 查看目录lamp详细信息, 参数 -d 表示查看文件夹本身,而不是查看文件夹下内容
[root@bogon tmp]# ls -ld lamp
drwxr-xr-x. 2 root root 6 12月 16 20:56 lamp
# Linux中,新建文件默认去除 x 权限
[root@bogon tmp]# ll bloom
-rw-r--r--. 1 root root 0 12月 16 21:01 bloom
  • Linux中,新建**文件**默认没有可执行权限
# 修改文件缺省权限
[root@bogon tmp]# umask 077
[root@bogon tmp]# mkdir lamb
[root@bogon tmp]# ll -d lamb
drwx------. 2 root root 6 12月 16 21:22 lamb
[root@bogon tmp]# touch lamb.list
[root@bogon tmp]# ll lamb.list 
-rw-------. 1 root root 0 12月 16 21:23 lamb.list

解释

  • 0 对应---
  • 7对应 rwx
  • 7对应 rwx
  • 但是实际文件夹 缺省权限却是 rwx --- ---
  • 进行亦或运算后的结果
  • 文件权限去掉x权限, 即rw- --- ---

例:我想改回默认权限rwx r-x r-x

  • rwx ==> 0
  • r-x ==> 2
  • r-x ==> 2

测试:

[root@bogon tmp]# umask 022
[root@bogon tmp]# mkdir lamb1
[root@bogon tmp]# ll -d lamb1
drwxr-xr-x. 2 root root 6 12月 16 21:32 lamb1
[root@bogon tmp]# umask -S
u=rwx,g=rx,o=rx

find

不建议使用,占用服务器

[root@bogon tmp]# find lamb1
lamb1
[root@bogon tmp]# find es
find: ‘es’: 没有那个文件或目录
# 精确搜索,在/etc目录下查询文件名为init的文件,区分大小写
[root@bogon tmp]# find /etc -name init
/etc/sysconfig/init
/etc/selinux/targeted/active/modules/100/init
# 模糊查询,使用通配符 * ,匹配任意字符
[root@bogon tmp]# find /etc -name *init*
/etc/systemd/system/sysinit.target.wants
/etc/inittab
/etc/sysconfig/init
/etc/sysconfig/network-scripts/init.ipv6-global
/etc/init.d
/etc/rc.d/init.d
/etc/selinux/targeted/active/modules/100/init
/etc/selinux/targeted/contexts/initrc_context
/etc/security/namespace.init
# 模糊查询 文件名为init后面有3个字符的文件
[root@bogon tmp]# find /etc -name init???
/etc/inittab
[root@bogon tmp]# mkdir INITTAB
# -iname 不区分大小写查询
[root@bogon tmp]# find / -iname init???
/dev/initctl
/run/systemd/initctl
/etc/inittab
/tmp/INITTAB
/usr/lib/dracut/modules.d/99base/init.sh
# 查询大于50MB的文件 , 单位为数据块,2数据块==1KB
[root@bogon tmp]# find / -size +102400
/boot/initramfs-0-rescue-4ab4fad3863e424fb979b7d73e8b015e.img
/proc/kcore
find: ‘/proc/98964/task/98964/fd/6’: 没有那个文件或目录
find: ‘/proc/98964/task/98964/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/98964/fd/5’: 没有那个文件或目录
find: ‘/proc/98964/fdinfo/5’: 没有那个文件或目录
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/var/cache/yum/x86_64/7/updates/gen/primary_db.sqlite
/usr/lib/locale/locale-archive
# 单位MB 注意大写 M
[root@bogon tmp]# find / -size +50M
/boot/initramfs-0-rescue-4ab4fad3863e424fb979b7d73e8b015e.img
/proc/kcore
find: ‘/proc/100141/task/100141/fd/6’: 没有那个文件或目录
find: ‘/proc/100141/task/100141/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/100141/fd/5’: 没有那个文件或目录
find: ‘/proc/100141/fdinfo/5’: 没有那个文件或目录
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/var/cache/yum/x86_64/7/updates/gen/primary_db.sqlite
/usr/lib/locale/locale-archive
# 单位KB 注意 小写 k
[root@bogon tmp]# find / -size +51200k
/boot/initramfs-0-rescue-4ab4fad3863e424fb979b7d73e8b015e.img
/proc/kcore
find: ‘/proc/105232/task/105232/fd/6’: 没有那个文件或目录
find: ‘/proc/105232/task/105232/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/105232/fd/5’: 没有那个文件或目录
find: ‘/proc/105232/fdinfo/5’: 没有那个文件或目录
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/var/cache/yum/x86_64/7/updates/gen/primary_db.sqlite
/usr/lib/locale/locale-archive
# 根据文件所属者查找
[root@bogon tmp]# find /tmp -user tiam
/tmp/dir1
/tmp/only.list
[root@bogon tmp]# ll
总用量 0
-rw-r--r--. 1 root root           0 12月 16 21:01 bloom
drwxrwxrwx. 3 tiam softwareclass 41 12月 16 01:04 dir1
drwxr-xr-x. 2 root root           6 12月 16 21:52 INITTAB
drwx------. 2 root root           6 12月 16 21:22 lamb
drwxr-xr-x. 2 root root           6 12月 16 21:32 lamb1
-rw-------. 1 root root           0 12月 16 21:23 lamb.list
drwxr-xr-x. 2 root root           6 12月 16 20:56 lamp
-rw-rw-r--. 1 tiam tiam           0 12月 16 20:48 only.list
drwx------. 3 root root          17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root           0 12月 15 10:26 test.list
drwx------. 2 root root           6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root           6 12月 16 20:17 vmware-root_673-3988556249
# 根据所属组查询
[root@bogon tmp]# find -group softwareclass
./dir1
[root@bogon tmp]# ll
总用量 0
-rw-r--r--. 1 root root           0 12月 16 21:01 bloom
drwxrwxrwx. 3 tiam softwareclass 41 12月 16 01:04 dir1
drwxr-xr-x. 2 root root           6 12月 16 21:52 INITTAB
drwx------. 2 root root           6 12月 16 21:22 lamb
drwxr-xr-x. 2 root root           6 12月 16 21:32 lamb1
-rw-------. 1 root root           0 12月 16 21:23 lamb.list
drwxr-xr-x. 2 root root           6 12月 16 20:56 lamp
-rw-rw-r--. 1 tiam tiam           0 12月 16 20:48 only.list
drwx------. 3 root root          17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root           0 12月 15 10:26 test.list
drwx------. 2 root root           6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root           6 12月 16 20:17 vmware-root_673-3988556249
  • -amin 访问时间 access
  • -cmin 文件属性 change
  • -mmin 文件内容 modify
# 查看/var目录下1分钟内被修改过的文件
[root@bogon tmp]# find /var -mmin -1
/var/log/audit/audit.log
/var/log/vmware-vmsvc-root.log

逻辑运算

  • -a and 表示"且"
  • -o or 表示 “或”
# 查询50MB~60MB之间的文件
[root@bogon tmp]# find / -size +50M -a -size -60M
find: ‘/proc/15539/task/15539/fd/6’: 没有那个文件或目录
find: ‘/proc/15539/task/15539/fdinfo/6’: 没有那个文件或目录
find: ‘/proc/15539/fd/5’: 没有那个文件或目录
find: ‘/proc/15539/fdinfo/5’: 没有那个文件或目录

文件类型

  • f 文件
  • d 目录
  • l 软链接
# 根据文件类型查询
[root@bogon tmp]# find -type f
./test.list
./dir1/yinlianjie
./only.list
./bloom
./lamb.list
[root@bogon tmp]# ll
总用量 0
-rw-r--r--. 1 root root           0 12月 16 21:01 bloom
drwxrwxrwx. 3 tiam softwareclass 41 12月 16 01:04 dir1
drwxr-xr-x. 2 root root           6 12月 16 21:52 INITTAB
drwx------. 2 root root           6 12月 16 21:22 lamb
drwxr-xr-x. 2 root root           6 12月 16 21:32 lamb1
-rw-------. 1 root root           0 12月 16 21:23 lamb.list
drwxr-xr-x. 2 root root           6 12月 16 20:56 lamp
-rw-rw-r--. 1 tiam tiam           0 12月 16 20:48 only.list
drwx------. 3 root root          17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root           0 12月 15 10:26 test.list
drwx------. 2 root root           6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root           6 12月 16 20:17 vmware-root_673-3988556249
[root@bogon tmp]# find test.list -exec ls -l \;
总用量 0
-rw-r--r--. 1 root root           0 12月 16 21:01 bloom
drwxrwxrwx. 3 tiam softwareclass 41 12月 16 01:04 dir1
drwxr-xr-x. 2 root root           6 12月 16 21:52 INITTAB
drwx------. 2 root root           6 12月 16 21:22 lamb
drwxr-xr-x. 2 root root           6 12月 16 21:32 lamb1
-rw-------. 1 root root           0 12月 16 21:23 lamb.list
drwxr-xr-x. 2 root root           6 12月 16 20:56 lamp
-rw-rw-r--. 1 tiam tiam           0 12月 16 20:48 only.list
drwx------. 3 root root          17 12月 16 20:17 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
-rwxrwxrwx. 2 root root           0 12月 15 10:26 test.list
drwx------. 2 root root           6 12月 16 00:25 vmware-root_666-2731021219
drwx------. 2 root root           6 12月 16 20:17 vmware-root_673-3988556249
# -exec 对查询结果 再次操作,显示详细信息
[root@bogon tmp]# find test.list -exec ls -l {} \;
-rwxrwxrwx. 2 root root 0 12月 15 10:26 test.list
# -ok 作用于-exec相同,但是多了一个询问步骤
[root@bogon tmp]# find test.list -ok ls -l {} \;
< ls ... test.list > ? y
-rwxrwxrwx. 2 root root 0 12月 15 10:26 test.list
# 查看文件节点
[root@bogon tmp]# ls -i
16777666 bloom    16784898 lamb1           277 systemd-private-36d853d491874b5c84f83329b44cddab-chronyd.service-S5zkhE
16777668 dir1     16777689 lamb.list  16777289 test.list
33575433 INITTAB  51041070 lamp       33575424 vmware-root_666-2731021219
     286 lamb     16777637 only.list       285 vmware-root_673-3988556249
# 根据节点查询
[root@bogon tmp]# find -inum 16777666
./bloom
相关文章
|
2天前
|
Linux
会玩这10个Linux命令,一定是个有趣的IT男!
会玩这10个Linux命令,一定是个有趣的IT男!
|
2天前
|
安全 Linux 开发者
Linux笔记之ldd命令详解
`ldd`命令是Linux环境下一个非常实用的工具,用于显示一个程序运行时所需的共享库依赖。它帮助开发者和系统管理员快速诊断程序运行问题,特别是在处理"找不到库文件"或者"错误的库文件版本"等错误时。然而,出于安全的考虑,对于不信任的可执行文件,应该慎用 `ldd`命令,可以考虑使用其他工具如 `objdump`。总的来说,懂得如何妥善且安全地使用 `ldd`,对于维护一个稳定和高效的Linux系统来说,是非常重要的。
17 9
|
2天前
|
Linux Shell
linux命令
linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置Shell命令和Linux命令。
|
3天前
|
移动开发 运维 网络协议
运维必备 | Linux netstat命令详解
运维必备 | Linux netstat命令详解
|
3天前
|
Linux
真香~ Linux vi常用命令汇总!
真香~ Linux vi常用命令汇总!
|
3天前
|
Linux Shell
linux命令
linux命令是对Linux系统进行管理的命令。对于Linux系统来说,无论是中央处理器、内存、磁盘驱动器、键盘、鼠标,还是用户等都是文件,Linux系统管理的命令是它正常运行的核心,与之前的DOS命令类似。linux命令在系统中有两种类型:内置Shell命令和Linux命令。
|
2天前
|
SQL 存储 分布式计算
Linux退出Hive命令
【8月更文挑战第14天】
|
3天前
|
Linux Shell 数据库
退休前一天都还在用的Linux常用命令!建议收藏!
退休前一天都还在用的Linux常用命令!建议收藏!
|
2天前
|
Linux Shell
危险!这10个Linux命令慎用,否则可能牢底坐穿!
危险!这10个Linux命令慎用,否则可能牢底坐穿!
|
3天前
|
Ubuntu Linux Shell
这7个重要的Linux命令,每一位Linux工程师都必须盘它!
这7个重要的Linux命令,每一位Linux工程师都必须盘它!