计算机网络/计算机科学与应用/系统/运维/开发

Linux熟练六、Linux文件与目录管理

一、目录与路径

1.1、相对路径与绝对路径

    绝对路径: 由根目录 / 写起   比如 /usr/share/doc 目录 (脚本编写 通常使用绝对路径)

    相对路径: 由当前目录 到 /usr/share/man 可以写为 cd ../man     


1.2、目录的操作

   1、特殊目录

    . 代表此层目录 

    .. 代表上层目录 

    - 代表前一个工作目录

    ~ 代表 目前用户身份 所在的家目录

    ~account  代表account这个用户的家目录 (account 是账号名称)

       注意: 在所有目录下都会存在2个目录,. 此层目录和 .. 上层目录 

    

       问:请问linux下,根目录下有没有上层目录..存在?

       答:存在 ,且根目录下存在. 与 .. 两个目录,并且2个目录属性与权限完全一致

[root@localhost ~]# ls -al /
总用量 28
dr-xr-xr-x.  18 root root  252 11月  9 14:47 .
dr-xr-xr-x.  18 root root  252 11月  9 14:47 ..

        常见处理目录的指令:

        cd 变换目录

        pwd 显示当前所在目录

        mkdir 建立一个新的目录

        rmdir 删除一个空的目录

[zth@localhost ~]$ su -
密码:
上一次登录:一 11月 11 10:00:55 CST 2024从 192.168.9.100pts/0 上
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# cd ~zth
[root@localhost zth]# cd ~
[root@localhost ~]# cd 
[root@localhost ~]# cd ..
[root@localhost /]# cd /var/spool/mail/
[root@localhost mail]# cd ../postfix/
[root@localhost postfix]#


(2)pwd 显示当前所在的目录

         pwd [-P]

         选项:

              -P(大写) 显示出确实的路径,而非使用链接link路径


         # 单纯显示工作目录

[root@localhost ~]# pwd
/root
[root@localhost ~]#


         # 显示出实际的工作目录,而非链接文件本身的目录名而已

[root@localhost ~]# cd /var/mail/


         # 列出当前的工作目录

[root@localhost mail]# pwd
/var/mail


         # 显示出实际的工作目录 (因为/var/mail 是连接档,链接到/var/spool/mail )

[root@localhost mail]# pwd -P (加上-P之后,会显示正确的路径,不会以链接文件的数据显示)
/var/spool/mail
[root@localhost mail]# ls -ld /var/mail
lrwxrwxrwx. 1 root root 10 11月  4 15:49 /var/mail -> spool/mail


(3)mkdir 建立新目录

    mkdir [-mp] 目录名称

    选项:

    -m 配置文件的权限,直接设定,不需要看预设权限umask的脸色

    -p 递归,一次性创建多层级目录

[root@localhost ~]# cd /tmp/
[root@localhost tmp]# 
[root@localhost tmp]# 
[root@localhost tmp]#


    # 建立test新目录

[root@localhost tmp]# mkdir test
[root@localhost tmp]# mkdir test1/test2/test3/test4
mkdir: 无法创建目录"test1/test2/test3/test4": 没有那个文件或目录


    # -p选项 自动建立多层目录

[root@localhost tmp]# mkdir -p test1/test2/test3/test4
[root@localhost tmp]#


    # 建立权限为 rwx--x--x的目录

[root@localhost tmp]# mkdir -m 711 test2
[root@localhost tmp]# ls -ld test*
drwxr-xr-x. 2 root root  6 11月 11 10:41 test
drwxr-xr-x. 3 root root 19 11月 11 10:42 test1


    # 注意上面权限,如果没加-m选项 强制设定属性,那么会使用系统默认属性 

    drwx--x--x. 2 root root  6 11月 11 10:42 test2


(4)rmdir 删除空的目录

    rmdir [-p] 目录名称 

    选项:

    -p 连同[上层][空的] 目录一起删除


    # 查看有多少目录存在

[root@localhost tmp]# ls -ld test*
drwxr-xr-x. 2 root root  6 11月 11 10:41 test
drwxr-xr-x. 3 root root 19 11月 11 10:42 test1
drwx--x--x. 2 root root  6 11月 11 10:42 test2


    # 可以直接删除

