The third of Linux learning--operation files and directories

Source: Internet
Author: User

I. Directory documentation Operations directives

1. PWD Displays the directory where you are currently

If you add the-P option, the correct directory name is obtained instead of being displayed as the path to the linked file. For example, under CentOS, just good/var/mail is/var/spool/mail's link file.

2. CD Change work path

You can use absolute and relative paths.

In addition, there are several special ways to represent the path:

1). Represents this Layer directory

2).. Represents a previous level directory

3)-Represents a previous working directory

4) ~ represents "Current user identity" in the home directory

5) ~account represents the user's home directory (account is a name)

3. LS lists directories and files under the directory

Options and Parameters:

-A: All files, including hidden files, are listed together

-A: All files, including hidden files, but not included. And.. These two directories

-D: List only directories

-F: Lists the results directly without sorting (the default is sort by file name!) )

-F: According to files, directories and other information, to give additional data structure, such as: *: On behalf of the executable file;/: representative 弽; =: represents the socket file; |: Represents the FIFO file;

-H: Lists the file capacity in a human-readable manner (e.g. GB, KB, etc.);

-I: List inode numbers;

-L: List output

-N: Lists UID and GID instead of user and group names

-r: Reverse output of the sorting results, for example: the original file name from small to large, the reverse is from large to small;

-R: Listed along with subdirectory contents;

-S: sorted by file size;

-T: Sort by time.

--color=never: Do not give color display according to the file characteristics;

--color=always: Display Color

--color=auto: Let the system decide whether to give the color according to the setting

--full-time: Output in full time mode (including year, month, day, hour, minute)

--time={atime,ctime}: Output access time or Change permission attribute time, not content change time.

4. mkdir Create a new directory

Options and Parameters:

-M: Configure folder permissions, which are made up of three digits from 0 to 7.

-P: Create a multi-level directory directly, such as: Mkdir-p TEST1/TEST2/TEST3

5. RmDir Delete Empty directory

Options and Parameters:

-P: Directly delete multi-layer empty directory, such as: Rmdir-p TEST1/TEST2/TEST3

6. CP Copy files or directories

Usage

1) CP option source file destination file

2) CP option Source1 source2 source3 .... directory

Options and Parameters:

-A: equivalent to the meaning of-pdr;

-D: If the source file is a linked file, the linked file is copied instead of the file itself, and the link to the source file is copied when the linked file is copied by default;

-F: For forced replication, if the target file already exists cannot be copied, then try again after removing;

-I: If the target file already exists, it will ask for the action in the overwrite, CentOS7 default query

-L: The link file for the hard link is established, not the copy file itself;

-P: Copy the past together with the attributes of the archive, rather than using the default properties (backup is often used);

-R: Recursive replication for directory replication;

-S: Copy as Symbolic link file (symbolic link shortcut);

-U: Update destination If destination is older than source.

7. RM (removing files or directories)

You can delete a non-empty directory, and you can use wildcards when deleting, such as b* all files that begin with B.

Delete-the beginning of the file, because-will be misunderstood as an option, such as RM-AAA,

Can be changed to RM./-AAA, or RM---AAA

Options and Parameters:

-F: The meaning of force, ignoring the non-existent file, no warning message will appear;

-I: Interactive mode that asks the user if the action is active before deleting it.

-R: Recursive delete

8. MV (move files and directories, or rename)

Usage

1) MV Option source destination

2) MV option Source1 source2 source3 .... directory

-f:force mandatory Meaning, if the target file already exists, will not ask and directly covered;

-I: Interactive mode, asking whether to overwrite

-U: If the target file already exists and the source is newer, it will be updated (update)

9. basename gets the path filename

DirName get the directory name of the path

Cat starts with the first line showing the contents of the archive

Options and Parameters:

-A: Equivalent to-vet's integration options, which can list some special characters rather than blanks;

-B: List line numbers, blank lines do not mark line numbers!

-N: List line numbers, along with line numbers for blank lines

-E: Displays the end of the break character $;

-T: the [tab] key is displayed in ^i;

-V: Lists some special characters that can't be seen


The TAC starts from the last line and displays backwards.


When the NL is displayed, the output line number

Options and Parameters:

-B: Specifies the way the line number is specified, mainly in two ways:
-B A: Indicates that blank lines also list line numbers (similar to cat-n);

-B T: Indicates that a blank line does not list line numbers (default);

-N: Lists the representation of line numbers in three main ways:

-N LN: The line number is displayed at the left of the screen;

-N RN: The line number is displayed on the very right of its own field and does not add 0;

-N RZ: The line number is displayed on the very right of the field, plus 0;

-W: The number of digits that the line number field occupies.


More used to browse large files, one page to display the contents of the file

