Linux Department of Science notes

Source: Internet
Author: User
Tags parent directory

1 pwd Print the current directory location

2 mkdir Creating a directory

-p recursion to create a parent directory that does not exist

-M setting property permissions for a directory

Mkdir-m 777 Testa # Create a testa directory with 777 permissions

3 rmdir Delete Empty directory

-p recursively Delete upper empty directory

Rmdir-p/testa/testb #同时删除 Testa testb an empty directory

4 $PATH executable file path variables, separated by colons for each directory

Echo $PATH #输出变量

5 ls display file or directory information

[Email protected] ~]#ls[-Aadffhilnrrst] FileName or directory name: [[Email protected]~]#ls[--color={never,auto,always}] file name or directory name: [[Email protected]~]#ls[--full- Time] FileName or directory name: Options and Parameters:- A: All files are listed together with hidden files (files that begin with.) (common)-A: All files, together with hidden files, but not included. The two directories- D: Lists only the directory itself, not the file data in the directory (common)-F: Lists the results directly without sorting (lsThe default is to sort by file name! )-F: Based on information such as file, directory, etc., give additional data structure, for example:*: represents executable file;/: representative Directory; =: represents socket file;124;: represents FIFO file;- H: List the file size in a human-readable manner (e.g. GB, KB, etc.) ;-I: List the inode number, the meaning of the Inode the next chapter will be introduced;-L: Long data serial out, including the file attributes and permissions and so on data; (common)-N: List uid with GID instead of user and group name (UID and GID will be mentioned in account management!) )-r: Reverse the output of the sorting results, for example: the original file name from small to large, the reverse is from large to small;-R: Together with the subdirectory contents, all the files in the directory will be displayed;-S: Sort by file size, not by filename;- T: Sort by time, not by file name . --color=never: Do not give color display according to the file characteristics;--color=Always : Display color--color=Auto: Let the system determine whether to give the color according to the settings--full- Time: Output in full time mode (including year, month, day, hour, minute)-- Time={atime,ctime}: Output access time or Change permission attribute time (CTime) instead of content change time (modification Time)

6 CP Copy files or directories, create links

[Email protected] ~]#CP[-Adfilprsu] Source file (source) destination file (destination) [[email protected]~]#CP[Options] source1 source2 source3 .... Directory options and Parameters:-A: equivalent to-DR--preserve=All means, as for Dr Please refer to the following instructions; (Common) Note: When copying, keep the original file by property as much as possible-D: If the source file is a property of the linked file (linkfile), the linked file attributes are copied rather than the file itself;-F: For force, if the target file already exists and cannot be opened, remove it and try again; Note: Delete the file if it exists-I : if the target file (destination) already exists, the action will be asked (commonly used) when overwriting: It is best to place the-i option in an alias-L: Create a link file for hard link, not copy the file itself;-P: Copy the past with the attributes (permissions, users, time) of the file, instead of using the default properties (backup is often used);-R: Recursive continuous replication for the replication behavior of the directory; (Common)-s: Copy becomes a symbolic link file (symbolic link), that is, "shortcut" file;-U:destination is copied only if the destination is newer than the source, or if the destination does not exist. --preserve=all: Except-P's permission-related parameters, also added SELinux attributes, links, xattr, etc. also copied. Finally, if the source file has more than two, then the last destination file must be "directory"! 

7 RM Delete file or directory, add-r option when deleting directory

RM [-fir] file or directory options and Parameters:-F: is the meaning of force, ignoring the non-existent file, no warning message;-I: interactive mode, before the deletion will ask the user whether the action -r: hand-back Delete Ah! Most commonly used in directories are deleted! This is a very dangerous option!!!

8 MV

