Linux Command operations, file copying, deletion and modification, etc.

Source: Internet
Author: User
Tags printable characters
CP Command

This command is used to copy the given file or directory to another file or directory. It is very powerful like the Copy command in msdos. Syntax: CP [Option] source file or directory target file or directory Description: This Command copies the specified source file to the target file or copies multiple source files to the target directory. The options of this command are as follows:-a this option is usually used when copying directories. It retains links and file attributes, and Recursively copies directories. Its role is equal to the combination of DPR options. -D: the link is retained during copy. -F delete an existing target file without prompting. -I and F options are opposite. A prompt is displayed asking the user to confirm before overwriting the target file. When the answer is Y, the target file will be overwritten, which is an interactive copy. -P in addition to copying the source file content, CP also copies the modification time and access permissions to the new file. -If the source file provided by R is a directory file, CP will recursively copy all subdirectories and files in the directory. The target file must be a directory name. -L do not copy, but only link files. It should be noted that, in order to prevent the user from using the CP Command inadvertently to destroy another file, such as the target file name specified by the user already exists, use the CP command to copy the file, this file will be overwritten by the new source file. Therefore, we recommend that you use the I option when using the CP command to copy the file. MV CommandYou can use the MV command to rename a file or directory or move the file from one directory to another. This command is like a combination of Ren and move in msdos. Syntax: MV [Option] source file or directory target file or directory Description: The second parameter type in the Video/video command is different (whether it is the target file or the target directory ), the MV command renames the file or moves it to a new directory. When the second parameter type is file, the MV command renames the file. At this time, only one source file (or the source directory name) can be used ), it renames the given source file or directory to the given target file name. When the second parameter is an existing directory name, there may be multiple source files or directory parameters. The MV command moves the source files specified by each parameter to the target directory. When a file is moved across file systems, the MV copies the file first, and then deletes the original file. The link to the file will also be lost. The meaning of each option in the command is-I interactive operation. If the MV operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to Answer Y or N. This will avoid overwrite the file by mistake. -F prohibit interactive operations. When an MV operation overwrites an existing target file, no instructions are given. If this option is specified, the I option will no longer work. If the target file (not a directory) already exists, the content of the file will be overwritten by the new file. To prevent the user from using the MV command to destroy another file, it is best to use the I option when using the MV command to move the file. Rm CommandYou can use the RM command to delete unnecessary files. This command is used to delete one or more files or directories in a directory. It can also delete a directory and all its files and subdirectories. For linked files, the link is closed, and the original file remains unchanged. The general format of the RM command is: Rm [Option] file... If the-r option is not used, RM will not delete the directory. The options of this command are described as follows:-F ignores non-existing files and never gives a prompt. -R indicates that Rm recursively deletes all directories and subdirectories listed in the parameter. -I. Be careful when using the RM command. Because once a file is deleted, it cannot be recovered. To prevent this situation, you can use the I option to confirm the files to be deleted one by one. If you enter y, the file will be deleted. If you enter anything else, the file will not be deleted.

 

Mkdir CommandFunction: create a directory (similar to the MD command in msdos ). Syntax: mkdir [Option] Dir-Name Description: This command creates a directory named by Dir-name. The user who creates a directory must have write permission in the current directory (the Dir-name parent directory), and The dirname cannot be an existing directory or file name in the current directory. The meaning of each option in the command is:-M sets the access permission for the new directory. You can also set it using the CHMOD command. -P can be a path name. If some directories in the path do not exist, after this option is added, the system automatically creates those directories that do not exist, that is, multiple directories can be created at a time. Rmdir CommandFunction: delete an empty directory. Syntax: rmdir [Option] Dir-Name Description: Dir-name indicates the directory name. This command deletes one or more sub-directory items from a directory. Note that a directory must be empty before it is deleted. The RM-r dir command can replace rmdir, But it is dangerous. When deleting a directory, you must also have the write permission on the parent directory. The options in the command are as follows:-P recursively deletes the directory dirname. When the sub-directory is deleted and its parent directory is empty, it is also deleted. If the entire path is deleted or some paths are retained for some reason, the system displays the corresponding information on the standard output.

