一、文件命名规则
(1)不能使用/来当文件名,/是用来做根的,也是用来做路径分隔符的;
(2)文件名不能超过255个字符;
(3)区分大小写file File FILE fiLe;
(4)目录也是文件,在同一路径下,两个文件不能同名;
二、命令学习
1.touch
功能描述:
新建空文件,或更新文件时间标记
语法:
touch [文件名]
范例:
[root@localhost ~]# touch hellotest.txt #创建一个名为hellotest.txt的文件
[root@localhost ~]# ll #长格式详细信息显示
total 4
-rw-------. 1 root root 1536 Mar 8 21:09 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Mar 11 09:27 hellotest.txt #时间为09:27
[root@localhost ~]# touch hellotest.txt #修改名为hellotest.txt文件的时间
[root@localhost ~]# ll
total 4
-rw-------. 1 root root 1536 Mar 8 21:09 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 Mar 11 09:28 hellotest.txt #时间为09:28
[root@localhost ~]#
2.mkdir
功能描述:
创建新的目录(Make Directory)
语法:
mkdir [选项] [/路径/]目录名
选项:
-p 递归创建多级目录
范例:
[root@localhost ~]# mkdir 123 #创建了一个名为123的目录文件
[root@localhost ~]# ls
123 anaconda-ks.cfg hellotest.txt
[root@localhost ~]# mkdir -p aaa/bbb/ccc/ddd #创建了层级目录aaa/bbb/ccc/ddd
3.ln
Linux中的链接文件不同于Windows的快捷方式,Linux的链接文件分为软连接和硬链接。软链接时可以跨分区,但源文件不可删除,硬链接不可跨分区,但可以将源文件删除。
软链接
格式:
ln -s 源文件 链接文件(目标文件) 一定要写绝对路径!
a.软链接,以路径的形式存在。类似于Windows操作系统中的快捷方式;
b.软链接可以跨文件系统,硬链接不可以;
c.软链接可以对一个不存在的文件名进行链接;
d.软链接可以对目录进行链接;
硬链接
格式:
ln 源文件 链接文件(目标文件)
a.硬链接,以文件副本的形式存在,但不占用实际空间;
b.不允许给目录创建硬链接;
c.硬链接只有在同一个文件系统中才能创建;
d.可以以不同的文件名中存在同一个目录中,或者以相同的文件名存在于不同的目录下;
e.建立硬链接时,在另外的目录或本目录中增加目标文件的一个目录项,这样,一个文件就登记在多个目录中;
范例:
#软链接
[root@localhost ~]# touch hello.txt
[root@localhost ~]# ln -s /root/hello.txt /tmp/hi.txt #创建文件的软链接
[root@localhost ~]# ls -l /tmp/hi.txt
lrwxrwxrwx. 1 root root 15 Mar 11 16:18 /tmp/hi.txt -> /root/hello.txt
[root@localhost ~]# mkdir test
[root@localhost ~]# ln -s /root/test/ /var/test #创建目录的软链接
[root@localhost ~]# ll /var/test
lrwxrwxrwx. 1 root root 11 Mar 11 16:19 /var/test -> /root/test/
[root@localhost ~]#
#硬链接
[root@localhost ~]# ln /root/hello.txt /root/hello-1.txt #创建硬链接
[root@localhost ~]# rm -rf hello.txt #源文件删除后,链接文件仍然可以正常使用
[root@localhost ~]# ll /root/hello-1.txt
-rw-r--r--. 1 root root 0 Mar 11 16:17 /root/hello-1.txt
[root@localhost ~]#
stat #显示出文件的详细内容;