You can use the following keys to interact when you start browsing with this command:

1) SPACEBAR (space): Represents a page down;
2) Enter: Represents a downward row;
3)/String: representative down Search "string" This keyword, CentOS7 not good
4): F: Immediately display the file name and the number of lines currently displayed;
5) Q: The representative immediately leaves more, no longer show the contents of the file.
6) b or [ctrl]-b: The representative pages back, but only useful for the file, the pipeline useless.


Less is similar to more, but more powerful and usable!

You can use the following keys to interact when you start browsing with this command:

1) SPACEBAR: Turn down one page;
2) [PageDown]: Turn down one page;
3) [PageUp]: Turn up one page;
4)/string: Search down the function of "string";
5) String: Search up the function of "string";
6) N: Repeat the previous search (with/or?) )
7) N: Reverse Repeats the previous search (with/or?)! )
8) Q: Leave less this program;


The head is only a few lines.

Options and Parameters:

-N: followed by a number that represents the meaning of a few lines


Tail only looks at the tail for a few lines.

Options and Parameters:

-N: followed by numbers, representing a few lines of loyalty

-F: Indicates continuous detection of the file, which is displayed to the screen immediately when the file has data written, until [ctrl]-c ends tail detection

OD reads the contents of the file in binary mode!

Options and Parameters:

-T: The output of various types (type) can be followed, for example:

A: Use the default character output;

C: Use ASCII character output

D[size]: Use decimal to output data, each integer occupies size bytes;

F[size]: Using floating point (floating) output data, each number occupies size bytes;

O[size]: Using octal (octal) output data, each integer occupies size bytes;

X[size]: Use hexadecimal (hexadecimal) output data, each integer occupies size bytes;

Touch Modify File Time

Options and Parameters:

-A: Revise access time only;

-C: Only modify the time of the file, if the file does not exist, do not create a new file;

-D: Can be followed by the date of the revision instead of the current date, or you can use the--date= "date or time"

-M: Modify Mtime only;

-T: The time after which the revision can be taken without the current time, in the format [YYMMDDHHMM]

Ii. Search for directories and documents

1. Which look for the command file location, just find the location defined by the path parameter.

which [-A] command

Options or parameters:

-A: Lists all instructions, by default only the location of the first found command is listed.

2. Whereis for Program name search, and only binary file (parameter-B), man description file (parameter-m) and source code file (parameter-s), using the database search

Whereis [-BMSU] file or directory name

Options and Parameters:

-B: Only binary format files are found

-M: Find only files under the manual path of the description file

-S: Find source files only

3. Locate according to the file part name (path part contains also count) to search, use database search, generally may update the database once a day, if can't wait to be able to update the database directly with UpdateDB.

Locate [-ir] keyword

Options and Parameters:

-I: Ignoring the difference in case;

-R: Can be followed by the normal representation of the display mode

4. Find files in the file system

Find [PATH] [option] [action]

Options and Parameters:

1) Time-related options: Total-atime,-ctime and-mtime, to-mtime description

-mtime N: In the first n days (only n itself) is more over the contents of the archives;

-mtime +n: Lists the file names of the content that were changed N days ago (excluding the N-day itself);

-mtime-n: Lists the file names of the content that have been changed within n days (including the N-day itself).

-newer File:file for an existing file, listing a new file name than file

2) Parameters related to the user or group name:

-uid N # is a number, and this number is the UID of the user

-gid N # is a number, and this number is the GID of the group name

-user name:name as user account name

-group Name:name for Group name

-nouser: Find the owner of the file does not exist in the/etc/passwd!

-nogroup: The owning group looking for the file does not exist in the/etc/group file!
Files that do not have a file owner may exist when you install the software yourself.

3) Parameters related to file permissions and names:

-name FileName: Searches for files named filename;

-size [+-]size: Search for files larger than size (+) or small (-). This size has: C: Represents Byte, K: Represents 1024bytes.

-type type: The types of search files, type, the main types are: general regular file (f), device files (b, c), directory (d), link file (l), socket (s), and FIFO (p) and other properties.

-perm Mode: Search file permission "just equals" mode file, this mode is a property value similar to chmod

-perm-mode: Search file Permissions "must all include Mode's permission" of the file, for example, we want to search-rwxr--r--, that is, 0744 of the file, using-perm-0744, when a file has the right to-rwsr-xr-x, that is, 4755, also will be listed because the properties of the-rwsr-xr-x already include the properties of the-rwxr--r--.

-perm +mode: The file that searches for file permissions "contains any mode permission",

4) Additional actions to be performed:

-exec Command:command is used for other instructions to process the results of the search.

-print: Print the results to the screen, this action is a preset action!

The third of Linux learning--operation files and directories

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.