Ls CommandLs is short for the English word list. Its function is to list the contents of a directory. This is one of the most commonly used commands, because you need to view the contents of a directory from time to time. This command is similar to the Dir command in DOS. Syntax: ls [Option] [directory or file] for each directory, this command will list all subdirectories and files. For each file, ls will output its file name and other required information. By default, output entries are sorted alphabetically. When the directory name or file name is not given, the current directory information is displayed. The meaning of each option in the command is as follows:-A displays all subdirectories and files in the specified directory, including hidden files. -A: displays all subdirectories and files in the specified directory, including hidden files. "." And "..." are not listed. -B indicates that non-printable characters in the file name are displayed with octal escape characters. -C is sorted by the file modification time. -C is divided into multiple columns to display items. -D if the parameter is a directory, only its name is displayed, and all files under it are not displayed. It is often used together with the L option to obtain detailed information about the directory. -F is not sorted. This option will invalidate the LTS option and make the AU option valid. -F indicates "/" after the directory name, "*" after the executable file, "@" after the symbolic link, and "|" after the pipeline (or FIFO ", mark "=" after the socket file ". -I displays the I node number of the file in the first output column. -L displays detailed information about a file in a long format. This option is the most commonly used. The information listed in each row is: file type and number of permission links the size of the file in the main file group or the last modified time name for the symbolic link file, the displayed file name is followed by "->" and the Referenced File Path Name. For device files, the "file size" field shows the master and secondary device numbers, rather than the file size. The total number of blocks in the directory is displayed at the beginning of the long format list, which contains indirect blocks. -L if the specified name is a symbolic link file, the file to which the link is directed is displayed. -M output is in bytes stream format. Files are displayed on different pages separated by commas. -N: the output format is the same as that of the L option. In the output, the file owner and group are represented by the corresponding UID and GID, rather than the actual name. -O and l options are the same, but do not display the owner information. -P adds a slash (/) to the end of the directory. -Q: Use "?" to indicate non-printable characters in the file name.. -R displays the output results in alphabetical order or the earliest priority. -R recursively displays the files in each subdirectory of the specified directory. -S indicates the number of blocks used by each directory item, including indirect blocks. -T: The display time is based on the modification time (most recent priority) rather than by name. If the file is modified at the same time, the file is in alphabetical order. The modification time depends on whether C or U is used. The default time mark is the last modification time. -U indicates the last time the file was accessed (the most recent priority) rather than by name. Change the-t time to the last access time. -X displays information about each sort item by row. In the information displayed by the LS-l command, the start is a string consisting of 10 characters. The first character indicates the file type, which can be one of the following types: -The d directory of a common file is a string of 9 characters after the C character device file of the device file of Block B. It indicates the access permission of the file, which is divided into three groups, each with three characters. The first group indicates the permissions of the file owner, the second group indicates the permissions of users in the same group, and the third group indicates the permissions of other users. The three characters in each group indicate the read, write, and execute permissions for the object. The permissions are as follows: R reads W write X and executes. For a directory, it indicates the access permission. S when the file is executed, assign the UID or GID of the file to the UID (User ID) or GID (group ID) of the execution process ). T sets the flag bit (left in memory and not swapped out ). If the file is a directory, the files in the directory can only be deleted by the Super User, directory owner, or file owner. If it is an executable file, after the file is executed, the pointer pointing to its body segment remains in the memory. In this way, the system will be able to mount the file more quickly when you execute it again. Tar CommandTar can create files and directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now, you can create files, such as floppy disks, on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission. Tar on Linux is of the GNU version. Syntax: when you use this command in a tar [primary option + secondary option] file or directory, the primary option is required. It tells tar what to do and the secondary option is used, optional. Main option: C. Create a new archive file. Select this option if you want to back up a directory or some files. R: append the file to the end of the file. For example, if you have prepared a backup file and find that there is still a directory or some files have forgotten to be backed up, you can use this option to append the directory or files you have forgotten to the backup file. T list the file content and check which files have been backed up. U updates the file. That is to say, replace the original backup file with the new file. If the file to be updated cannot be found in the backup file, append it to the end of the backup file. X release a file from the file. Auxiliary option: B. This option is set for the tape drive. It is followed by a number to describe the block size. The default value is 20 (20*512 bytes ). F. This option is usually required when you use an archive file or device. K. Save the existing files. For example, if we restore a file, the same file will not be overwritten during restoration. M sets the modification time of all files to the present when restoring files. M creates a multi-volume archive file to store it on several disks. V detailed report on the file information processed by tar. If this option is not available, tar does not report file information. W each step requires confirmation. Z uses gzip to compress/decompress the file. With this option, the file can be compressed. However, you must use this option to decompress the file during restoration. Gzip CommandThere are two obvious advantages to reduce the file size. One is to reduce the storage space, and the other is to reduce the transmission time when the file is transmitted over the network. Gzip is a frequently used command in Linux to compress and decompress files, which is convenient and easy to use. Syntax: gzip [Option] indicates the meaning of each option in the compressed (decompressed) File Name:-C writes the output to the standard output and retains the original file. -D. decompress the compressed file. -L the following fields are displayed for each compressed file: compressed file size: Uncompressed file size compression ratio: Uncompressed file name-r Recursively search for a specified directory and compress all files or decompress them. -T test to check whether the compressed file is complete. -V displays the file name and compression ratio for each compressed and decompressed file. -Num uses the specified numeric num to adjust the compression speed.-1 or -- fast indicates the fastest compression method (low compression ratio), and-9 or -- best indicates the slowest compression method (high compression ratio ). The default value is 6. Unzip CommandHow can I expand files compressed by WinZip in Microsoft Windows in Linux? You can use the unzipcommand to unexpand a compressed file named. Zip. Syntax: unzip [Option] the options of the compressed file name. Zip are described as follows:-X file list to decompress the file, but do not include the specified file. -V. -T whether the test file is damaged, but the pressure is not solved. -D directory: Decompress the compressed file to the specified directory. -Z only displays the annotation of the compressed file. -N does not overwrite existing files. -O overwrites existing files and does not require user confirmation. -J. Do not recreate the directory structure of the document and decompress all the files to the same directory. DF CommandFunction: Checks disk space usage of the file system. You can use this command to obtain the space occupied by the hard disk and the remaining space. Syntax: DF [Option] Description: The DF command displays the I node and disk block usage of all file systems. The meaning of each option of this command is as follows:-A displays the disk usage of all file systems, including 0 block file systems, such as/proc file systems. -K is displayed in K bytes. -I: displays the I node information instead of the disk block. -T: displays the disk space usage of each specified type of file system. -X lists the disk space usage of a file system of a specified type (opposite to the T option ). -T displays the file system type. Du CommandThe original English meaning of DU is "disk usage", which means to display the usage of disk space. Function: calculates the disk space occupied by directories (or files. Syntax: Du [Option] [names…] Note: This command step by step enters each sub-directory of the specified directory and displays the directory's usage of File System data blocks (1024 bytes. If no names is provided, the current directory is counted. The meaning of each option of this command is as follows:-s only gives the total number of occupied data blocks for each names parameter. -A Recursively displays the number of data blocks occupied by each file in the specified directory and its descendants. If neither-s nor-A is specified, only the disk blocks occupied by each directory and Its subdirectories in names are displayed. -B lists disk space usage in bytes (the system defaults to K bytes ). -K lists the disk space usage in 1024 bytes. -C is followed by a total (system default setting ). -L calculate the size of all files, and calculate hard-linked files multiple times. -X skipping directories on different file systems is not counted. Dd command: copy the specified input file to the specified output file, and convert the format during the copy process. You can use this command to implement the diskcopy command in DOS. Use the DD command to write the data on the floppy disk as a storage file on the hard disk, and then write the storage file to the second disk to complete the diskcopy function. Note that you should delete the storage file on the hard disk with the RM command. Standard input files and standard output files are used by default. Syntax: dd [Option] If = input file (or device name ). Of = output file (or device name ). IBS = Bytes: the number of bytes read from the buffer zone. Skip = blocks skip the IBS * blocks block at the beginning of the read buffer. Obs = Bytes: the number of bytes written to the buffer zone. BS = Bytes: set the number of bytes in the read/write buffer at the same time (equal to setting IBS and OBS ). CBS = byte: bytes are converted once. Count = blocks only copies the input blocks block. Conv = ASCII converts the ebcdic code to the ascil code. Conv = ebcdic converts an ascil code to an ebcdic code. Conv = IBM converts an ascil code to an alternate ebcdic code. Conv = block converts a variable bit to a fixed character. Conv = ublock converts a fixed bit to a variable bit. Conv = ucase converts lowercase letters to uppercase letters. Conv = lcase converts uppercase letters to lowercase letters. Conv = notrunc: the output file is not truncated. Conv = swab exchange each pair of input bytes. Conv = do not stop processing when noerror occurs. Conv = Sync adjusts the size of each input record to the IBS size (filled with NUL ). Fdformat CommandFloppy disk is a common storage medium. A floppy disk must be formatted before it can be used. Then, you can use commands such as tar, DD, and cpio to store data, or you can create an installable file system on a floppy disk. Function: low-level formatting of a floppy disk Syntax: Format [-N] device Description: This command is used to format a floppy disk. -N the disk is not verified after being formatted. Device specifies the device to be formatted. It is usually one of the following devices: /dev/fd0d360/dev/fd0h1200/dev/fd0d360/dev/fd0h360/dev/fd0d720/dev/fd0h320/dev/fd0h360/dev/fd0d320/dev/fd0h1440 command name:

Permission: All Users

Usage: chmod [-CFVR] [-- help] [-- version] mode file...

Note: file access permissions for Linux/Unix are classified into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Parameter format:

Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxx]...] [,...], where

