Common Linux commands (2)

Source: Internet
Author: User
Ii. File directory commands

CD [path] can be a relative or absolute path to change the working directory.
This command changes the current directory to the specified directory. If no path is specified, return to the user's main directory. To change to the specified directory, you must have the execution and read permissions on the specified directory.
You can use "CD-" to return to the previous working directory.
"./" Indicates the current directory, and "../" indicates the upper-level directory.
CD/: Return to the top-level directory
CD: Return to the current user's home directory
Ls [Options] [file]
Lists the contents of a directory. "file" indicates the file to be viewed. By default, all files in the current directory are viewed.
Common parameters:
-L only one file or directory name is displayed in one row
-A: displays all files and directories.
-A: displays all directories except the row directory and the upper directory.
-C: The time sorting has been changed to display files and directories.
-H: Use "k", "M", and "G" to display the file and directory size
-I: displays inode numbers of files and directories.
-D. List directories like other files, instead of file content.
-F unordered directories are listed in the order they are on the disk.
-R recursively lists all subdirectories in the directory.
-X is sorted by file extension to help you identify files of the same class.
Use-L to list the file display formats:
File type and number of permission connections file owner file group file size modification time file name
File [Options] File Name
Used to determine the specific type of a file
-Z: If a file is compressed, an attempt is made to obtain the type of the original file (not compressed ).
Mkdir [Options] path
Create a directory
Common Parameters
-M: Set the read and write permissions for the new directory, or use the CHMOD command to set
-P: if the upper-level directory of the Created directory is not created, the upper-level directory is automatically created.
Cat [Options] file1 file2
Connect to and display information about one or more specified files
Common Parameters
-N number of The number of rows output from the first line
-B is similar to-N, but the blank row is not numbered.
-E is displayed at the end of each row $
At the same time, this command can display the content of multiple files in turn
Head/tail [Options] File Name
10 lines at the beginning/end of the file are displayed by default.
-CN: displays the content of the first or last n Bytes.
-NN: displays the content of the first and last n rows.
CP, MV, RM
(1) Role
① CP: copy the given file or directory to another file or directory (if the target file is an existing file or directory, it will automatically overwrite the original file ).
② MV: Rename the file or directory or move the file from one directory to another.
③ RM: delete one or more files or directories in a directory.
(2) Format
① CP: CP [Options] source file or directory target file or directory
② MV: MV [Options] source file or directory target file or directory
③ RM: Rm [Options] file or directory
(3) Common Parameters
① Main option parameters of CP
-A retains the link and file attributes, and copies its sub-directories. The effect is equal to the combination of the DPR option.
-D copy is a reserved Link
-F delete an existing file without prompting
-I Prompt before overwriting the target file to ask the user to confirm. When answering y, the target file will be overwritten and the interaction will be copied.
-P in addition to copying the original file, CP also copies the modification time and file permissions to the new file.
-R if the source file is a directory name, CP will recursively copy all subdirectories and files in this directory. At this time, the target file must be a path name.
② Main options and parameters of MV
-I 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
-F prohibit interactive operations. No prompt is given when the MV operation will overwrite existing files. After the specified option, I will not work.
③ Rm main option Parameters
-I interactive Deletion
-F ignore non-existing files, but no prompt is given
-R indicates that Rm recursively deletes all directory words listed in the Parameter
SCP
Copy files between the host and Remote Server
Rename
Role: rename a file
Format: Rename from To File
The command has three parameters:
From: Source character
To: Target character
File: the file to be modified.
Example:
// Change the suffix of all files from RM to rmvb
Rename. rm. rmvb *
// Replace uppercase letters in all file names with lowercase letters.
Rename 'tr/A-Z/a-Z '*
// Rename Taq (old).tar.gz to Taq (new).tar.gz
Rename' (old) ''(new) ''' Taq (old).tar.gz'
The renamed function is also used for the MV command:
Format: MV oldfile newfile
However, the difference with rename is that rename can change multiple files at the same time, while MV can only change one file at a time.
Rmdir
Delete directories. If a directory and subdirectory are empty, you can use the-P option to delete these directories, but it only limits the directory to be empty.
You can use Rm-RF to delete the entire directory.
Chown and chgrp (with root permission)
① Chown: Change the file owner and group
Chown [Option] file owner [owner group name] file, where the file owner is the modified file owner
② Chgrp: Change the group ownership of the file
All group files of the chgrp [Option] file, where all the groups of files are the owner of the changed File
(2) Common Parameters
Common chown and chgrp parameters have the same meaning as follows:
-C,-changes detailed descriptions of the ownership that each file actually changes
-F: no error message is displayed.
Chown gbyukg Taq: Change the owner of the Taq folder to a gbyukg user
Chmod changes File Access Permissions
(1) format:
① Symbol mark:
The symbol mark can be specified as multiple. That is to say, multiple user-level permissions can be specified, but they must be separated by commas (,). If they are not displayed, they are not changed.
Chmod [-CFVR] [-- help] [-- version] mode file...
Mode: permission setting character in the following format: [ugoa] [[+-=] [rwxx] [,...]
U => User, G => group, O => Other, A => All indicates all three
+ Indicates adding permissions.-Indicates canceling permissions, and = indicates unique permission settings.
Chmod Ugo + R file1.txt
Chmod A + R file1.txt
② Octal values:
Chmod ABC File
Each ABC is a number indicating the permissions of the user, group, and other.
R = 4, W = 2, x = 1
If you want the rwx attribute, 4 + 2 + 1 = 7
If you want the R-x attribute, 4 + 1 = 5
Chmod 777 file works the same way as chmod A = WRX
(2) Option parameters:
-C. If the file has been changed, the change action is displayed.
-F if the file has no permission to be changed, no error message is displayed.
-V: displays detailed information about permission change.
-R: Change the permissions of all files and subdirectories in the current directory.
Sort displays content in sequence
Sort [Options] File Name 1 file name 2
The sort tool sorts the file content and displays it, but does not change the original file. If multiple file names exist, these files are merged and displayed together.
Grep searches for specific content in the specified file and outputs the row standard output containing the content.
Grep [Options] content to be searched [file and path]
The default "file and path" indicates searching in the current directory. By default, 'grep' only searches for the current directory. If multiple subdirectories exist in this directory, you can use-R to explicitly search for subdirectories. For example, grep Hello Taq-R will search all the files in the Taq directory, including subdirectories. you can also use-D skip to ignore the query of sub-directories, for example, grep Hello Taq-D Skip.
Common grep Parameters
-Num: displays the num row matching the context at the same time (Num is an integer)
-C: only counts matching rows.
-I is case insensitive.
-H: the file name is not displayed when you query the file.
-L only show names when querying files, but not matching rows
-N: display matching rows and row numbers
-S does not display error messages that do not exist or do not match the text
-V: displays all rows that do not include matched rows.
Note that you must provide a file filtering method (* for searching all files *). If you forget, 'grep' will wait until Program Interrupted. If this happens, press <Ctrl C> and try again.
Grep hello-R *
If you expect a lot of output, you can use the pipeline to switch it to 'less' for reading.
Grep Hello Taq-r | less
Grep search supports regular expressions.
Find [path] [Option] [description]
Search for a file in a specified directory. the permission is granted to all users.
The path is the search path of the file. The system starts to search for the file along the directory tree. It is a list of paths separated by spaces. If the default path is used, the current path is used by default.
Enter find directly:
.
./Yun
./Yun/Hello. php
The description is a matching expression, which is an expression accepted by the find command, as follows:
-Name filename # search for a file named filename
-Perm # search by execution permission
-User Username # search by file owner
-Group groupname # search by group
-Mtime-N + N # Find the file based on the file change time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Atime-N + N # query gin by file access time: 0px ">
-Ctime-N + N # Find the file based on the file creation time.-N indicates that the file is less than N days, and + N indicates that the file is earlier than N days.
-Print # output the search result and print it
The find command can use a hybrid search method to connect descriptions with-and, for example, find-size + 500c-and-mtime + 1 to find files larger than 500 bytes and modified within one day.
Locate
Ln [Options] Directory for creating a link to the target file
Creates a symbolic link for a file in another location. When the same file needs to be used in different directories, Linux allows users not to create the same file in each required directory, instead, you only need to link files in other directories with the ln command, so that you do not have to occupy disk space again.
Common parameters:
-S: Creates a soft link. If this parameter is not set, the connection is hard.
The ln command will keep the synchronization of each link file. That is to say, no matter which one is changed, other files will change the same.

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.