Summary of Linux file and directory management commands

Source: Internet
Author: User

1. cd

CD ~,CD: Go back to your home folder; CD: the current layer; CD-: Go back to that directory.

2. PWD Displays the directory where you are currently

-P: The tender does not display the data of the connection file, but instead displays the correct full path

3, mkdir new directory

-P: Create a multi-level directory yourself;-M mod: Force set permissions

4, rmdir delete "empty" directory

When you want to delete something in a non-empty directory: Rm-r dirName

5. LS View files and directories

-A: All files, including hidden files;-D: Lists only the directory itself;-F: Gives additional data structures based on information such as files and directories (*: Represents the executable file,/: Represents the directory, =: Represents the socket file, |: Represents the FIFO)

-I: Lists inode numbers;-L: Lists Long data strings (commonly used);-S: Sort by file size;-T: Sort by time;--color=never/always/auto (whether the file attribute is given color),--time={atime,ctime}

6. CP [-ADFILPRSU] source file destination file

-A: Equivalent to-pdr;-d: If the source file is a property of a connection file, the connection file property is copied instead of the file itself;-I: If the target file already exists, the operation will be queried first when overwriting, and-L: Creating the connection file for hard connection, not copying the file itself;-P: Copy the past with the properties ;-R: Recursive continuous Replication (for directory)

7. RM (removing files or directories)

-I: interactive mode;-r: Recursive delete

8, MV (moving files and directories, or renaming)

-F: If the target file already exists, will not be queried and directly overwritten;-I: interactive mode;-U: If the target file already exists and is newer

9. Cat (view file contents)

-B: Lists line numbers (blank lines are not labeled);-E: Displays the line break character at the end of $;-N: Prints lines (including blank lines);-V: Lists special characters;-T: Displays "tab" as ^i

10. TAC (Reverse list)

11, NL (add line number printing)

-B: Specify the line number a: A blank line is also listed T: a blank row is not listed;-N: A way to list the representation of a line number ln: The line number appears on the far left of the screen RN: The line number is displayed on the far right of the field, without adding 0 RZ: Same rn and add 0;-w: number of digits

12, More (Page view)

In the more this program amount of running process, a few key functions:

SPACEBAR: down one page Enter: Down Line/string: query string down: F: Immediately display the file name and the number of rows currently displayed Q: Exit B: Page back (only useful for files, pipe useless)

13. Less (one page, one page turn)

SPACEBAR: down one page "PageDown": Flip a Page "PageUp": Flip a page/string: Query the string down? String: Query up string N: Copy previous query N: Reverse copy previous query Q: Exit

14, head (remove the first few lines)

-N number: followed by numbers to represent a few lines (do not write the default display of 10 lines, negative numbers indicate that the data is not printed later)

15, tail (remove the following lines)

-N Number: (followed by numbers, meaning the next few lines, do not write the default 10 lines, +number represents the previous numeric row data does not print)

16. OD (non-plain text file)

-T: can be followed by various types

c:ascii character output; d[size]: decimal; f[size]: floating point; O[size]: octal; x[size]: Hex

17. Touch modify file time or create file

-A: Only Modify access time (access times);-C: Modify only the status time (state) and not new if the file does not exist;-D: the date after which you want to modify;-M: Modify only modification time;-t: the time after which you want to modify it, Format "YYMMDDHHMM"

18. Umask: Set the default permissions for new files or directories

19, Chattr set asked the hidden properties of Kim

+: Add special parameters;-: reduce a particular parameter; =: Only the parameters that follow

A: This file can only add data, not delete and modify data (common)

I: Let a file cannot be deleted, renamed, set up a connection and cannot write or add data (common)

20. Lsattr display the hidden properties of the file

-A: The properties of the hidden file are listed as well;-D: If it is a directory, only the directory itself is listed, not the file name within the directory;-r: Data with subdirectories are listed together

21, (about Suid, SGID, sbit next in detail record)

22. File View types of files

23, which look for "Execute file" (script file name, command)

24, Whereis (file name lookup, using the database to find data, fast and efficient)

-B: Only binary files are found;-S: Only source files are found;-M: Only files found under the manual path of the description file

25, locate (file name lookup, the data found by the created/var/lib/mlocate inside the data provided)

-I: Ignore case,-R: followed by the display of the regular expression

26. Find (most commonly used)

Parameter one:

-mtime N-Nth for numbers, files changed in "One Day" before N days

-mtime +n: Meaning N days ago (excluding n days itself)

-mtime-n: Mean within n days (including n days)

The use of-atime,-ctime and-mtime as parameter two:

-uid N: Find files belonging to n this user account ID

-gid N: Find files belonging to n this user group ID

-user Name: Find files that belong to the name of this user

-group Name: Find files that belong to the name of this user group

-nouser: Does not belong to any user

-nogroup: Does not belong to any user group

Parameter three:

-name filename: Finding a file named filename

-size [+-]size: Find a file larger than size (+) or small (-), in C:byte,k:1024bytes

-type Type: Specify file type, generic file (f), directory (d), socket file (s), FIFO (p), connection file (B/C)

-perm mod: Find files with file permissions just for MoD

-perm-mod: Find ask file must contain mod all files (must contain all)

-perm +mod: Find file contains mod any permission (one can)

Parameter four:

-exec command:-exec can be followed by other commands to process the found results

A few examples of fiind:

Example one: Find/etc below, the file capacity is greater than 50KB and the file owner is not the root file name, and the permissions are fully listed

Find/etc-size +50k-uid +0-exec ls-l {} \;

Example two: Find the files under/etc with capacity greater than 1500KB and capacity equal to 0, and complete list

FINF/ETC \ (-size +1500k-o-size 0k \)-exec ls-l {} \;

Finally, add: the relationship between permissions and commands

Scenario One: Allow users to access a directory (such as a CD):

(1) Directory: Permissions of at least X

(2) File: If the user needs to consult (LS, etc.), the file requires R permission

Scenario Two: The user reads a file in a directory (cat, more, less)

(1) Directory: at least X permissions

(2) File: at least R permission

Situation three: User to fix a file

(1) Directory: at least R and X permissions

(2) File: At least R and W

Scenario Four: Let a user create a file in a directory

(1) Directory: At least W and x permissions

Scenario Five: Let the user go to the directory and execute a command in the directory

(1) Directory: at least X permissions

(2) File: At least x permission

Summary of Linux file and directory management commands

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.