U indicates the owner of the file, G indicates that the owner of the file belongs to the same group, O indicates that the owner of the file belongs to other people, and a indicates that all three are.

+ Adds a permission,-Indicates canceling the permission, and = indicates a unique permission.

R indicates that the file can be read, W indicates that the file can be written, and X indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable. -C: if the permission of the file has been changed, the change action is displayed.

-F: Do not display an error message if the file permission cannot be changed.

-V: displays details of permission changes.

-R: Change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)

-- Help: displays auxiliary instructions

-- Version: displays the version.

Example: Set the file file1.txt to readable by all users:

Chmod Ugo + R file1.txt

Set file1.txt to readable:

Chmod A + R file1.txt

Set file1.txt and file2.txt as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:

Chmod ug + W, o-w file1.txt file2.txt

Set ex1.py to only the owner of the file to execute:

Chmod U + x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:

Chmod-r a + R *

In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.

Syntax: chmod ABC File

Each A, B, and C is a number, indicating the permissions of the user, group, and other respectively.

R = 4, W = 2, x = 1

If you want the rwx attribute, 4 + 2 + 1 = 7;

If the RW-attribute is required, 4 + 2 = 6;

If you want the R-x attribute, 4 + 1 = 7.

Example:

Chmod A = rwx File

And

Chmod 777 File

Same effect

Chmod ug = rwx, O = X file

And

Chmod 771 File

Same effect

If you use chmod 4755 filename, you can grant root permissions to this program.

 
Related Article

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.