Detailed explanation of Linux commands related to file and directory attributes, collection

Long article dry goods: Detailed explanation of Linux commands related to file and directory attributes, collection~

Linux should be learned  today

 

 

 

 

 

Linux directory structure

 

For every Linux learner, understanding the directory structure of the Linux file system is an important step to learn Linux well. To understand the standard of the linux file directory structure and the detailed functions of each directory is for us to make good use of the linux system Regardless of the importance, let's start to understand the relevant knowledge of the Linux directory structure.

When using Linux, if you pass ls -l /, you will find that there are many directories under /, such as etc, usr, var, bin... etc. In these directories, we Go inside and find that there are also many directories or files. The file system looks like a tree structure under Linux, so we can call the structure of the file system a tree structure.

The file system is used to organize and arrange file access, so it is visible. In Linux, we can use tools such as ls to view its structure. In the Linux system, all we see are tree structures; For example, the operating system is installed in a file system, and it appears as a tree structure starting from /. The top of the linux file system is /, we call / the root of Linux, which is the file system of the Linux operating system. The entrance of the Linux file system is /, and all directories, files, and devices are under /. / is the organizer of the Linux file system and the top leader.

Since Linux is an open source code, major companies and organizations do their own operations and programming based on the core code of Linux. This results in a different directory under the root. As a result, individuals cannot use other people's PCs with Linux systems. Because you don't know some basic configuration, where are the files. . . This caused confusion. This is the reason for the birth of the FHS (Filesystem Hierarchy Standard) organization. This organization is a group spontaneously formed by linux enthusiasts, mainly to make some basic requirements for linux, so that the operator will not become illiterate in Linux by changing a host.

