文件系统小结2

网友投稿 218 2022-10-30


文件系统小结2

alias:定义别名

显示当前shell下所有可用的命令别名

[root@localhost ~]# alias

alias cp='cp -i'

alias egrep='egrep --color=auto'

alias fgrep='fgrep --color=auto'

alias grep='grep --color=auto'

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias mv='mv -i'

alias rm='rm -i'

alias which='alias | /usr/bin/which--tty-only --read-alias --show-dot --show-tilde'

定义别名NAME,相当于执行命令VALUE

[root@localhost ~]#alias mv='mv -i'(单引号)

在命令行中定义的别名,仅在当前shell进程中有效,若要永久有效,需定义在配置文件中

(PS:切换shell执行~]#bin/csh,即执行csh,exit退出此shell)

对当前用户的配置文件:~/.bashrc

对所有用户的配置文件:/etc/bashrc(需有管理员权限)

(需重新登录后生效,或执行source/path/to/config_file   ./path/to/config_file)

rm:删除文件

常用选项

-i:交互式

-f:强制删除

-r:递归删除

eg:~]#rm –rf /,删除全部文件

mv:移动并重命名文件

~]#mv a b,在当前目录下,将a重命名为b

常用选项

-i:交互式

-f:强制

tree:显示目录树

常用选项

-d:只显示目录

-L(level):指定显示层级数目

-p(pattern):只显示由指定通配符匹配的路径

mkdir:创建目录

常用选项

-p:自动创建所需各目录

-v:显示详细信息

-m(mode):指定创建目录的权限

rkdir:删除空目录

常用选项

-p:递归删除空目录

-v:显示详细信息

rm –r:递归删除目录树

inode:索引节点编号

[root@localhost ~]# ls –i(查看文件inode)

201364469 anaconda-ks.cfg  201453315 Downloads   67354234 Public

134361364 Desktop          201453316 Music           1704 Templates

134361365 Documents             1705 Pictures    67354235 Videos

不同分区内文件的inode编号可能相同

同一分区内文件的inode编号不能相同,若有相同,则为同一文件

[root@localhost testdir]# cat aa

kkk

aaa

aaa

[root@localhosttestdir]# ln aa bb(ln创建文件硬链接,硬链接不能跨分区)

[root@localhost testdir]# ls

aa bb

[root@localhost testdir]# ls -l

total 8

-rw-r--r-- 2 root root 12 Jul 31 20:14 aa

-rw-r--r-- 2 root root 12 Jul 31 20:14 bb

[root@localhost testdir]# stat aa bb

File: ‘aa’

Size: 12                 Blocks: 8          IO Block: 4096   regular file

Device: 802h/2050d         Inode: 134333665  Links: 2

Access: (0644/-rw-r--r--)  Uid: (   0/    root)   Gid: (   0/    root)

Access: 2016-07-31 20:14:57.895309997 +0800

Modify: 2016-07-31 20:14:54.642310202 +0800

Change: 2016-07-31 20:15:06.910309428 +0800

Birth: -

File: ‘bb’

Size: 12                 Blocks: 8          IO Block: 4096   regular file

Device: 802h/2050d         Inode: 134333665  Links: 2

Access: (0644/-rw-r--r--)  Uid: (   0/    root)   Gid: (   0/    root)

Access: 2016-07-31 20:14:57.895309997 +0800

Modify: 2016-07-31 20:14:54.642310202 +0800

Change: 2016-07-31 20:15:06.910309428 +0800

Birth: -

可见aa与bb除文件名不同外,元数据完全相同

~]#ln –s:创建软链接

用法:~]#ln –s filename[linkname](注意路径)

[root@localhost testdir]# touch f1

[root@localhost testdir]# ls

f1

[root@localhost testdir]# ln -s f1 f2

[root@localhost testdir]# ll -i f1 f2

134333665 -rw-r--r-- 1 root root 0 Jul 3120:35 f1

134333666 lrwxrwxrwx 1 root root 2 Jul 3120:35 f2 -> f1

[root@localhost testdir]# cat f2

[root@localhost testdir]# echo xxx > f1

[root@localhost testdir]# ls -l -i f1 f2

134333665 -rw-r--r-- 1 root root 4 Jul 3120:36 f1

134333666 lrwxrwxrwx 1 root root 2 Jul 3120:35 f2 -> f1

[root@localhost testdir]# cat f2

xxx

软链接可跨分区

软链接文件路径的路径应是相对于软链接文件的路径,或者可以写绝对路径

每个分区提供的inode数量固定

df –i:可查看分区的inode编号数量值

[root@localhost ~]# df -i

Filesystem       Inodes     IUsed     IFree    IUse%   Mountedon

/dev/sda2      41943040   6388    41936652    1%      /

devtmpfs        121534    379      121155     1%      /dev

tmpfs           125166     1        125165    1%      /dev/shm

tmpfs           125166     495      124671    1%      /run

tmpfs           125166    13       125153     1%      /sys/fs/cgroup

/dev/sda3      20971520   87328     20884192  1%      /usr

/dev/sda1       499712    329      499383     1%      /boot

tmpfs           125166     1        125165    1%      /run/user/0

file:查看文件类型

语法:~]#file [option]

OPTION:

[root@localhost testdir]# file f1

f1: ASCII text

[root@localhost testdir]# cat f1

/etc/issue

/testdir/f1

-b:列出文件辨识结果,不显示文件名称

[root@localhost testdir]# file -b f1

ASCII text

-c:详细显示指令执行过程

[root@localhost testdir]# file -c f1

contoffset        typeopcode     mask         value         desc

-f:列出文件所包含文件内容所指的文件类型

[root@localhost testdir]# file -f f1

/etc/issue:  ASCII text

/testdir/f1: ASCII text


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:TCP三次握手、糊涂窗口、粘包问题
下一篇:3分钟纯 Java 注解搭个管理系统的示例代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~