RHCSAday2

本文详细介绍了Linux中`su`命令的用法,包括切换用户、选项解析及其在终端的帮助信息。同时,解释了`ls`命令的不同参数,如列出目录、文件属性、大小转换等。还深入探讨了软链接和硬链接的概念、作用、创建方式及其在文件系统中的应用。这些内容对于理解和操作Linux系统至关重要。
摘要由CSDN通过智能技术生成

一、命令帮助的两种方法:

1、su --help(获取该命令的帮助信息)

Usage:
 su [options] [-] [<user> [<argument>...]]

Change the effective user ID and group ID to that of <user>.
A mere - implies -l.  If <user> is not given, root is assumed.

Options:
 -m, -p, --preserve-environment  do not reset environment variables
 -g, --group <group>             specify the primary group
 -G, --supp-group <group>        specify a supplemental group

 -, -l, --login                  make the shell a login shell
 -c, --command <command>         pass a single command to the shell with -c
 --session-command <command>     pass a single command to the shell with -c
                                   and do not create a new session
 -f, --fast                      pass -f to the shell (for csh or tcsh)
 -s, --shell <shell>             run <shell> if /etc/shells allows it
 -P, --pty                       create a new pseudo-terminal

 -h, --help                      display this help
 -V, --version                   display version


2、man su(退出 q)终端不会显示

SU(1) (第一章节)                           User Commands                           SU(1)

NAME
       su - run a command with substitute user and group ID

SYNOPSIS
       su [options] [-] [user [argument...]]

DESCRIPTION
       su allows to run commands with a substitute user and group ID.

       When  called  without  arguments, su defaults to running an interactive
       shell as root.

       For backward compatibility, su  defaults  to  not  change  the  current
       directory  and  to  only  set  the environment variables HOME and SHELL
       (plus USER and LOGNAME if the target user is not root).  It  is  recom‐
       mended  to always use the --login option (instead of its shortcut -) to
       avoid side effects caused by mixing environments.

       This version of su uses PAM for  authentication,  account  and  session
       management.   Some  configuration options found in other su implementa‐
       tions, such as support for a wheel group, have  to  be  configured  via
 Manual page su(1) line 1 (press h for help or q to quit)

​ main手册(一[所有用户可以执行命令的帮助和信息]、五[所有配置文件的帮助信息]、八[只有管理员可以执行命令的帮助]三个章节)

eg:查看章节的帮助信息man 5 group

【】–>可有可没有

二、ls: list 列出对应目录下的所有数据文件

ls /目录(可以跟多个目录名)

① ls -l/ll:使用长格式列出(列出文件属性)

eg.
-rw-------. 1 root root 1278 Nov 20 13:53 anaconda-ks.cfg
第一列:
第一个字符:标记文件类型
linux中有七大文件类型(类比于Windows):- 普通文本文件(.txt) d 目录文件(文件夹)l 软连接,符号链接文件(快捷方式)b 块设备文件 c字符设备文件p 管道符文件 s socket套接字文件
2-11个字符:文件的权限标识符 
第二列:硬链接次数
第三列:文件所属用户
第四列:文件的所属组
第五列:文件大小
第六到八列:文件创建时间/修改时间
第九列:文件名

②ls -l -h/ll -h:数据文件大小单位转换

③ls -l -d/ls -ld:当前/指定目录的属性信息

④ls -la:把当前以及上级目录下所有文件(包括隐藏文件)属性显示

⑤ls -lA:当前目录下所有文件(包括隐藏文件)属性

⑥ls -li:文件节点号(编号)inode索引节点号

软链接/硬链接

软链接:

一、概念

软链接文件也是一个单独的文件,软链接文件的数据存储区记录的是源文件的位置信息。类似于Windows的快捷方式。

二、作用

通过指定路径快速便捷匹配其他路径下的数据文件

三、应用

可以对文本文件创建,也可以对目录文件创建,支持快文件系统

四、表示

通过l标记文件类型

五、创建方式

ln -s(创建快捷方式)
eg:
ln [OPTION]... [-T] TARGET LINK_NAME

示例:
35305976 lrwxrwxrwx. 1 root root    3 Nov 24 15:15 N.lnk -> NMX
35305973 -rw-r--r--. 1 root root    0 Nov 24 15:15 NMX


创建软链接,目标文件和链接文件不在同一路径,用绝对路径,相对路径会有问题(标红)
#touch FILENAME 创建文件
#mkdir FILENAME 创建目录文件
#rm FILENAME 删除文本文件
#rm -r DIRNAME 删除目录文件

硬链接

一、概念

多个文件名指向同一个inode的节点

二、作用

防止误删除,对文件名备份

三、应用

可以对文本文件,默认不可以对目录文件创建,不支持跨文件系统

四、表示

多个硬链接文件有相同的节点号

五、创建方式

ln 

示例:35305973 -rw-r--r--. 2 root root    0 Nov 24 15:15 M.txt

eg:
在系统/root目录下创建file文件
(1)对file文件创建一个快捷方式file.lnk放在/目录下;
(2)对file文件创建一个硬链接文件位newfile放在/目录下;
创建/root目录下file文件:
[root@localhost ~]# touch /file
[root@localhost ~]# 
[root@localhost ~]# ll -i
total 8
33575045 -rw-------. 1 root root 1278 Nov 20 13:53 anaconda-ks.cfg
 1545555 drwxr-xr-x. 2 root root    6 Nov 20 14:09 Desktop
 1545556 drwxr-xr-x. 2 root root    6 Nov 20 14:09 Documents
18265808 drwxr-xr-x. 2 root root    6 Nov 20 14:09 Downloads
35305979 -rw-r--r--. 1 root root    0 Nov 24 15:21 file

(1)
[root@localhost ~]# ln -s file /file.lnk
[root@localhost ~]# 
[root@localhost ~]# ll /
total 28
lrwxrwxrwx.   1 root root    7 Jun 21  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Nov 20 13:54 boot
drwxr-xr-x.  20 root root 3220 Nov 24 14:43 dev
drwxr-xr-x. 145 root root 8192 Nov 24 14:43 etc
-rw-r--r--.   1 root root    0 Nov 24 15:35 file
lrwxrwxrwx.   1 root root    4 Nov 24 15:40 file.lnk -> file
lrwxrwxrwx.   1 root root   10 Nov 24 15:30 f.lnk -> /root/file

(2)
root@localhost ~]# ln file /newfile.txt
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# ll /
total 28
lrwxrwxrwx.   1 root root    7 Jun 21  2021 bin -> usr/bin
dr-xr-xr-x.   5 root root 4096 Nov 20 13:54 boot
drwxr-xr-x.  20 root root 3220 Nov 24 14:43 dev
drwxr-xr-x. 145 root root 8192 Nov 24 14:43 etc
-rw-r--r--.   1 root root    0 Nov 24 15:35 file
lrwxrwxrwx.   1 root root    4 Nov 24 15:40 file.lnk -> file
lrwxrwxrwx.   1 root root   10 Nov 24 15:30 f.lnk -> /root/file
drwxr-xr-x.   3 root root   23 Nov 20 13:52 home
lrwxrwxrwx.   1 root root    7 Jun 21  2021 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Jun 21  2021 lib64 -> usr/lib64
drwxr-xr-x.   2 root root    6 Jun 21  2021 media
drwxr-xr-x.   3 root root   18 Nov 20 13:43 mnt
-rw-r--r--.   2 root root    0 Nov 24 15:21 newfile.txt


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值