MV [-mv  [options] source1 source2 source3 .... Directory options and Parameters:-f:force mandatory Meaning, If the target file already exists, does not ask to be overwritten directly;-I: If the target file (destination) already exists, you will be asked to overwrite it! -U: If the target file already exists and source is newer, update (update)

9 File Content Lookup instructions

Cat Show file contents starting from first line TAC TAC Cat Write Backwards!  nl  display, the output line number!   More page-by-page display file content  less much more better yet, he can flip ahead!  head  only a few lines tail  only look at the tail a few lines od to read the contents of the file in binary way! 

Cat (CONCATENATE) displays the contents of the file starting from the first line

Cat [-Abentv] options and Parameters:-A: Equivalent-VET of the integration options, can list some special characters instead of blank;-B: List line numbers, only do line numbers for non-blank lines, blank lines are not marked with line numbers! -E: Displays the end of the line break character $,-N: Prints the travel number, along with a blank line, with a row number,different from the option of-B;-T: Displays the [tab] key as ^I;-V: Lists some Characters

TAC (Reverse list)

Starting from the last line, you can see that the TAC is cat 's backwards Write! 

NL (Add line number to print) when displayed, by the output line number!
NL [-BNW] file options and Parameters:-B: Specify the way the line number is specified, there are two main types:cat -N);-B T: If there is a blank line, do not list the line number (default) for the empty row; -N: List the method of line number representation, there are three main kinds:ln  : The line number is displayed on the left of the screen;0  ;0  ; -W : Number of characters occupied by the line number field
 
More (one page turn) one page of the display file content
blank Key (space): Represents a page Down; Enter: Represents a downward turn "line";/  More, the contents of the file are no longer displayed. b or [Ctrl]-B: Represents a page back, but this action is only useful for files and useless for pipelines.

Less (one page, one page) smaller is similar to more, but better than more, he can page forward!

blank key: Flip one page Down; [PageDown]: Turn one page down; [PageUp]: Flip one page up;/ string: Search for "string" function;  /or?  /or?   Less this procedure;

Head (remove the previous lines)

Head [-N number] file options and Parameters:-N: followed by numbers, indicating the meaning of a few lines

Tail (take back a few lines)

Tail [-N number] file options and Parameters:-N: followed by numbers, representing the meaning of a few lines of F: Indicates continuous detection of the following file name, to wait until the [ctrl]-c will end tail detection





[[email protected] ~]# tail-f/var/log/messages <== to wait until the input [crtl]-c will not leave tail this command detection!

OD reads non-plain text files

[[email protected] ~]# od [-t TYPE] File option or parameter:-T: The following can be followed by various "type" output, for example: A: Using the default characters to output; C: Use ASCII characters to output d[siz E]: Use decimalto output data, each integer occupies size Bytes; F[size]: Use floating-point value (floating) to output data, each number occupies size Bytes; O[size] : Use octal (octal) to output data, each integer occupies size Bytes; X[size]: Uses hexadecimal (hexadecimal) to output data, each integer occupies size Bytes;
Example one: please/usr/bin/passwd's content is displayed using ASCII! [[Email protected]~]# od-t c/usr/bin/passwd0000000 177E L F002 001 001\0\0\0\0\0\0\0\0\00000020 003\0&gt; \0 001\0\0\0 364 3\0\0\0\0\0\00000040@ \0\0\0\0\0\0\0X e \0\0\0\0\0\00000060\0\0\0\0@ \0 8\0\ t \0@ \0 035\0 034\00000100 006\0\0\0 005\0\0\0@ \0\0\0\0\0\0\0..... (omitted later) .... # The leftmost first column is8Carry to represent the number of bytes. For the above example, the second column 0000020 represents the beginning of # -the content of a byes (2x8). Example two: please/etc/issue the contents of this file are listed in 8 in the table of stored values and ASCII [[email protected]~]# od-t occ/etc/Issue0000000 134 123 012 113 145 162 156 145 154 040 134 162 040 157 156 040\ S \ n K e r n E l \ r o n0000020 141 156 040 134 155 012 012a n \ m \ n \ n0000027# as shown above, you can find out what values each character can correspond to! It is important to note that the value is8Carry the Carry Oh! # For example, S corresponds to a record value of123, turn into decimal: 1x8^2+2x8+3= the。

Touch to modify the file time or create a new file, Touch This command is most often used: Create an empty file; Revise a file date to current (Mtime and Atime)

