魏蓝

以梦为马

导航

复习之文件目录

1.touch命令:用于修改或者目录的时间属性,包括存取时间和更改时间。若文件不存在,系统会建立一个新的文件。

语法:

touch [-acfm] [-d<日期时间>] [-r<参考文件或目录>] [-t<日期时间>] [--help]

参数说明:

a:改变档案的读取时间记录(atime和ctime)

m:改变档案的修改时间记录(mtime和ctime)

d:设定时间与日期,可以使用各种不同的格式

t:设定档案时间记录,格式与date指令相同

范例:创建一个新文件

[root@centos7 data]# ls
[root@centos7 data]# touch file
[root@centos7 data]# ls
file
[root@centos7 data]# stat file
  File: ‘file’
  Size: 0               Blocks: 0          IO Block: 4096   regular empty file
Device: 803h/2051d      Inode: 67          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:default_t:s0
Access: 2022-02-05 09:18:19.259013812 +0800
Modify: 2022-02-05 09:18:19.259013812 +0800
Change: 2022-02-05 09:18:19.259013812 +0800
 Birth: -

 

 

2.查看文件类型用file

[root@centos7 data]# file file
file: empty
[root@centos7 data]# file file1
file: ASCII text

 

 

3.文件命名规则:

1)文件名最长为255个字节

2)包括路径在内文件名称最长4095个字节

3)蓝色->目录 绿色->可执行文件 红色->压缩文件 浅蓝色->链接文件 灰色->其他文件

4)除了/和NUL,所有字符都有效,但使用特殊字符的目录名和文件不推荐使用,有些字符需要用引号来引用

 

 

4.改变后缀颜色的文件

/etc/DIR_COLORS

 

 

5.1)生成一个名为$abc的文件

[root@centos7 data]# touch '$abc'
[root@centos7 data]# ll $abc
total 4
-rw-r--r--. 1 root root  0 Feb  5 09:31 $abc

注意:这里要用单引号,不能用双引号,因为双引号会识别$,会把abc当成一个变量,而这个变量未定义,所以touch默认会找一个名为空的文件

[root@centos7 data]# touch "$abc"
touch: cannot touch ‘’: No such file or directory

同样,删除也一样

[root@centos7 data]# rm -rf '$abc'
[root@centos7 data]# ls
file

2)用touch生成一个名为-a的文件

以为-a是touch的参数所以会出现下面的情况

[root@centos7 data]# touch -a
touch: missing file operand
Try 'touch --help' for more information.

所以我们需要改变思路,将参数那一项用--加一个空格表示没有参数即可:

[root@centos7 data]# touch -- -a
[root@centos7 data]# ls
-a  file

当然删除同理:

[root@centos7 data]# rm -rf -- -a
[root@centos7 data]# ls
file

 

 

6.linux下的文件类型

1)- 普通文件

2)d 目录文件

3)b 块设备

4)c 字符设备

5)l 符号链接文件

6)p 管道文件(pipe)

7)s 套接字文件(socket)

 

 

7.显示当前工作目录

1)每个SHELL和系统进程都有一个当前的工作目录

2)CWD:current work direcctory

3)显示当前SHELL CWD的绝对路径

pwd(printing working directory):

-P 显示真实物理路径   -L 显示链接路径(默认)

[root@centos7 dir1]# pwd -P    
/data/dir1
[root@centos7 dir1]# pwd -L    
/data/dir1

 

 

8.查看文件状态

1)stat

2)三个时间戳:

access time:访问时间,atime,读取文件内容

modify time:修改时间,mtime,改变文件内容(数据)

change time:改变时间,ctime,元数据发生改变

[root@centos7 dir1]# stat /data/dir1
  File: ‘/data/dir1’
  Size: 6               Blocks: 0          IO Block: 4096   directory
Device: 803h/2051d      Inode: 67          Links: 2
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Context: unconfined_u:object_r:default_t:s0
Access: 2022-02-05 09:57:53.018038076 +0800
Modify: 2022-02-05 09:57:53.018038076 +0800
Change: 2022-02-05 09:57:53.018038076 +0800
 Birth: -

 

 

9.绝对和相对路径

1)绝对路径:以正斜杠开始,完整的文件的位置路径,可用于任何想指定一个文件名的时候

2)相对路径:不以斜线开始,指定相对于当前工作目录或某目录的位置,可以作为一个简短的形式指定一个文件名

3)basename

[root@centos7 ~]# basename /etc/lvm/cache
cache

4)dirname

[root@centos7 ~]# dirname /etc/lvm/cache    
/etc/lvm

 

 

10更改目录

1)cd(change directory)改变目录:

使用绝对或者相对路径:

[root@centos7 ~]# cd /etc/lvm/cache
[root@centos7 cache]# 
[root@centos7 ~]# cd ../etc/lvm/cache
[root@centos7 cache]# 

