[Linux operating system] File compression and file permissions, linux File compression
Book of war in Linux & 3
Only some common commands are recorded, and the comparative commands are not recorded
File compression zip and unzip
Zipcommand to process. ZIP files with unzipcommand. The former is used to compress files, and the latter is used to extract files.
Zip command usage
1. Basic usage
Zip file.zip test
Compress the file test.zip
2. After compression, delete the original file
Zip-m file.zip test
The Parameter m indicates that the compressed file test is deleted.
3. Compress subdirectories together
Zip-r file.zip *
The r parameter indicates that the subdirectories are compressed together.
Zip-j file.zip *
Parameter j indicates that the sub-directory content is ignored.
4. Specify the compression ratio to compress the file
Zip-9 file.zip *
The compression rate is 9, ranging from 1 to 9.
Generally, 5 is recommended,
5. Compress a large number of files
Zip-@ file.zip
File1.txt
File2.txt
Press Ctrl + D and enter OK. Press Ctrl + C to cancel.
6. Exclude files that do not need to be compressed.
Zip file.zip *-x file1.txt
Unzip command usage
1. Basic usage
Unzip file.zip
Extract
2. Exclude files that do not need to be decompressed
Unzip file.zip-x file1
Gzip and gunzip
These two commands can be used to compress files, but cannot compress multiple files.
1.gzip command basic usage
Gzip file.txt
Compressed file file.txt
2. view the compressed Package content
Gzip-l file.gz
3. compression rate
Gzip-9 file.txt
4.decompress the .gz File
Gunzip file.gz or gunzip-d file.gz
Tar package
Basic usage of the tar command
The file name to be packaged after the tar parameter is packaged
The tar command parameter list is as follows:
| Parameters |
Description |
| -C |
Create a new file |
| -V |
Display Command Execution Information |
| -F |
Common File Operations |
| -X |
Unbind a tar file |
| -H |
Repackaging |
| -R |
Add a new file to the packaged File |
You can add multiple parameters during use. For example, when packaging a file, you can use:
Tar-cvf y.tar x.txt # This command is used to package a file as a common file and output the package-related information.
Tar-cf y.tar x.txt # Only package files and do not output information
Introduction to file permissions and File Ownership Permissions
For each file in a Linux system, the permissions are divided into four types: r (read, read), w (write, write), x (execute, execute ), -(no permission ). Each file has three categories of users: The file owner, the file owner in the same group, and other users. Each type of user has permissions on the file.
Run the ls-l command to view the file permissions, as shown below:
-Rw-r-. 1 student 12 Aug 17 05:52 x.txt
A series of symbols starting with a directory entry describe the access permission category, with a total of 10 characters:
-The first character is the file type: d indicates the directory, B indicates the system device, and fast input/output is used to interact with the outside world, usually a disk; c indicates the system device, use Continuous character input/output to interact with the outside world, such as the serial port and sound device ;. indicates a common file with no special attributes.-indicates a file.
-2-4 characters indicates the user (owner) permission of the file
-The 5-7 characters indicate the permissions of users in the same group as the file owner.
-The 8-10 characters indicate the permissions of other users.
2, 5, and 8 indicate the r read permission;
3, 6, and 9 indicate w write permissions;
4, 7, and 10 are used to indicate x execution permissions.
In the preceding example, the file owner of x.txt has the read and write permissions. users in the same group also have the read and write permissions. Other users only have the read permission.
Run the chmod command to modify the access permissions of files/directories. 1. Modify the access permissions in digital notation.
Numeric notation means that the four permissions r, w, x, and-are sequentially represented by numbers 4, 2, 1, and 0, and then the permissions are represented by the sum of numbers.
For example, rwx indicates (421), and the sum is 7. This indicates the permissions of a class of users.-rw-r-indicates-(420) (420) (400), that is, 664, which indicates the object access permission.
To modify the File Permission, run the following command:
Chmod xxx file name
To be modified.
2. Modify the access permission in text notation
Use letters +/-/= to modify the File Permission. The command format is as follows:
Chmod [who] [+/-/=] [mode] File Name
The operation object who represents four different users:
-Utable shows "user", that is, the file is the directory owner.
-G indicates "same group users", that is, all users with the same group ID as files
-O indicates "Other (others) Users"
-A indicates "all (all) Users", which is the default value of the system.
Example:
Chmod u + r, g + w, o-r x.txt
Chmod u = rwx x.txt
Note: No space is allowed before or after the comma; otherwise, the command cannot be executed.
3. modify directory permissions
The modification of directory permissions is similar to that of files. to modify the access permissions of all files in the directory, use "*"
Chmod 774/home/student /*
If there are subdirectories in the directory, add the parameter R.
Chmod-R 774/home/student /*
Chown changes the ownership of files/Directories
Command Format: chown changed file owner or group file
For example:
Chown root x.txt