Touch [-ACDMT] file options and Parameters:  Time access Time (atime): When the contents of this file are fetched, this reads (access) is updated. For example, if we use cat to read/etc/man_db.conf, we will update the file's atime. -C: Only the time to modify the file, if the file does not exist, do not create a new file, status time (CTime): When the file's "status" changes, it will update the time, for example, such as permissions and properties have been changed, will update this time AH. -D: You can follow the date you want to revise instead of the current date, oryou can use-date =" date or time "-m: modify only mtime; Modification Time (Mtime): When the "content data" of this file is changed, it will be updated! Content data refers to the contents of a file, not the attributes or permissions of a file. -T: the time after which the revision can be received instead of the current time, in the format [YYYYMMDDHHMM]

Chattr (set file hidden properties)

[Email protected] ~]#chattr[+-=][asacdistu] File or directory name options and parameters:+: Add a special parameter, the other original parameters will not move. -: Remove a particular parameter, otherwise the original parameter is not moved. =: Set a certain, and only the following parameter a: When you set a property, if you have access to this file (or directory), his access time atime will not be modified, can avoid I/O slower machine over-access disk. (It is recommended to use file system mount parameters to handle this project) S: General file is non-synchronous write to disk (principle please refer to [previous chapter Sync] (...)/text/index.html#Sync), if you add S this property, when you make any changes to the file, the change is "synchronously" written to disk. A: After setting a, this file will only add data, not delete and cannot modify the data, only the root can set this property C: After this property is set, will automatically "compress" the file, will be automatically extracted when reading, but in the storage, It will be compressed and then stored (it seems pretty useful for large files!). D: When the dump program is executed, setting the D property will allow the file (or directory) not to be dump backup I: This I can be very powerful! He can make a file "can't be deleted, renamed, set link or can't write or add data!" "It's a great help for system security!" Only the root can set this property s: When the file is set to the S property, if the file is deleted, he will be completely removed from the hard disk space, so if deleted by mistake, can not be saved back Oh! U: In contrast to S, when using U to set a file, if the file is deleted, then the data content actually exists in the disk, you can use to rescue the file Oh! Note 1: Property settings are common for a and I settings, and many settings must be root to set the note 2:XFS file system only supports Aadis
Example: Please try to/tmp below create the file, and add the parameters of I, try to delete look. [[Email protected]~]# CD/Tmp[[email protected] tmp]#TouchAttrtest &lt;==Create an empty file [[email protected] tmp]#chattr+i attrtest &lt;==give the attribute of I [[email protected] tmp]#RMAttrtest &lt;==try to delete seeRM: Remove Regular emptyfile' Attrtest'? yRM: Cannot remove ' attrtest': Operation not permitted# Did you see it? Whirring Even Root has no way to delete this file! Quickly release the settings! Example: Please cancel the I property of the file! [Email protected] tmp]#chattr-I. attrtest

Lsattr (show file hidden properties)

lsattr [-AdR] file or directory options and Parameters:-A: The properties of the hidden file are also shown;-D: If a directory is followed, only the properties of the directory itself, not the file name within the directory;   Chattr +lsattr at

Set UID

The SUID permission is valid only for binary program (binary programs);

Performer must have X executable permission for the program;

This permission is valid only in the course of executing the program (run-time);

The performer will have the permissions of the program owner (owner).

Set UID

SGID is useful for binary programs;

The program executor is required to have X permission for the program;

The performer will receive the support of the program group during the execution process!

When a directory has the SGID permissions set, he will have the following features:

The user can enter this directory if they have r and X permissions for this directory;

The user's active group (effective group) in this directory will become a group of that directory;

Purpose: If the user has permission to W in this directory (can create a new file), the new file created by the consumer will be the same as the group for this directory.

Sticky bit this Sticky bit, sbit is currently only valid for the directory, has no effect on the file. The role of Sbit for a directory is:

When the user has W, x permission, that is, the Write permission for this directory;

When a user creates a file or directory under that directory, only himself and Root have the right to delete the file

Suid/sgid/sbit permission settings

4 for SUID

2 for SGID

1 for Sbit

Use the chmod xxxx filename to set, and in addition to the digital method, you can also use the symbolic method to deal with Oh! Where SUID is U+s, and SGID is G+s, Sbit is o+t!

File types observed

Linux Department of Science notes

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.