In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
As a computer user, you can't use a computer if you don't know how to operate the file system graphically. So as a programmer, if you do not know how to operate the Linux file system on the command line, you dare not say that you are a qualified programmer. Using Unix / Linux as the application server in our work is nothing more than deploying the software we have written to a remote server, without all kinds of operations on files, so it will be difficult to move if you don't know how to manipulate files. Next, let's take a look at the Unix / Linux file system.
1. Local file system
Here we will discuss the local disk-oriented file system (hard disk, CD-ROM,DVD-ROM,USB). Such file systems UFS (Unix File System), FAT (File Allocation File is usually the file system for Windows and DOS systems), NTFS (New Technology File System, usually Windows NT,2000,XP file system), UDF (Universal Disk Formt is usually DVD file system), HFS+ (Hierarchical File System hierarchical file system, such as Mac OS X), ISO9660 is usually CD-ROM file system and EXT2 extended file system (it is the default kernel file system for Linux), and so on.
Having said that, what kind of file system does CentOS 7 in the virtual machine we use? Use df-T to check.
From the Type column, we see that it uses the xfs file system, a high-performance journaling file system that was born in 1993 and was ported to the Linux system in 2000. All of the above are disk-oriented local file systems, as well as network-oriented and temporary virtual file systems. For example, tmpfs in the figure above is a temporary memory-oriented file system.
two。 Directory structure
If you want to manipulate files skillfully, you must understand the directory structure of the system. Unix / Linux uses a hierarchical file system structure, "/" is the foundation of the file system, and all other directories start here. We use the tree command to view the directory structure starting from the root directory, showing only one layer of depth. As follows:
The bin directory mainly stores binary executable files, such as the programs we used in the previous article, such as passwd,cat,vi. The boot directory holds the files used to boot the system. The dev directory stores device files. The etc directory stores system configuration files, such as user information and hosts information. Lib stores files for shared libraries. Media stores hanging media files. Mnt stores suspended mobile device files. Additional software installed by opt can be specified to be installed in this directory for ease of management. Proc contains information about the processes that the system is currently running. Root my system user home directory. No relevant information was found by run. Sbin-> usr/sbin stores the necessary procedures for system management. Srv stores files generated by users on their own initiative and provides external services. Sys stores global device files, such as bus control, etc. Tmp stores temporary files. Usr can store any file, such as an online help page used by many users. Var stores files of variable length, such as log files.
3. Commonly used commands
If you want to manipulate files, you must first learn to navigate the file system. Next, learn about a few common navigation commands!
Pwd shows the current directory, and when we execute the command, we need to make sure that the current directory is the directory we expected, so this command is often used. The following shows that we are now in the / root directory cd (Change Directory) to any directory we want to go, such as we want to go to the / etc directory: which and whereis, some of the tools we usually use, if we want to know where they are really located, we can use which. For example, if we want to know where the cd tool is located, we can do the following: the difference between which and whereis is that which searches for the content specified in the environment variable PATH, and whereis will look in the directory specified by PATH and MANPATH. Find looks for directories or files. For example, we need to find a file called test under the / root directory: file to check the type of file, for example, to see what type of file test is, and display the results as a text file ls to display the contents of the directory. If we want to view the contents of the root path, we can do the following: the -l parameter can display the corresponding details, owner and permissions of the file. 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. Type of file
As you may have noticed, there is some information on the far left of the files listed with the ls command. For example, drwxr-xr-x, the first bit represents the type of file, and the next 9 bits represent the permissions of the file. -indicates that 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 drives. D means this is a directory file. L means this is a symbolic link that can be understood as a shortcut in the Windows system. P means this is a channel for communication. S means this is a socket for communication. Since we usually use symbolic links, so let's briefly introduce symbolic links. Unix / Linux uses inode to reference files instead of file names, and inode is unique in a partition. There are two kinds of symbolic links, hard links and soft links. First let's create a file, and then create a hard link and a soft link for it, respectively.
Next, we write to the source file, hard link, and soft link respectively, and we will find that writing to any one of them will be reflected in the others.
Since the effect is the same, what is the difference between soft links and hard links? Hard links are implemented using inode, and soft links are implemented using file names. So, if we delete the file file and then create a new file file. At this time, our soft link is still valid, while the hard link is invalid. The experimental data are as follows:
5. Permissions for the file
When we use the ls-l command to view the file, the leftmost string reflects the permissions of the file, as in the following example:
As shown in the figure above, we can clearly understand where the permissions of each user for the file are viewed, then the corresponding rgraine wjournal x is read, write, and execute permissions, respectively. We can use chmod (change mode) to change the permissions of the file, and there are two choices when operating, one is to use the symbolic mode, that is, rwx, and the other is the absolute mode to use eight numbers to represent one permission. Use the chmod user (a/u/g/o) + /-permissions (rwx) file name command format to manipulate file permissions. The results of the experiment:
We can also use absolute mode to manipulate file permissions, such as chmod 777 file, which represents the maximum permissions that all users use to manipulate file files. The number of absolute mode represents the following meaning:
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. Leave a brain teaser here, why not use 3 for read permissions?
6. View Fil
It is inevitable to check the log file after the program goes wrong, and the command to view the file is particularly important at this time. We can use commands such as cat,more,less,head,tail to view the contents of the file. Cat prints all the content on the screen, which is not suitable for viewing files with a lot of content. You can use more at this time. Press the enter key after viewing and continue to display the next line. The less command is more powerful and can be moved using the up and down arrow keys. Head looks at the contents of the header of the file, and tail looks at the contents of the tail. When viewing some log files that are constantly output, we can use the tail-f command to constantly refresh the display.
7. View partition space usage
If a stupid programmer writes an endless loop, it is inevitable to generate a super-large log file to burst the server. So how do we look at the space usage of the partition? Df (disk free) shows disk usage, for example: df-k
After mastering the above commands, we can manipulate the files of the Unix / Linux system, but the powerful system is far more than this command, so let's learn while using it in the actual combat process.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.