Unix/linux File System operation

Source: Internet
Author: User
Tags disk usage file permissions

As a computer user, do not understand the graphical operation of the file system does not count on the use of computers. So as a programmer, if you do not understand the command line operation of the Linux file system, you do not dare to say that you are a qualified programmer. We work in the use of Unix/linux as an application server, nothing more than to deploy our written software to a remote server, without the various operations on the file, if you do not manipulate the file then will be unable to move. Next, let's meet the Unix/linux file system.

1. local file system

Here we will discuss the file system (hard disk, CD-ROM,DVD-ROM,USB) for the local disk. This type of filesystem UFS (Unix file system), FAT (file Allocation files are usually the filesystem of Windows and DOS systems), NTFS (the New technology file system, usually Window s Nt,2000,xp file system), UDF (Universal Disk formt is usually a DVD file system), hfs+ (Hierarchical File system hierarchical filesystem, such as Mac OS X), ISO9660 usually C D-rom file system and EXT2 Extended file system (it is the Linux default kernel file system) and so on.

Having said that, what type of file system does CentOS 7 use in the virtual machines we use? Use DF-T to see it.

From the Type column we see that it uses the XFS file system, a high-performance log file system that was born in 1993 and was ported to Linux Systems in 2000. The above describes the disk-oriented local file system, in fact, there are network-oriented and temporary virtual file system, for example, TMPFS is a memory-oriented temporary file system.

2. Directory structure

To be proficient in working with files, you must understand the system's directory structure, Unix/linux uses a hierarchical file system structure, "/" is the root of the filesystem, and all other directories start here. We use the tree command to see the directory structure starting from the root, showing only a layer of depth. As follows:

?

The bin directory primarily stores binary executables, such as the PASSWD,CAT,VI program we used in the previous article. The boot directory holds the files that are used to start the system. The dev directory holds the device files. ETC directory to store system configuration files, such as user information, hosts information. Lib to store the files for the shared library. Media files are stored in the attached file. MNT stores the files that are hung on the mobile device. Opt for additional installation of the software can be specified to install in this directory, easy to manage. Proc exists the process information that the system is currently running. Root my system user home directory. Run did not find the relevant information. Sbin-Usr/sbin the necessary procedures for storage system management. SRV stores user-generated files for external service. SYS stores global device files, such as bus control. TMP holds temporary files. USR can store arbitrary files, such as online help pages that are used by many users. var stores variable-length files, such as log files.

3. Common commands

To manipulate files, you must first learn the navigation of the file system. Let's take a look at a few common navigation commands now!

    • The PWD displays the current directory, and we need to make sure that the current directory is the one we expect when we execute the command, so this command is often used. Shown below we are now in the/root directory?
    • CD (change directory) go to any directory we want to go to, such as we want to go to the/etc directory:?
    • Which and Whereis, some of the tools we normally use, if we want to know what directory they are really in, you can use which. For example, we want to know what directory the CD tool is located in, and you can do the following:? The difference between which and Whereis is that which searches for the content specified in the path of the environment variable, Whereis will look in the directory specified in path and MANPATH.
    • Find directories or files, for example, we need to find a file called Test in the/root directory:?
    • File to view the types of files, for example, what type of file is the test, display the result as a text file?
    • LS Displays the contents of the directory, if we want to see the contents of the root path, you can do the following:? The-l parameter can display the corresponding details of the file, owner, permission, size, last change time, symbolic link. At the same time we can also add the-a parameter to display all files, including. The hidden file at the beginning.
4. Types of files

You may have noticed that the left side of the file listed with the LS command has some information. For example Drwxr-xr-x, the first bit represents the file type, and the following 9 bits represent the permissions of the file. -Represents whether this is a text file, or an executable file. B means this is a block file, such as a hard disk. C-character device files, such as hard disks. D means this is a directory file. L represents this is a symbolic link that can be understood as a shortcut in a Windows system. P means that this is a pipeline for communication. s means that this is a socket for communication. Since we usually use symbolic links for our operations, we briefly introduce the following symbolic links. Unix/linux uses the Inode to refer to a file rather than a filename, and the inode is unique within a partition. There are 2 types of symbolic links, hard links and soft connections. Let's start by creating a file and then creating a hard link and a soft connection for it, respectively.

?

Next we write to the source files, the hard links, the soft links, and we will find that any one of them will be reflected on the other.

?

Since the effect is all the same, then what is the difference between a soft link and a hard link? Hard links are implemented using Inode, and soft links are implemented using filenames. So, if we delete the file, then we create a new file. At this point our soft link is still in effect, and the hard link has been invalidated. The following experimental data:

?

5. Permissions for files

When we use the Ls-l command to view a file, the leftmost string reflects the file's permissions, as in the following example:

?

If we can clearly understand the individual user's permissions on the file where to view, then the corresponding r,w,x are read, write, execute permissions. We can use chmod to change the permissions of the file, the operation of the time there are 2 choices, one is the use of symbolic mode, that is, rwx, and the other is absolute mode with 8 numbers, respectively, represents a kind of permission. Use the chmod user (a/u/g/o) +/-Permissions (rwx) file name command format to manipulate file permissions, experimental results:

?

?

We can also use absolute mode to manipulate file permissions, such as chmod 777 file, which represents the maximum operation permissions that all users have for file files. The absolute pattern of numbers represents the following meanings:

0 No permissions, 1 Execute permissions, 2 Write permissions, 3 execute and Write permissions, 4 Read permissions, 5 read and Execute permissions, 6 read and Write permissions, 7 all permissions. Here's a brain teaser, why not use 3 for read access?

6. View Files

The command to view a file is especially important when you have to check the log file after a program error. We can use commands such as cat,more,less,head,tail to view the contents of the file. Cat Prints the contents of a brain all over the screen and is not suitable for viewing multiple files. At this point, you can use more, press ENTER after viewing, continue to display the next line, less command more powerful, you can use the UP and DOWN ARROW keys to move. Head view the contents of the file header, tail View the contents of the trailer. We can use the tail-f command to constantly refresh the displayed content while looking at some of the log files that are constantly being exported.

7. View partition space usage

If there's a stupid programmer who wrote a dead loop program, then you can't avoid generating a super big log file to explode the server. So how do we see the space usage of the partition? DF (disk free) shows disk usage, for example: Df-k

After mastering the above command, we have been able to unix/linux system files a meal operation, but a powerful system far more than this command, let us in the process of actual combat, while learning with the side.

Unix/linux File System operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.