[root@localhost tmp]# rmdir test


    # 因为目录中有内容,无法直接删除

[root@localhost tmp]# rmdir test1
rmdir: 删除 "test1" 失败: 目录非空
[root@localhost tmp]# rmdir -p test1/test2/test3/test4


    # 目录中test与test1不见了

[root@localhost tmp]# ls -ld test*
drwx--x--x. 2 root root 6 11月 11 10:42 test2


    注意: rmdir 只能删除空的目录


    1.3、执行文件路径的变量 $PATH 

[root@localhost tmp]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/redis:/usr/local/mysql/bin:/root/bin
[root@localhost tmp]# exit
登出
[zth@localhost ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/redis:/usr/local/mysql/bin:/home/zth/.local/bin:/home/zth/bin


    不同身份使用者预设的PATH不同,默认能够随意执行的指令也不同

    PATH 是可以修改的

    使用绝对路径或相对路径直接指定某个指令的文件名来执行,会比搜寻PATH来的正确

    指令应该要放置在正确的目录下,执行才会比较方便

    本目录 (.)最好不要放到PATH当中


二、文件与目录管理

2.1、文件与目录检视 ls 

        ls [-aAdfFhilnrRSt] 文件名或目录名称...

        ls [--color={never,auto,always}] 文件名或目录名称...

        ls [--full-time]  文件名或目录名称..

     

        选项:

-a 全部文件 包括隐藏的(开头为.的文件) 一起列出来

-A 全部文件 包括隐藏文件(不包括 .与.. 这2个目录)

-d 仅列出目录本身 而不是列出目录内的文件数据

-f 直接列出结果 而不进行排序 (ls预设会以档名排序)

-F 根据文件、目录等信息 给与附加数据结构 

(*:代表可执行文件; /:代表目录; =:代表 socket 文件; |:代表 FIFO 文件;)

-h 将文件容量以人类较易阅读的方式(GB KB)列出来

-i 列出inode号码 

-n 列出UID与GID而非使用者与群组的名称

-r 将排序结果反向输出

-R 连同子目录内容一起列出来 

-S  以文件容量大小排序 而不是用档名排序

-t  以时间排序

--color=never 不要依据文件特性给与颜色显示

--color=always 显示颜色

--color=auto 让系统自行依据设定来判断是否给与颜色

--full-time 以完整时间模式输出

--time={atime,ctime} 输出access时间或改变权限属性时间(ctime)


    # 将家目录下所有文件列出来(含属性与隐藏文件)

[zth@localhost ~]$ ls -al ~
总用量 28
drwx------. 15 zth  zth  4096 11月  4 15:59 .
drwxr-xr-x.  5 root root   43 11月  6 14:00 ..
-rw-r--r--.  1 zth  zth    18 4月   1 2020 .bash_logout
-rw-r--r--.  1 zth  zth   193 4月   1 2020 .bash_profile
-rw-r--r--.  1 zth  zth   231 4月   1 2020 .bashrc
drwx------. 14 zth  zth  4096 11月  4 15:59 .cache
drwxr-xr-x. 14 zth  zth   261 11月  4 15:59 .config
drwx------.  3 zth  zth    25 11月  4 15:59 .dbus
-rw-------.  1 zth  zth    16 11月  4 15:59 .esd_auth
-rw-------.  1 zth  zth   310 11月  4 15:59 .ICEauthority
drwx------.  3 zth  zth    19 11月  4 15:59 .local
drwxr-xr-x.  4 zth  zth    39 11月  4 15:49 .mozilla
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 公共
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 模板
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 视频
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 图片
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 文档
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 下载
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 音乐
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 桌面


    # 不显示颜色 但在文件名末显示出该文件名代表的类型type

[zth@localhost ~]$ ls -alF --color=never ~
总用量 28
drwx------. 15 zth  zth  4096 11月  4 15:59 ./
drwxr-xr-x.  5 root root   43 11月  6 14:00 ../
-rw-r--r--.  1 zth  zth    18 4月   1 2020 .bash_logout
-rw-r--r--.  1 zth  zth   193 4月   1 2020 .bash_profile
-rw-r--r--.  1 zth  zth   231 4月   1 2020 .bashrc
drwx------. 14 zth  zth  4096 11月  4 15:59 .cache/
drwxr-xr-x. 14 zth  zth   261 11月  4 15:59 .config/
drwx------.  3 zth  zth    25 11月  4 15:59 .dbus/
-rw-------.  1 zth  zth    16 11月  4 15:59 .esd_auth
-rw-------.  1 zth  zth   310 11月  4 15:59 .ICEauthority
drwx------.  3 zth  zth    19 11月  4 15:59 .local/
drwxr-xr-x.  4 zth  zth    39 11月  4 15:49 .mozilla/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 公共/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 模板/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 视频/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 图片/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 文档/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 下载/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 音乐/
drwxr-xr-x.  2 zth  zth     6 11月  4 15:59 桌面/


    # 完整的呈现文件的修改时间 modification time 

[zth@localhost ~]$ ls -al --full-time ~
总用量 28
drwx------. 15 zth  zth  4096 2024-11-04 15:59:18.603382398 +0800 .
drwxr-xr-x.  5 root root   43 2024-11-06 14:00:21.202508491 +0800 ..
-rw-r--r--.  1 zth  zth    18 2020-04-01 10:17:30.000000000 +0800 .bash_logout
-rw-r--r--.  1 zth  zth   193 2020-04-01 10:17:30.000000000 +0800 .bash_profile
-rw-r--r--.  1 zth  zth   231 2020-04-01 10:17:30.000000000 +0800 .bashrc
drwx------. 14 zth  zth  4096 2024-11-04 15:59:22.823567626 +0800 .cache
drwxr-xr-x. 14 zth  zth   261 2024-11-04 15:59:27.393767260 +0800 .config
drwx------.  3 zth  zth    25 2024-11-04 15:59:15.158231102 +0800 .dbus
-rw-------.  1 zth  zth    16 2024-11-04 15:59:15.766257796 +0800 .esd_auth
-rw-------.  1 zth  zth   310 2024-11-04 15:59:15.495245898 +0800 .ICEauthority
drwx------.  3 zth  zth    19 2024-11-04 15:59:15.545248093 +0800 .local
drwxr-xr-x.  4 zth  zth    39 2024-11-04 15:49:41.210841000 +0800 .mozilla
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 公共
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 模板
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 视频
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 图片
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 文档
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 下载
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 音乐
drwxr-xr-x.  2 zth  zth     6 2024-11-04 15:59:18.603382398 +0800 桌面


2.2、复制、删除与移动 cp rm mv 

(1)cp命令 复制文件或目录 

         还可以建立结档(快捷方式) 比较2个文件的新旧 复制整个目录等功能

         cp [-adfilprsu] 来源文件(source)  目标文件(destination)

         cp [options] source1 source2 source3 .... directory

         选项参数:

-a 相当于 -dr --preserve=all 的意思 

-d 若来源文件为链接文件的属性(link file),则复制链接文件属性而非文件本身

-f 为强制(force)的意思 若目标文件已经存在且无法开启,则移除后再尝试一次

-i 若目标文件(destination)已经存在时,在覆盖时会先询问动作的进行(常用)

-l 进行硬式连结(hard link)的连结档建立,而非复制文件本身

-p 连同文件的属性(权限、用户、时间)一起复制过去,而非使用默认属性(备份常用)

-r 递归持续复制,用于目录的复制行为;(常用)

-s 复制成为符号链接文件 (快捷文件)

-u :destination 比 source 旧才更新 destination,或 destination 不存在的情况下才复制

--preserve=all :除了 -p 的权限相关参数外,还加入 SELinux 的属性, links, xattr 等也复制了

注意:最后需要注意的,如果来源档有两个以上,则最后一个目的文件一定要是『目录』才行!


    # 将家目录下的 .bashrc 复制到/tmp下 并更名为 bashrc 

[root@localhost ~]# cp ~/.bashrc /tmp/bashrc


    # 使用-i选项后会提示是否覆盖

[root@localhost ~]# cp -i ~/.bashrc /tmp/bashrc
cp:是否覆盖"/tmp/bashrc"? n
[root@localhost ~]# 
[root@localhost ~]# 
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# cp /var/lo
local/ lock/  log/


    # 将/var/log/wtmp复制到/tmp且观察属性

    # 不加任何选项的情况下,文件的某些属性 权限会改变 包括文件的建立时间也改变了

[root@localhost tmp]# cp /var/log/wtmp .
[root@localhost tmp]# ls -l /var/log/wtmp wtmp 
-rw-rw-r--. 1 root utmp 16512 11月 11 10:00 /var/log/wtmp
-rw-r--r--. 1 root root 16512 11月 11 11:42 wtmp
[root@localhost tmp]# 
[root@localhost tmp]#


    # 如果想要将文件的所有特性都一起复制 则加-a属性 

[root@localhost tmp]# cp -a /var/log/wtmp wtmp_2
[root@localhost tmp]# ls -l /var/log/wtmp wtmp_2
-rw-rw-r--. 1 root utmp 16512 11月 11 10:00 /var/log/wtmp
-rw-rw-r--. 1 root utmp 16512 11月 11 10:00 wtmp_2


    注意: 

    因此当我们在进行备份的时候,某些需要特别注意的特殊权限文件, 例如密码

    文件 (/etc/shadow) 以及一些配置文件,就不能直接以 cp 来复制,而必须要加上 -a 或者是 -p 等等    

    可以完整复制文件权限的选项才行!另外,如果你想要复制文件给其他的使用者, 也必须要注意到

    文件的权限(包含读、写、执行以及文件拥有者等等), 否则,其他人还是无法针对你给予的文件进

    行修订的动作喔!注意注意!


    # -r 是可以复制目录 但是 文件与目录的权限可能会改变

    # 可以利用 cp -a /etc/ /tmp 下达指令

[root@localhost tmp]# cp /etc/ /tmp/
cp: 略过目录"/etc/"
[root@localhost tmp]# cp -r /etc/ /tmp/


    cp 有多种文件属性与权限特征,复制时必须要考虑:

        是否需要要完整的保留来源文件的信息?

        来源文件是否为连结档 (symbolic link file)?

        来源档是否为特殊的文件,例如 FIFO, socket 等?

         来源文件是否为目录?

(2)移除文件或目录 rm

         rm [-fir] 文件或目录

    选项:

-f 就是 force 的意思,忽略不存在的文件,不会出现警告讯息

-i :互动模式,在删除前会询问使用者是否动作

-r :递归删除啊!最常用在目录的删除了!这是非常危险的选项!!!

    

    # -i 选项会主动询问 避免删除错误的档名

[root@localhost tmp]# cd /tmp/
[root@localhost tmp]# rm -i bashrc 
rm:是否删除普通文件 "bashrc"?y


    # * 号 可以代表无穷多个任意字符 

[root@localhost tmp]# rm -i bashrc*
rm: 无法删除"bashrc*": 没有那个文件或目录
[root@localhost tmp]# rmdir /tmp/etc/
rmdir: 删除 "/tmp/etc/" 失败: 目录非空


    # root身份 预设已经加入了 -i 选项  ctrl+c结束

[root@localhost tmp]# rm -r /tmp/etc/
rm:是否进入目录"/tmp/etc/"? y
rm:是否删除普通文件 "/tmp/etc/fstab"?y
rm:是否删除普通空文件 "/tmp/etc/crypttab"?^C


    # 指令前加上反斜杠 

[root@localhost tmp]# \rm -r /tmp/etc/


    # 删除 带有 - 开头的文件 直接删除 “-” 选项 系统会误判

    # rm ./-aaa-


(3)mv 移动文件与目录  或更名 

    mv [-fiu]  source destination 

    mv [options] source1 source2 source3  ...directory 


    选项:

-f force强制的意思 如果目标文件已经存在 不会询问直接覆盖

-i 若目标文件 已经存在时 就会询问是否覆盖

-u 若目标文件已经存在,且 source 比较新,才会更新 (update)


    # 将文件移动到某个目录中去

[root@localhost tmp]# cd /tmp/
[root@localhost tmp]# cp ~/.bashrc bashrc
[root@localhost tmp]# mkdir mvtest
[root@localhost tmp]# mv bashrc mvtest/
[root@localhost tmp]# 
[root@localhost tmp]#


    # 将mvtest 目录更名为 mvtest2 

[root@localhost tmp]# mv mvtest mvtest2
[root@localhost tmp]#


    # 将全部文件移动到mvtest2目录中

[root@localhost tmp]# cp ~/.bashrc  bashrc1
[root@localhost tmp]# cp ~/.bashrc  bashrc2
[root@localhost tmp]# mv bashrc1 bashrc2 mvtest2


注意: 如果有多个来源文件或目录 则最后一个目标文件 一定是目录

(4)取得路径的文件名与目录名称

# 取得最后的档名

[root@localhost tmp]# basename /etc/sysconfig/network
network


# 取得的变成目录名了

[root@localhost tmp]# dirname /etc/sysconfig/network
/etc/sysconfig


三、文件内容查阅

显示文件内容指令 cat  more less 

查看大型文件时 使用tail 

cat 第一行开始显示文件内容

tac 从最后一行开始显示 

nl 显示的时候,顺道输出行号

more 一页一页显示文件内容

less 与 more  类似,它可以向前翻页

head 只看头几行 

tail 只看尾几行 

od 以二进制方式读取文件内容 

3.1、直接检视文件内容

直接查阅文件内容可以使用  cat / tac /nl 

(1)cat 

cat [-AbEnTv]

选项: 

-A 相当于 -vET 的选项 列出一些特殊字符而不是空白字符

-b 列出行号,针对非空白行做行号显示 空白行不标行号

-E 将结尾的断行字符 $ 显示出来

-n打印行号 连同空白行也会有行号 

-T 将tab 按键以^显示出来 

-v 列出一些看不出来的特殊字符 

# 查看issue 文件内容 

[root@localhost tmp]# cat /etc/issue
\S
Kernel \r on an \m


# 加上行号 

[root@localhost tmp]# cat -n /etc/issue
 1\S
 2Kernel \r on an \m
 3


# 将文件内容完整显示出来 (包含特殊字符)

[root@localhost tmp]# cat -A /etc/man_db.conf 
# $
#$
# This file is used by the man-db package to configure the man and cat paths.$
# It is also used to provide a manpath for those without one by examining$
# their PATH environment variable. For details see the manpath(5) man page.$
#$


(2)tac 

倒着显示 

[root@localhost tmp]# tac /etc/issue
Kernel \r on an \m
\S


(3)nl 添加行号打印

nl [-bnw] 文件

选项: 

-b 指定行号指定的方式 主要有2种:

-b a  表示不论是否为空行 也同样列出行号 

-b t 如果有空行 空的一行不显示行号 

-n  列出行号表示的方法 

-n  ln 行号在屏幕最左方显示

-n  rn 行号在自己字段的最右显示 且不加0

-n  rz 行号在自己字段的最右方显示 且加0

-w 行号字段的占用的字符数

# nl列出/etc/issue内容  

[root@localhost tmp]# nl /etc/issue
     1\S
     2Kernel \r on an \m


# 空行显示行号

[root@localhost tmp]# nl -b a /etc/issue
 1\S
 2Kernel \r on an \m
 3


 

# 行号前加上0

[root@localhost tmp]# nl -b a -n rz /etc/issue
000001\S
000002Kernel \r on an \m
000003


# 行号前加上0 改成3位

[root@localhost tmp]# nl -b a -n rz -w 3 /etc/issue
001\S
002Kernel \r on an \m
003
[root@localhost tmp]#


3.2、可翻页检视

more less 

(1)more (一页一页翻页)

# more  /etc/man_db.conf


空格键space 代表向下翻一页

Enter 代表向下翻一行

/字符串 搜索字符串

:f 立刻显示出文件名以及目前显示

q 立刻离开more 

b 或 ctrl-b 代表往回翻页 不过这动作只对文件有用 对管线无用

注意:more不能向前翻页

(2)less 一页一页翻动

less 可以向下或向上搜寻

空格键 向下翻页

pagedown 向下翻页

pageup 向上翻页

/字符串 向下搜寻字符串

?字符串 向上搜寻字符串

n 重复前一个搜索 

N 反向重复前一个搜索

g 前进到这个资料的第一行去

G 前进到这个数据的最后一行去 

q 离开less

3.3、资料截取

head tail 都是以行为单位来截取的

(1)head 取出前面几行

head [-n number] 文件

选项: 

-n 后面加数字  表示几行的意思

# 默认显示前10行 

[root@localhost tmp]# head /etc/man_db.conf 
# 
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:


# 显示前20行 -n  20 

[root@localhost tmp]# head -n 20 /etc/man_db.conf 
# 
#
# This file is used by the man-db package to configure the man and cat paths.
# It is also used to provide a manpath for those without one by examining
# their PATH environment variable. For details see the manpath(5) man page.
#
# Lines beginning with `#' are comments and are ignored. Any combination of
# tabs or spaces may be used as `whitespace' separators.
#
# There are three mappings allowed in this file:
# --------------------------------------------------------
# MANDATORY_MANPATHmanpath_element
# MANPATH_MAPpath_elementmanpath_element
# MANDB_MAPglobal_manpath[relative_catpath]
#---------------------------------------------------------
# every automatically generated MANPATH includes these fields
#
#MANDATORY_MANPATH /usr/src/pvm3/man
#
MANDATORY_MANPATH/usr/man
[root@localhost tmp]#


# 如果接的是负数,例如上面范例的-n -100 时,代表列前的所有行数, 但不包括后面 100 行

范例:如果后面 100 行的数据都不打印,只打印/etc/man_db.conf 的前面几行,该如何是好?

[root@localhost tmp]# head -n -100 /etc/man_db.conf 

(2)取出后面几行

tail [-n number] 文件 

选项:

-n 后面接数字 代表显示几行的意思

-f :表示持续侦测后面所接的档名,要等到按下[ctrl]-c 才会结束 tail 的侦测

# 显示最后10行 

[root@localhost tmp]# tail /etc/man_db.conf 
# formatted for a terminal of the given width, regardless of the width of
# the terminal actually being used. This should generally be within the
# range set by MINCATWIDTH and MAXCATWIDTH.
#
#CATWIDTH0
#
#---------------------------------------------------------
# Flags.
# NOCACHE keeps man from creating cat pages.
#NOCACHE


# 显示最后20行 

[root@localhost tmp]# tail -n 20 /etc/man_db.conf 
#
#---------------------------------------------------------
# Range of terminal widths permitted when displaying cat pages. If the
# terminal falls outside this range, cat pages will not be created (if
# missing) or displayed.
#
#MINCATWIDTH80
#MAXCATWIDTH80
#
# If CATWIDTH is set to a non-zero number, cat pages will always be
# formatted for a terminal of the given width, regardless of the width of
# the terminal actually being used. This should generally be within the
# range set by MINCATWIDTH and MAXCATWIDTH.
#
#CATWIDTH0
#
#---------------------------------------------------------
# Flags.
# NOCACHE keeps man from creating cat pages.
#NOCACHE
[root@localhost tmp]#


# 如果 不知道文件有几行 只想显示100行 

# tail -n +100 /etc/man_db.conf


3.4、非纯文档 od

3.5、修改文件时间或建置新档 touch 

linux会有3个时间参数 

modification time(mtime)

status time (ctime)

access time (atime)

四、文件与目录的默认权限与隐藏权限

4.1、文件预设权限 umask 

umask 指定 目前用户在建立文件或目录时候的权限 默认值 

# 后面3个数字与权限有关  第一个数字为特殊权限

[root@localhost tmp]# umask 
0022


# -S选项 以符号方式显示权限 

[root@localhost tmp]# umask -S
u=rwx,g=rx,o=rx


默认权限属性上,目录与文件是不一样的,预设情况:

文件预设 没有可执行x权限 只有rw 最大666 权限:-rw-rw-rw-

目录预设 默认为777 权限:drwxrwxrwx 


泰山崩于前而色不变,麋鹿兴于左而目不瞬,然后可以制利害,可以待敌。--心术

评论

^