切换至父目录

[root@centos7 etc]# cd ..
[root@centos7 /]# cd ..
[root@centos7 /]# pwd
/
[root@centos7 /]# cd ../..
[root@centos7 /]# pwd
/

切换当前用户主目录

[root@centos7 /]# cd
[root@centos7 ~]# pwd
/root

切换至以前的工作目录

[root@centos7 ~]# cd -
/
[root@centos7 /]# pwd
/

2)选项-P

3)相关环境变量:

PWD:当前工作路径

[root@centos7 /]# echo $PWD
/

OLDPWD:上一次目录路径

[root@centos7 /]# echo $OLDPWD
/root

 

 

11.列出目录内容ls

1)列出当前目录的内容或指定目录

2)用法:

ls [OPTIONS] [FILE_OR_DIRS]

3)示例:

ls -a 包含隐藏文件

[root@centos7 ~]# ls -a
.              .bash_profile   .cache   Desktop    .esd_auth      .mozilla  Public     .viminfo
..             .bash_profiley  .config  Documents  .ICEauthority  Music     Templates  y
.bash_history  .bashrc         .dbus    Downloads  .local         Pictures  Videos

ls -l 显示额外的信息

[root@centos7 ~]# ls -l
total 4
drwxr-xr-x. 2 root root   6 Feb  3 21:00 Desktop
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Documents
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Downloads
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Music
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Pictures
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Public
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Templates
drwxr-xr-x. 2 root root   6 Jan  1 01:28 Videos
-rw-r--r--. 1 root root 178 Feb  3 21:31 y

ls -R 目录递归通过

[root@centos7 data]# ls -R
.:
dir1

./dir1:
f1

ls -ld 目录和符号链接信息

[root@centos7 ~]# ls -ld
dr-xr-x---. 15 root root 4096 Feb  5 09:22 .

ls -1 文件分行显示

[root@centos7 ~]# ls -1
Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videos

ls -S 文件从大到小排序

[root@centos7 ~]# ls -S
y  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

ls -t 文件按mtime排序

[root@centos7 ~]# ls -t
y  Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

ls -u 配合-t选项,显示并按atime,从新到旧排序

[root@centos7 ~]# ls -ut
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  y

ls -U 按目录存放顺序显示

[root@centos7 ~]# ls -U
Desktop  Downloads  Templates  Public  Documents  Music  Pictures  Videos  y

ls -X 按文件后缀排序

[root@centos7 ~]# ls -X
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos  y

 

 

12.df命令:命令用于显示目前在Linux系统上的文件系统磁盘使用情况统况

语法:

df [选项] ... [file]
[root@centos7 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          915780       0    915780   0% /dev
tmpfs             931512       0    931512   0% /dev/shm
tmpfs             931512   10640    920872   2% /run
tmpfs             931512       0    931512   0% /sys/fs/cgroup
/dev/sda2       52403200 5029468  47373732  10% /
/dev/sda3       31441920   33024  31408896   1% /data
/dev/sda1        1038336  184100    854236  18% /boot
tmpfs             186304      32    186272   1% /run/user/0
/dev/sr0         9961428 9961428         0 100% /run/media/root/CentOS 7 x86_64

 

 

13.bash的快捷键(了解)

1)ctrl + l 清屏,相当于clear命令

2)ctrl + o 执行当前命令,并重新显示本命令

3)ctrl + s 阻止屏幕输出,锁定

4)ctrl + q 允许屏幕输入

5)ctrl + c 终止命令

6)ctrl + z 挂起命令

7)ctrl + a 光标移到命令行首,相当于Home键

8)ctrl + e 光标移到命令行尾,相当于End键

9)ctrl + f 光标向右移动一个字符

10)ctrl + b 光标向左移动一个字符

11)alt + f 光标向右移动一个单词尾

12)alt + b 光标向左移动一个单词首

13)alt + r 删除当前整行

14)ctrl + xx 光标在命令行首和光标之间移动

15)ctrl + u 从光标处删除至命令行首

16)ctrl + k 从光标处删除至命令行尾

17)ctrl + w 从光标处向左删除至单词首

18)ctrl + d 删除光标处的一个字符

19)alt + d 从光标处删除至单词尾

20)ctrl + h 删除光标前的一个字符

21)ctrl + y 将删除的字符粘贴至光标后

22)alt + c 将光标处开始向右更改为首字母大写的单词

23)alt + u 从光标处开始,将右边一个单词改为大写

24)alt + l 从光标处开始,将右边一个单词改为小写

25)ctrl + t 交换光标处和之前的字符的位置

26)alt + t 交换光标处和之前的单词的位置

27)alt + N 提示输入指定字符后,重复显示该字符N次

注意:alt组合快捷键经常和其他软件冲突

posted on 2022-02-05 11:26  魏蓝  阅读(57)  评论(0编辑  收藏  举报