2.Linux Files and directories

Source: Internet
Author: User

1. Directories and Paths
A more specific directory under Linux:
.         Represents this layer directory        : Represents the previous directory-represents the          previous working directory -the          home directory where the current user identity is located ~account represents the account  user's home directory ( Account is a name)

$PATH variables

$PATH is similar to the PATH environment variable under the Windows system, and the Execute command is to search for the existence of the command in the path specified by path.

Echo $PATH

You can display the value of the current $path variable.

Common commands for directories and files
CD: Switch directory pwd [-P]: Show current directory     -P: Displays the current directory, not the link path mkdir [-MP]: Create a new directory     -m: Permissions    for Profile -P : You can create a multi-level directory rmdir [-p]: Delete    an empty directory -P: Together with the previous "empty" directory to delete

Command List
ls: View files and directories CP, RM, MV: Copy, delete, and move basename directory: Get the last file name DirName directory: Get directory Name

2. File content and Property modification
Commands to view the contents of a file
Cat  starts displaying the file contents from the first line  the TAC starts with the last line, and you can see that the TAC is backwards written by cat! NL   Display, the output line number! More page by page The content of the file is less similar to more, but better than more, he can page forward! Head only a few lines tail only look at the tail a few lines od   in binary way read the contents of the file!
Touch Modify File Time

Linux files have three times :modification Time (mtime), Status Time (CTime), Access time (Atime) are modified, state changed, and read times respectively.

Touch [-acdmt] file options and Parameters:-a  : only revise access time;-C  : Only when the file is modified, and if the file does not exist, do not create a new file;-D  : You can follow the date you want to revise instead of the current date, or you can use--date=" date or time "-m  : Modify only mtime;-T  : The time of the following can be changed instead of the current time, in the format [YYMMDDHHMM]

File default Permissions

The umask command can display the default permission values when creating directories and files.

The default file permission is RW-RW-RW minus the default value, and if the value of Umask is 0022, then the calculation rule is rw-rw-rw minus 0-WX-WX

The default directory permission is drwx-rwx-rwx minus the default value, the calculation Rule drwx-rwx-rwx minus 0-WX-WX, you can modify the default value with the following command:

Umask value

File Hidden Properties

 chattr [+-=][asacdistu] file or directory name options and parameters:  + : Add a special parameter, otherwise the existing parameters will not move. -: Remove one of the special parameters, and the other parameters do not move.  =: Configuration must be, and only the following parameter a: When you configure a This property, if you have access to this file (or directory), his access time atime will not be modified, can avoid I  /o slow machine over-access disk. This is helpful for a slower computer S: General files are non-synchronous write disk (principle please refer to the fifth chapter of sync), if you add S this property, when you make any file modification, the change will be "synchronously" written to the disk. A: After configuring a, this file will only add data, not delete or modify the data, only root can configure this property. C: After this property is configured, the file will be "compressed" automatically, when read will be automatically decompressed, but in the time of storage, will be compressed and then stored (it seems to be very useful for large files!) D: When the dump program is run, configuring the D property will allow the file (or directory) to not be dump backup I: This I can be very powerful! He can make a file "can not be deleted, renamed, CONFIGURED links can not write or add data!" "It's a great help for system security!" Only the root can configure this property s: When the file is configured with 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 configure 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: Property configuration is common for configuration values of a and I, and many configuration values must be root to configure  

View File types
File File name

File Special Permissions
SUID, SGID, Sbit
3. Query for commands and files

Related commands

which [-a] command option or parameter:-a: Lists all commands that can be found in the PATH directory, not just the first found command name
Whereis [-BMSU] file or directory name options and parameters:-B    : Find only files in binary format-m: Find only    files under the manual path of the description file-S    : Find source only file-u    : Search for other special documents not included in the above three items
Locate [-ir] keyword options and parameters:-I  : ignoring case differences;-R  : Can be followed by the normal representation of the display method
Find [PATH] [option] [action] option with parameter: 1.  Time-related options: A total of-atime,-ctime, and-mtime, with the-mtime description   -mtime  N: "n" as the number, meaning "within one day" before the nth day of the document was changed;   -mtime +n: List in n The file name of the content that was changed prior to the day (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, list file names that are newer than
 2. Parameters related to the name of the user or group:-UID-N is a number, which is the user's account ID, which is the UID, which is the number that is recorded in the/etc/passwd that corresponds to the account name.   We will introduce this in the fourth chapter. -gid-N is a number, this number is the ID of the group name, that is, GID, this GID record in/etc/group, the relevant introduction we will fourth note ~-user Name:name for the user account name Oh!   For example, Dmtsai-group Name:name is a group name, such as users,-nouser: The owner of the search file does not exist/etc/passwd person!                -nogroup: Search for files that have groups that do not exist in/etc/group files! When you install the software yourself, it is possible that the properties of the software do not have the owner of the file, which is possible! At this time, you can use-nouser and-nogroup to search. 
 3. Parameters related to file permissions and names:-name filename: Searches for files called filename,-size [+-]size: Searches for files larger than size (+) or small (-). This size has the following specifications: C: Represents Byte, K: 1024bytes.                   So, to find a larger file than 50KB, is "-size +50k"-type type: Search for the file types, types mainly include: General formal file (f),   Device file (b, c), directory (d), Nexus (L), socket (s), and FIFO (p) properties.   -perm Mode: Search file Permissions "Just wait for" mode file, this mode is similar to the chmod attribute value, for example, the-rwsr-xr-x property is 4755!                 -perm-mode: Search for 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 permissions of-rwsr-xr-x, that is, 4755, it is also listed, because the properties of-rwsr-xr-x are already included in the-rwxr--r--attribute.                 -perm +mode: Search file permission "contains any mode permission" of the file, for example, we search for-rwxr-xr-x, that is,-perm +755, but a file property is-RW------- will also be listed because he has-rw .... The attribute exists! 
4. Extra action:   -exec Command:command for other commands, the-exec can be followed by additional commands to process the search                   results.   -print        : Print the results to the screen, this action is the default action!
4. End

2.Linux Files and directories

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.