According to the official document of FHS (http://www.pathname.com/fhs/), their main purpose is to let users know that the installed software is usually placed in that directory, so they want independent software development Manufacturers, operating system creators, and users who want to maintain the system can all follow FHS standards. In other words, the focus of FHS is to regulate what kind of data should be placed in each specific directory. This has many benefits, because the Linux operating system can develop the unique style that developers want under its existing appearance (the directory structure remains unchanged).

In fact, FHS has been continuously revised based on past experience. FHS defines the directory into four interactive forms according to the frequency of use of the file system and whether users are allowed to change it at will. It's a bit like this:

 

Shareable

Unshareable

Static

/usr (where the software is placed)

/etc (configuration file)

/opt (third-party cooperation software)

/boot (boot and kernel files)

Variable

/var/mail (user mail box)

/var/run (program related)

/var/spool/news (newsgroup)

/var/lock (program related)

 

Four types:

1. Shareable:

It can be shared with other systems for mounting directories, so data including executable files and user emails can be shared with other hosts on the network for mounting directories;

2. Unshareable:

The device files or socket files related to the program running on your own machine are only related to your own machine, so of course it is not suitable for sharing with other hosts.

3. Constant:

Some data does not change frequently, and does not change following the distribution. For example, library, file description file, host service configuration file managed by system administrator, etc.;

4. Variable:

Data that changes frequently, such as log files, newsgroups that general users can receive by themselves, etc.

 

In fact, for the directory tree structure, FHS only defines what data should be placed under the three-level directories, which are the definitions of the three directories below:

/ (root, root directory): related to booting the system;

/usr (unix software resource): related to software installation/execution;

/var (variable): Related to the system operation process.

 

1. The meaning and content of the root directory (/):

The root directory is the most important directory of the entire system, because not only all directories are derived from the root directory, but the root directory is also related to actions such as booting/restore/system repair. As the system needs specific boot software, core files, programs needed for booting, library and other file data when booting the system, if there is an error in the system, the root directory must also contain a program that can repair the file system. Because the root directory is so important, in terms of FHS requirements, he hopes that the root directory should not be placed in a very large partition, because the larger the partition you will put more data, so that the partition where the root directory is located There may be more opportunities for errors.

Therefore, the FHS standard recommends: The partition where the root directory (/) is located should be as small as possible, and the software installed by the application should not be placed in the same partition as the root directory. Keep the root directory as small as possible. Not only is the performance better, but the file system where the root directory is located is also less prone to problems. To put it bluntly, the root directory is the same as the C drive of Windows.

Based on the above reasons, FHS believes that the root directory (/) should contain the following subdirectories:

table of Contents

File content should be placed

/bin

The system has many directories where executable files are placed, but /bin is special. Because /bin puts instructions that can be operated in single maintenance mode. The commands under /bin can be used by root and general accounts, mainly: cat, chmod (modify permissions), chown, date, mv, mkdir, cp, bash and other commonly used commands.

/boot

Mainly place the files used for opening the machine, including Linux core files, boot menu and configuration files required for booting, etc. The commonly used file name of the Linux kernel is: vmlinuz. If you are using the boot management program grub, the directory /boot/grub/ will also exist.

/dev

On Linux systems, any devices and peripherals are stored in this directory as files. Just by accessing a certain file in this directory, it is equivalent to accessing a certain device. The more important files are /dev/null, /dev/zero, /dev/tty, /dev/lp*, /dev/hd*, /dev/sd*, etc.

/etc

Almost all the main configuration files of the system are placed in this directory, such as personnel account and password files, startup files of various services, and so on. Generally speaking, the attributes of each file in this directory can be accessed by general users, but only root has the authority to modify it. FHS recommends not to place executable files (binary) in this directory. The more important files are: /etc/inittab, /etc/init.d/, /etc/modprobe.conf, /etc/X11/, /etc/fstab, /etc/sysconfig/ and so on. In addition, the important directories are: /etc/init.d/: The default startup scripts for all services are placed here, for example, if you want to start or close iptables: /etc/init.d/iptables start, / etc/init.d/ iptables stop

/etc/xinetd.d/: This is the configuration file directory of the services managed by the so-called super daemon.

/etc/X11/: Various configuration files related to X Window are here, especially the configuration files of the two X Servers, xorg.conf or XF86Config.

/home

This is the default user home directory (home directory) of the system. When you add a general user account, the default user home directory will be standardized here. More importantly, there are two codes for the home directory: ~: represents the home directory of the current user, and ~guest: represents the home directory of the user named guest.

/lib

There are many libraries in the system, and /lib places the libraries that will be used when booting, and the libraries that will be called by the commands under /bin or /sbin. What is a library? You can think of it as a plug-in, some commands must have these plug-ins to be able to successfully complete the execution of the program. Especially important is the /lib/modules/ directory, because this directory will place the core-related modules (drivers).

/media

media is the English for media. As the name implies, the removable device is placed under this /media. Devices including floppy disks, CDs, DVDs, etc. are temporarily mounted here. Common file names are: /media/floppy, /media/cdrom, etc.

/ mnt

If you want to temporarily mount some additional devices, it is generally recommended that you can place them in this directory. In the early days, this directory was used for the same purpose as /media. Only after having /media, this directory is used for temporary mounting.

/opt

This is a directory for third-party cooperative software. What is third-party collaborative software? For example, KDE, a desktop management system, is an independent project, but it can be installed on a Linux system, so KDE software is recommended to be placed in this directory. In addition, if you want to install additional software yourself (not provided by the original distribution), you can also install your software here. However, in previous Linux systems, we were still used to placing them in the /usr/local directory.

/root

The home directory of the system administrator (root). It is placed here because if you enter the single-person maintenance mode and only mount the root directory, the directory can have root's home directory, so we want the root's home directory and the root directory to be placed in the same partition.

/sbin

Linux has a lot of commands for setting up the system environment. These commands can only be used by root to configure the system, and other users can only query them at most. The ones placed under /sbin are needed during the boot process, which includes the commands needed to boot, repair, and restore the system. As for some server software programs, they are generally placed in /usr/sbin/. As for the system binary generated by the software installed on this machine, it is placed in /usr/local/sbin/. Common commands include: fdisk, fsck, ifconfig, init, mkfs, etc.

/srv

Srv can be regarded as the abbreviation of service, which is the data directory that these services need to access after some network services are started. Common services such as WWW, FTP, etc. For example, the web page data required by the WWW server can be placed in /srv/www/. Haha, it seems that the code we usually write should be put here.

/tmp

This is a place for general users or programs that are running to temporarily place files. This directory is accessible to anyone, so you need to clean it up regularly. Of course, important information cannot be placed in this directory. Because FHS even recommends that all data under /tmp should be deleted when booting.

事实上FHS针对根目录所定义的标准就仅限于上表,不过仍旧有些目录也需要我们了解一下,具体如下:

 

目录

应放置文件内容

/lost+found

这个目录是使用标准的ext2/ext3档案系统格式才会产生的一个目录,目的在于当档案系统发生错误时,将一些遗失的片段放置到这个目录下。 这个目录通常会在分割槽的最顶层存在,例如你加装一个硬盘于/disk中,那在这个系统下就会自动产生一个这样的目录/disk/lost+found

/proc

这个目录本身是一个虚拟文件系统(virtual filesystem)喔。 他放置的资料都是在内存当中,例如系统核心、行程资讯(process)(是进程吗?)、周边装置的状态及网络状态等等。因为这个目录下的资料都是在记忆体(内存)当中,所以本身不占任何硬盘空间。比较重要的档案(目录)例如: /proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/*等等。呵呵,是虚拟内存吗[guest]?

/sys

这个目录其实跟/proc非常类似,也是一个虚拟的档案系统,主要也是记录与核心相关的资讯。 包括目前已载入的核心模组与核心侦测到的硬体装置资讯等等。 这个目录同样不占硬盘容量。

除了这些目录的内容之外,另外要注意的是,因为根目录与开机有关,开机过程中仅有根目录会被挂载, 其他分区则是在开机完成之后才会持续的进行挂载的行为。就是因为如此,因此根目录下与开机过程有关的目录, 就不能够与根目录放到不同的分区去。那哪些目录不可与根目录分开呢?有底下这些:

/etc:配置文件

/bin:重要执行档

/dev:所需要的装置文件

/lib:执行档所需的函式库与核心所需的模块

/sbin:重要的系统执行文件

这五个目录千万不可与根目录分开在不同的分区。请背下来啊。 

 

二. /usr 的意义与内容:

依据FHS的基本定义,/usr里面放置的数据属于可分享的与不可变动的(shareable, static), 如果你知道如何透过网络进行分区的挂载(例如在服务器篇会谈到的NFS服务器),那么/usr确实可以分享给局域网络内的其他主机来使用喔。

/usr不是user的缩写,其实usr是Unix Software Resource的缩写, 也就是Unix操作系统软件资源所放置的目录,而不是用户的数据啦。这点要注意。FHS建议所有软件开发者,应该将他们的数据合理的分别放置到这个目录下的次目录,而不要自行建立该软件自己独立的目录。

 

因为是所有系统默认的软件(distribution发布者提供的软件)都会放置到/usr底下,因此这个目录有点类似Windows 系统的C:\Windows\ + C:\Program files\这两个目录的综合体,系统刚安装完毕时,这个目录会占用最多的硬盘容量。 一般来说,/usr的次目录建议有底下这些:

目录

应放置文件内容

/usr/X11R6/ 

为X Window System重要数据所放置的目录,之所以取名为X11R6是因为最后的X版本为第11版,且该版的第6次释出之意。 

/usr/bin/ 

绝大部分的用户可使用指令都放在这里。请注意到他与/bin的不同之处。(是否与开机过程有关) 

/usr/include/ 

c/c++等程序语言的档头(header)与包含档(include)放置处,当我们以tarball方式 (*.tar.gz 的方式安装软件)安装某些数据时,会使用到里头的许多包含档。 

/usr/lib/ 

包含各应用软件的函式库、目标文件(object file),以及不被一般使用者惯用的执行档或脚本(script)。 某些软件会提供一些特殊的指令来进行服务器的设定,这些指令也不会经常被系统管理员操作, 那就会被摆放到这个目录下啦。要注意的是,如果你使用的是X86_64的Linux系统, 那可能会有/usr/lib64/目录产生 

/usr/local/ 

统管理员在本机自行安装自己下载的软件(非distribution默认提供者),建议安装到此目录, 这样会比较便于管理。举例来说,你的distribution提供的软件较旧,你想安装较新的软件但又不想移除旧版, 此时你可以将新版软件安装于/usr/local/目录下,可与原先的旧版软件有分别啦。 你可以自行到/usr/local去看看,该目录下也是具有bin, etc, include, lib...的次目录 

/usr/sbin/ 

非系统正常运作所需要的系统指令。最常见的就是某些网络服务器软件的服务指令(daemon) 

/usr/share/ 

放置共享文件的地方,在这个目录下放置的数据几乎是不分硬件架构均可读取的数据, 因为几乎都是文本文件嘛。在此目录下常见的还有这些次目录:/usr/share/man:联机帮助文件

/usr/share/doc:软件杂项的文件说明

/usr/share/zoneinfo:与时区有关的时区文件

 

/usr/src/ 

一般原始码建议放置到这里,src有source的意思。至于核心原始码则建议放置到/usr/src/linux/目录下。 

 

三.  /var 的意义与内容:

如果/usr是安装时会占用较大硬盘容量的目录,那么/var就是在系统运作后才会渐渐占用硬盘容量的目录。 因为/var目录主要针对常态性变动的文件,包括缓存(cache)、登录档(log file)以及某些软件运作所产生的文件, 包括程序文件(lock file, run file),或者例如MySQL数据库的文件等等。常见的次目录有:

目录

应放置文件内容

/var/cache/

应用程序本身运作过程中会产生的一些暂存档

/var/lib/

程序本身执行的过程中,需要使用到的数据文件放置的目录。在此目录下各自的软件应该要有各自的目录。 举例来说,MySQL的数据库放置到/var/lib/mysql/而rpm的数据库则放到/var/lib/rpm去

/var/lock/

某些装置或者是文件资源一次只能被一个应用程序所使用,如果同时有两个程序使用该装置时, 就可能产生一些错误的状况,因此就得要将该装置上锁(lock),以确保该装置只会给单一软件所使用。 举例来说,刻录机正在刻录一块光盘,你想一下,会不会有两个人同时在使用一个刻录机烧片? 如果两个人同时刻录,那片子写入的是谁的数据?所以当第一个人在刻录时该刻录机就会被上锁, 第二个人就得要该装置被解除锁定(就是前一个人用完了)才能够继续使用

/var/log/

非常重要。这是登录文件放置的目录。里面比较重要的文件如/var/log/messages, /var/log/wtmp(记录登入者的信息)等。

/var/mail/

放置个人电子邮件信箱的目录,不过这个目录也被放置到/var/spool/mail/目录中,通常这两个目录是互为链接文件。

/var/run/

某些程序或者是服务启动后,会将他们的PID放置在这个目录下

/var/spool/

这个目录通常放置一些队列数据,所谓的“队列”就是排队等待其他程序使用的数据。 这些数据被使用后通常都会被删除。举例来说,系统收到新信会放置到/var/spool/mail/中, 但使用者收下该信件后该封信原则上就会被删除。信件如果暂时寄不出去会被放到/var/spool/mqueue/中, 等到被送出后就被删除。如果是工作排程数据(crontab),就会被放置到/var/spool/cron/目录中。

 

由于FHS仅是定义出最上层(/)及次层(/usr, /var)的目录内容应该要放置的文件或目录数据, 因此,在其他次目录层级内,就可以随开发者自行来配置了。

 

四. 目录树(directory tree) :

在Linux底下,所有的文件与目录都是由根目录开始的。那是所有目录与文件的源头, 然后再一个一个的分支下来,因此,我们也称这种目录配置方式为:目录树(directory tree), 这个目录树的主要特性有:

目录树的启始点为根目录 (/, root);

每一个目录不止能使用本地端的 partition 的文件系统,也可以使用网络上的 filesystem 。举例来说, 可以利用 Network File System (NFS) 服务器挂载某特定目录等。

每一个文件在此目录树中的文件名(包含完整路径)都是独一无二的。

 

如果我们将整个目录树以图的方法来显示,并且将较为重要的文件数据列出来的话,那么目录树架构就如下图所示:

图片

五. 绝对路径与相对路径

除了需要特别注意的FHS目录配置外,在文件名部分我们也要特别注意。因为根据档名写法的不同,也可将所谓的路径(path)定义为绝对路径(absolute)与相对路径(relative)。 这两种文件名/路径的写法依据是这样的:

绝对路径:

由根目录(/)开始写起的文件名或目录名称, 例如 /home/dmtsai/.bashrc;

相对路径:

相对于目前路径的文件名写法。 例如 ./home/dmtsai 或 http://www.cnblogs.com/home/dmtsai/ 等等。反正开头不是 / 就属于相对路径的写法

而你必须要了解,相对路径是以你当前所在路径的相对位置来表示的。举例来说,你目前在 /home 这个目录下, 如果想要进入 /var/log 这个目录时,可以怎么写呢?

cd /var/log   (absolute)

cd ../var/log (relative)

因为你在 /home 底下,所以要回到上一层 (../) 之后,才能继续往 /var 来移动的,特别注意这两个特殊的目录:

.  :代表当前的目录,也可以使用 ./ 来表示;

.. :代表上一层目录,也可以 ../ 来代表。

这个 . 与 .. 目录概念是很重要的,你常常会看到 cd .. 或 ./command 之类的指令下达方式, 就是代表上一层与目前所在目录的工作状态。

 

实例1:如何先进入/var/spool/mail/目录,再进入到/var/spool/cron/目录内?

命令:

cd /var/spool/mail

cd ../cron

说明:

由于/var/spool/mail与/var/spool/cron是同样在/var/spool/目录中。如此就不需要在由根目录开始写起了。这个相对路径是非常有帮助的,尤其对于某些软件开发商来说。 一般来说,软件开发商会将数据放置到/usr/local/里面的各相对目录。 但如果用户想要安装到不同目录呢?就得要使用相对路径。

 

实例2:网络文件常常提到类似./run.sh之类的数据,这个指令的意义为何?

说明:

由于指令的执行需要变量的支持,若你的执行文件放置在本目录,并且本目录并非正规的执行文件目录(/bin, /usr/bin等为正规),此时要执行指令就得要严格指定该执行档。./代表本目录的意思,所以./run.sh代表执行本目录下, 名为run.sh的文件。

 

Linux文件类型与扩展名

 

Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念。我们通过一般应用程序而创建的比如file.txt、file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux文件类型中衡量的话,大多是常规文件(也被称为普通文件)。

一. 文件类型

Linux文件类型常见的有:普通文件、目录文件、字符设备文件和块设备文件、符号链接文件等,现在我们进行一个简要的说明。

1. 普通文件 

我们用 ls -lh 来查看某个文件的属性,可以看到有类似-rwxrwxrwx,值得注意的是第一个符号是 - ,这样的文件在Linux中就是普通文件。这些文件一般是用一些相关的应用程序创建,比如图像工具、文档工具、归档工具... .... 或 cp工具等。这类文件的删除方式是用rm 命令。 另外,依照文件的内容,又大略可以分为:

1>. 纯文本档(ASCII):

这是Linux系统中最多的一种文件类型,称为纯文本档是因为内容为我们人类可以直接读到的数据,例如数字、字母等等。 几乎只要我们可以用来做为设定的文件都属于这一种文件类型。 举例来说,你可以用命令: cat ~/.bashrc 来看到该文件的内容。 (cat 是将一个文件内容读出来的指令).

2>. 二进制文件(binary):

Linux系统其实仅认识且可以执行二进制文件(binary file)。Linux当中的可执行文件(scripts, 文字型批处理文件不算)就是这种格式的文件。 刚刚使用的命令cat就是一个binary file。

3>. 数据格式文件(data): 

有些程序在运作的过程当中会读取某些特定格式的文件,那些特定格式的文件可以被称为数据文件 (data file)。举例来说,我们的Linux在使用者登录时,都会将登录的数据记录在 /var/log/wtmp那个文件内,该文件是一个data file,他能够透过last这个指令读出来! 但是使用cat时,会读出乱码~因为他是属于一种特殊格式的文件?

2. 目录文件

当我们在某个目录下执行,看到有类似 drwxr-xr-x ,这样的文件就是目录,目录在Linux是一个比较特殊的文件。注意它的第一个字符是d。创建目录的命令可以用 mkdir 命令,或cp命令,cp可以把一个目录复制为另一个目录。删除用rm 或rmdir命令。 

3. 字符设备或块设备文件 

如时您进入/dev目录,列一下文件,会看到类似如下的:

 

[root@localhost ~]# ls -al /dev/tty

crw-rw-rw- 1 root tty 5, 0 11-03 15:11 /dev/tty

[root@localhost ~]# ls -la /dev/sda1

brw-r----- 1 root disk 8, 1 11-03 07:11 /dev/sda1

我们看到/dev/tty的属性是 crw-rw-rw- ,注意前面第一个字符是 c ,这表示字符设备文件。比如猫等串口设备。我们看到 /dev/sda1 的属性是 brw-r----- ,注意前面的第一个字符是b,这表示块设备,比如硬盘,光驱等设备。

这个种类的文件,是用mknode来创建,用rm来删除。目前在最新的Linux发行版本中,我们一般不用自己来创建设备文件。因为这些文件是和内核相关联的。

与系统周边及储存等相关的一些文件, 通常都集中在/dev这个目录之下!通常又分为两种:

区块(block)设备档 :

就是一些储存数据, 以提供系统随机存取的接口设备,举例来说,硬盘与软盘等就是啦! 你可以随机的在硬盘的不同区块读写,这种装置就是成组设备!你可以自行查一下/dev/sda看看, 会发现第一个属性为[ b ]!

字符(character)设备文件:

亦即是一些串行端口的接口设备, 例如键盘、鼠标等等!这些设备的特色就是一次性读取的,不能够截断输出。 举例来说,你不可能让鼠标跳到另一个画面,而是滑动到另一个地方!第一个属性为 [ c ]。

4. 数据接口文件(sockets): 

数据接口文件(或者:套接口文件),这种类型的文件通常被用在网络上的数据承接了。我们可以启动一个程序来监听客户端的要求, 而客户端就可以透过这个socket来进行数据的沟通了。第一个属性为 [ s ], 最常在/var/run这个目录中看到这种文件类型了。

例如:当我们启动MySQL服务器时,会产生一个mysql.sock的文件。

 

[root@localhost ~]# ls -lh /var/lib/mysql/mysql.sock 

srwxrwxrwx 1 mysql mysql 0 04-19 11:12 /var/lib/mysql/mysql.sock

注意这个文件的属性的第一个字符是 s。

5. 符号链接文件: 

当我们查看文件属性时,会看到有类似 lrwxrwxrwx,注意第一个字符是l,这类文件是链接文件。是通过ln -s 源文件名 新文件名 。上面是一个例子,表示setup.log是install.log的软链接文件。怎么理解呢?这和Windows操作系统中的快捷方式有点相似。

符号链接文件的创建方法举例:

 

[root@localhost test]# ls -lh log2012.log

-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

[root@localhost test]# ln -s log2012.log  linklog.log

[root@localhost test]# ls -lh *.log

lrwxrwxrwx 1 root root   11 11-22 06:58 linklog.log -> log2012.log

-rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

 

6. 数据输送文件(FIFO,pipe):

FIFO也是一种特殊的文件类型,他主要的目的在解决多个程序同时存取一个文件所造成的错误问题。FIFO是first-in-first-out的缩写。第一个属性为[p] 。

 

二. Linux文件扩展名

1. 扩展名类型

基本上,Linux的文件是没有所谓的扩展名的,一个Linux文件能不能被执行,与他的第一栏的十个属性有关, 与档名根本一点关系也没有。这个观念跟Windows的情况不相同喔!在Windows底下, 能被执行的文件扩展名通常是 .com .exe .bat等等,而在Linux底下,只要你的权限当中具有x的话,例如[ -rwx-r-xr-x ] 即代表这个文件可以被执行。

不过,可以被执行跟可以执行成功是不一样的~举例来说,在root家目录下的install.log 是一个纯文本档,如果经由修改权限成为 -rwxrwxrwx 后,这个文件能够真的执行成功吗? 当然不行~因为他的内容根本就没有可以执行的数据。所以说,这个x代表这个文件具有可执行的能力, 但是能不能执行成功,当然就得要看该文件的内容.

虽然如此,不过我们仍然希望可以藉由扩展名来了解该文件是什么东西,所以,通常我们还是会以适当的扩展名来表示该文件是什么种类的。底下有数种常用的扩展名:

*.sh : 脚本或批处理文件 (scripts),因为批处理文件为使用shell写成的,所以扩展名就编成 .sh

*Z, *.tar, *.tar.gz, *.zip, *.tgz: 经过打包的压缩文件。这是因为压缩软件分别为 gunzip, tar 等等的,由于不同的压缩软件,而取其相关的扩展名!

*.html, *.php:网页相关文件,分别代表 HTML 语法与 PHP 语法的网页文件。 .html 的文件可使用网页浏览器来直接开启,至于 .php 的文件, 则可以透过 client 端的浏览器来 server 端浏览,以得到运算后的网页结果。

基本上,Linux系统上的文件名真的只是让你了解该文件可能的用途而已,真正的执行与否仍然需要权限的规范才行。例如虽然有一个文件为可执行文件,如常见的/bin/ls这个显示文件属性的指令,不过,如果这个文件的权限被修改成无法执行时,那么ls就变成不能执行。

上述的这种问题最常发生在文件传送的过程中。例如你在网络上下载一个可执行文件,但是偏偏在你的 Linux系统中就是无法执行!呵呵!那么就是可能文件的属性被改变了。不要怀疑,从网络上传送到你的 Linux系统中,文件的属性与权限确实是会被改变的。

2. Linux文件名长度限制:

在Linux底下,使用预设的Ext2/Ext3文件系统时,针对文件名长度限制为:

单一文件或目录的最大容许文件名为 255 个字符

包含完整路径名称及目录 (/) 之完整档名为 4096 个字符

是相当长的档名!我们希望Linux的文件名可以一看就知道该文件在干嘛的, 所以档名通常是很长很长。

3. Linux文件名的字符的限制:

由于Linux在文字接口下的一些指令操作关系,一般来说,你在设定Linux底下的文件名时, 最好可以避免一些特殊字符比较好!例如底下这些:

* ? > < ; & ! [ ] | \ ' " ` ( ) { }

因为这些符号在文字接口下,是有特殊意义的。另外,文件名的开头为小数点“.”时, 代表这个文件为隐藏文件!同时,由于指令下达当中,常常会使用到 -option 之类的选项, 所以你最好也避免将文件档名的开头以 - 或 + 来命名。

linux文件属性详解

 

Linux 文件或目录的属性主要包括:文件或目录的节点、种类、权限模式、链接数量、所归属的用户和用户组、最近访问或修改的时间等内容。具体情况如下:

命令: 

ls -lih

输出:

 

[root@localhost test]# ls -lih

总计 316K

2095120 lrwxrwxrwx 1 root root   11 11-22 06:58 linklog.log -> log2012.log

2095112 -rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

2095110 -rw-r--r-- 1 root root   61 11-13 06:03 log2013.log

2095107 -rw-r--r-- 1 root root    0 11-13 06:03 log2014.log

2095117 -rw-r--r-- 1 root root    0 11-13 06:06 log2015.log

2095118 -rw-r--r-- 1 root root    0 11-16 14:41 log2016.log

2095119 -rw-r--r-- 1 root root    0 11-16 14:43 log2017.log

2095113 drwxr-xr-x 6 root root 4.0K 10-27 01:58 scf

2095109 drwxrwxr-x 2 root root 4.0K 11-13 06:08 test3

2095131 drwxrwxr-x 2 root root 4.0K 11-13 05:50 test4

说明:

第一列:inode

第二列:文件种类和权限;

第三列: 硬链接个数;

第四列: 属主;

第五列:所归属的组;

第六列:文件或目录的大小;

第七列和第八列:最后访问或修改时间;

第九列:文件名或目录名

 

我们以log2012.log为例:

 

2095112 -rw-r--r-- 1 root root 296K 11-13 06:03 log2012.log

 

inode 的值是:2095112 

文件类型:文件类型是-,表示这是一个普通文件; 关于文件的类型,请参考:Linux文件类型与扩展名 

文件权限:文件权限是rw-r--r-- ,表示文件属主可读、可写、不可执行,文件所归属的用户组不可写,可读,不可执行,其它用户不可写,可读,不可执行;

 

硬链接个数: log2012.log这个文件没有硬链接;因为数值是1,就是他本身;

文件属主:也就是这个文件归哪于哪个用户 ,它归于root,也就是第一个root;

文件属组:也就是说,对于这个文件,它归属于哪个用户组,在这里是root用户组;

文件大小:文件大小是296k个字节;

访问可修改时间 :这里的时间是最后访问的时间,最后访问和文件被修改或创建的时间,有时并不是一致的;

当然文档的属性不仅仅包括这些,这些是我们最常用的一些属性。

关于inode:

inode 译成中文就是索引节点。每个存储设备或存储设备的分区(存储设备是硬盘、软盘、U盘等等)被格式化为文件系统后,应该有两部份,一部份是inode,另一部份是Block,Block是用来存储数据用的。而inode呢,就是用来存储这些数 据的信息,这些信息包括文件大小、属主、归属的用户组、读写权限等。inode为每个文件进行信息索引,所以就有了inode的数值。操作系统根据指令, 能通过inode值最快的找到相对应的文件。

做个比喻,比如一本书,存储设备或分区就相当于这本书,Block相当于书中的每一页,inode 就相当于这本书前面的目录,一本书有很多的内容,如果想查找某部份的内容,我们可以先查目录,通过目录能最快的找到我们想要看的内容。虽然不太恰当,但还是比较形象。

当我们用ls 查看某个目录或文件时,如果加上-i 参数,就可以看到inode节点了;比如我们前面所说的例子:

 

[root@localhost test]#  ls -li log2012.log 

2095112 -rw-r--r-- 1 root root 302108 11-13 06:03 log2012.log

log2012.log 的inode值是 2095112 ; 查看一个文件或目录的inode,要通过ls 命令的的 -i参数。

END

Guess you like

Origin blog.csdn.net/wzlsunice88/article/details/111225931