"Linux operating System" file compression and file permissions

Source: Internet
Author: User
Tags gz file

"Linux Bingshu" Reading notes &3

Only a few common commands are recorded, and the command that is biased is not recorded.

Zip and Unzip file compression

The zip command and the unzip command process the. zip file, which is used to compress the file, which is used to unzip the file

Zip command usage

1. Basic Usage
Zip File.zip Test
Compress the file test to File.zip
2. After compressing, delete the original file
Zip-m File.zip Test
The parameter m indicates that the compressed file is deleted after the test
3. Compress sub-directories together
Zip-r File.zip *
Parameter r indicates that the sub-directories are compressed together
Zip-j File.zip *
Parameter J indicates that the contents of the subdirectory are ignored
4. Specify compression rate compression file
Zip-9 File.zip *
Specify a compression rate of 9 with a range of 1-9
The general recommendation is to take 5,
5. Compress a large number of files
Zip [email protected] File.zip
File1.txt
File2.txt
Press Ctrl+d to enter confirm, CTRL + C 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
Unzip
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
Compressing files file.txt
2. View the contents of a compressed package
Gzip-l file.gz
3. Compression Ratio
gzip-9 file.txt
4. Unzip the. gz file
Gunzip file.gz or gunzip-d file.gz

File Packager tar

basic usage of the TAR command
File to be packaged after the TAR parameter is packaged
The list of tar command parameters is as follows:

Parameters Description
-C Create a new file
-V Show command execution information
-F Refers to normal file operations
-X Unpack the tar file
-H Re-packaging
-R Add a new file to the packaged file

When you use it, you can add multiple parameters, such as when you package a file, using:
TAR-CVF Y.tar x.txt #此命令表示以普通文件的方式打包文件并且输出打包的相关信息
TAR-CF Y.tar x.txt #只打包文件, no output information

Introduction to file permissions and file ownership file permissions

For each Linux system file, it has four kinds of permissions: R (read, reading), W (write, write), X (Execute, execute),-(no permission). There are three different types of users in each file: The file owner, the owner of the file, the same group of users, and the other 3 classes, each of which has permissions on the file.

Use the command ls-l to see the file's permissions, as follows:
-rw-rw-r–. 1 Student Student 12 June 05:52 X.txt

A sequence of symbols that begin with a directory entry describes the access category, a total of 10 characters:
-The first character is the type of file: D indicates the directory, B represents the system device, uses fast input/output to interact with the outside world, usually disk, C represents the system device, uses continuous character input/output to interact with the outside world, such as serial port and sound device; Indicates normal file, no special attribute;-Indicates file
-The 第2-4个 character represents the user (owner) permission for the file
-The 第5-7个 character represents the permissions of the same group of users as the owner of the file
-第8-10个 characters represent permissions for other users

2, 5, 8 is used to indicate R Read permission;
3, 6, 9 to indicate W Write permission;
4, 7, 10 are used to represent X execution permissions.

In the example above, the file owner of X.txt has both read and write permissions, and the same group of users have read and write permissions, while other users have only read this permission.

chmod command to modify access permissions for a file/directory 1. Modifying access rights in digital notation

The number notation means that four kinds of permissions R, W, X,-in turn, are represented by the numbers 4, 2, 1, 0, and then the numbers are added to represent the permissions.
For example: rwx (421), add is 7, this can represent a class of user permissions,-rw-rw-r–, can be expressed as-(420) (420) (400), that is, 664, which can represent the access rights of the file.

When modifying file permissions, use the command:
chmod XXX file name
You can implement the modifications.

2. Modifying access rights in text notation

The text notation uses the letter +/-/= permission to modify the file permissions, the command format is as follows:
chmod [Who][+/-/=][mode] File name
Action object who represents four different types of users:
-U means "user", that is, the owner of the file is the directory
-G means "group user", that is, all users with the same group ID as the main file
-O means "other (others) users"
-a means "all users", which is the system default value

Example:
chmod u+r,g+w,o-r X.txt
chmod u=rwx X.txt

Note: There can be no spaces before and after commas, otherwise the command cannot be executed

3. Modification of directory Permissions

Directory permissions are modified similar to files, if you want to modify access to all files in the directory, you should use "*"
chmod 774/home/student/*
If there are subdirectories in the directory, you should add the parameter R
Chmod-r 774/home/student/*

Chown Changing the ownership of files/directories

Command format: Chown file owner or group file after change
Such as:
Chown Root X.txt

"Linux operating System" file compression and file permissions

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.