This article address:http://www.cnblogs.com/archimedes/p/linux-commands1.html, reprint please indicate source address.
ls command
LS is used to list the contents of the directory, it is one of the most commonly used commands, the LS command format is:
ls[options [directory name or file name]
Main parameters of the option:
. Options main parameter
-A,--all: Do not hide any items that begin with the "." Character.
-A,--almost-all: List except ". "and" ... " Other than the project.
--author: The author of each file is printed.
-B,--escape: represents non-printable characters in an octal overflow sequence.
--block-size= Size: The block is in the specified byte.
-B,--ignore-backups: does not list any items that end with the ~ character.
-F: Do not sort, the-au parameter takes effect, and the-lst parameter is invalidated.
-F,--classify: Adds an indicator of the file type (*/[email protected]| one of them).
-g:like-l, but does not list owner.
-G,--no-group:inhibit display of group information.
-I,--inode: Lists the inode number for each file.
-I,--ignore= style: Do not print any items that conform to the shell's universal characters.
-K:--block-size=1k.
-l: Lists information using a longer format.
-L,--dereference: Displays the object that the symbolic link indicates, rather than the information of the symbolic link itself, when the file information for the symbolic link is displayed.
-M: All items are separated by commas and fill the entire row width.
-N,--numeric-uid-gid: Similar to-L, but lists the UID and GID number.
-N,--literal: Lists the names of the unprocessed items, such as control characters that are not handled specifically.
-P,--file-type: plus an indicator of the file type (/[email protected]| one of them).
-Q,--quote-name: Enclose the project name in double quotation marks.
-R,--reverse: in reverse order.
-R,--recursive: Lists all subdirectory tiers at the same time.
-S,--size: The block size is the order.
There are several different colors when using the LS command, where Blue is the directory, green means executable, red is compressed, light blue is a linked file, bold black indicates a symbolic link, and gray is another format file:
ls most commonly used is the ls-l,:
The file type begins with a 10-character string. Where the first character represents a file type, it can be one of the following types:
-(normal file), D (directory), L (symbolic Link), B (block device file), C (character device file). The following 9 characters represent the access rights of the file, divided into 3 groups and 3 bits per group.
The first group represents the permissions of the file owner, the second group represents the permissions of the same group of users, and the third group represents the permissions of the other users.
The three characters of each group represent the read (R), write (w), and Execute permissions (x)of the file respectively. For the directory, the access permission is indicated. s indicates that the UID or GID of the file is assigned to the UID (user ID) or GID (group ID) of the executing process when the file is executed. T indicates that the flag bit is set (left in memory, not swapped out). If the file is a directory, the files in that directory can only be deleted by the superuser, the directory owner, or the file owner. If it is an executable file, the pointer to its body segment remains in memory after the file executes. This will enable the system to load the file more quickly when it is executed again. The file size, build time, file, or command name are then displayed.
PWD, cd command
The PWD is used to display the absolute path of the current working directory in the format: PWD
The CD is used to change the working directory in the format: CD
mkdir command
Used to create a new directory with the following format:
mkdir[Options] Directory name
Role: The role of the mkdir command is to establish a subdirectory named DirName, similar to the MD command under MS DOS, whose use rights are all users.
[Options] Main parameters
-M,--mode= mode: Set permissions, similar to chmod.
-P,--parents: Creates a top-level directory when needed, and is not considered an error if the directory already exists.
-V,--verbose: Displays information each time a new directory is created.
--version: Show version information and leave.
CP command
Features: Copying Files or directories
Note: The CP instruction is used to copy files or directories, such as specifying more than two files or directories at the same time, and the final destination is an existing directory, it will copy all the previously specified files or directories into this directory. If you specify multiple files or directories at the same time, and the final destination is not an existing directory, an error message appears
Parameters:
-A or--archive the effect of this parameter with the same as specifying the "-DPR" parameter
-B or--backup Delete, overwrite destination files are backed up first, backed up files or directories are also created as symbolic links and point to source files or directories linked to source files or directories. If this parameter is not added, the source file or directory will be copied directly if a symbolic link is encountered during the copy process.
-F or--force forcibly copy a file or directory, regardless of whether the destination file or directory already exists
-I or--interactive overwrite the file before asking the user
-L or--link to create a hard link to the source file instead of copying the file
-P or--preserve preserves the properties of the source file or directory, including the owner, the owning group, the permissions and the time
-P or--parents retains the path to the source file or directory, which can be an absolute or relative path, and the destination directory must already be in
-R recursive processing, the files under the specified directory and subdirectories are processed together. If the form of the source file or directory is not a directory or symbolic link, it will be treated as normal file
-R or--recursive recursive processing, the files and subdirectories under the specified directory are processed together
-S or--symbolic-link to create symbolic links to source files instead of copying files
-S < back-end string > or--suffix=< back-up string > After backing up the destination file with the "-B" parameter, a backup string is added to the end of the backup file. The default backup character string is the symbol "~"
If you or--update use this parameter, the file will only be copied when the source file has been modified (modification time) when the destination file is updated, or the destination file for the name is not present.
-V or--verbose shows the execution process
-V < backup method > or--version-control=< backup method > Specifies that when backing up files, the backup file name is named in the following 3 ways:
1.numbered or T, the backup number will be used, and the ~1~ string will be added at the end of the word, with the number incremented sequentially
2.simple or never will use a simple backup, the default back-end string is ~, can also be specified by-s
3.existing or nil will use the current mode, the program will first check if there is a backup number, if there is a backup number, if not the use of simple backup
The file system that the file or directory is copied by-X or--one-file-system must be the same as the file system where the CP instruction is executed, otherwise it will not be copied or processed in other partitions
--help Show online Help
--sparse=< Timing > Setting time to save sparse files
--version Display version
Example:
Copy files only if the source files are newer than the modified time of the destination file
Cp-u-V file1 file2
. Copy the file file1 to a file file2
CP file1 File2
The file file1 is copied into a file interactively by file2
Cp-i file1 file2
. Copy the file file1 to File2 because the destination file already exists, so specify a mode that uses forced replication
Cp-f file1 file2
. copy directory Dir1 to directory Dir2
Cp-r file1 file2
. copy files File1, file2, File3 and directory Dir1 to Dir2 at the same time
Cp-r file1 file2 file3 dir1 dir2
. preserve file properties while copying
Cp-p a.txt tmp/
. Preserve the directory structure of files while copying
Cp-p/var/tmp/a.txt./temp/
. Creating a backup file when copying
Cp-b a.txt tmp/
Backup file generated when copying, tail ~1~ format
Cp-b-V T a.txt/tmp
. Specify the backup file footer
Cp-b-S _bak a.txt/tmp
MV Command
Role:
The MV command is used to rename a file or directory , or to move a file from one directory to another , and its use rights are for all users. This command is like a combination of Ren and move in a DOS command.
Format:
Mv[options] Source file or directory, destination file or directory
[Options] Main parameters:
-I: Interactive mode operation. If the MV operation will result in overwriting an existing target file, then the system asks whether to overwrite it, asking the user to answer "y" or "n", which avoids overwriting the file by mistake.
-F: Disables interactive operation. MV operation to overwrite an existing target file without giving any indication, after specifying this parameter the I parameter will no longer work.
Application Examples:
(1) Rename the file test.c to test1.c:
$ mv test.c test1.c
(2) Move the test1.c file to the Ccode folder:
$ mv Test1./ccode
RM command
RM is a commonly used command that removes one or more files or directories from a directory, and it can delete all files and subdirectories under a directory . For linked files, only the links are deleted and the original files remain unchanged.
RM is a dangerous command, especially when used , especially for novices, or the entire system will be destroyed in this command (e.g., RM *-rf under/(root directory)). So, before we execute RM, it's a good idea to check in which directory, exactly what to delete, and keep a high level of sanity in the operation.
1. Command format:
RM [Options] File ...
2. Command function:
Delete one or more files or directories in a directory, and RM does not delete the directory if the-r option is not used. If you use RM to delete a file, you can usually still restore the file to its original state.
3. Command parameters:
-F,--force ignores nonexistent files and never gives hints.
-I,--interactive for interactive deletion
-R,-R,--recursive instructs RM to delete all directories and subdirectories listed in the parameters recursively.
-V,--verbose detailed display of the steps performed
--HELP Display this help message and exit
--version output version information and exit
Instance:
Delete the file test, the system will first ask whether to delete.
Delete all files in the projects subdirectory and subdirectories
Cat command
The purpose of the cat command is to connect files or standard input and print. This command is commonly used to display the contents of a file, or to connect several files to display, or to read from a standard input and display it, often in conjunction with redirection symbols.
1. Command format:
Cat [Options] [file] ...
2. Command function:
There are three major features of cat:
(1) Show entire file at once: Cat filename
(2) Create a file from the keyboard: cat > FileName can only create new files and cannot edit existing files.
(3) Merging several files into one file: Cat file1 file2 > file
3. Command parameters:
-A,--show-all equivalent to-vet
-B,--number-nonblank number of non-null output lines
-e equivalent to-ve
-E,--show-ends displays at the end of each line
-N,--number all line numbers for the output, numbering the number of rows for all outputs starting from 1
-S,--squeeze-blank a blank line that has more than two lines in a row and is substituted for a row
-T vs.-VT equivalence
-T,--show-tabs to display the ^i character as a
-U (ignored)
-V,--show-nonprinting uses ^ and M-references, except LFD and TAB
Common commands in Linux (1)