Here are the usual commands to remind yourself lest you always forget a few
cd pwd mkdir rmdir LS MV CP RM Cat TAC NL More less head tail OD
Ls-l file <== shows the default Mtime
LS--time={ctime|atime] File <== Displays the specified time type
LS--full-time <== Displays the full time mtime
Mtime (modification time), CTime (status Tim), Atime (Access time)
#touch [-ACDMT] File name
Options and Parameters:
-A: Revise access time only;
-C: Only the time to modify the file, 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 the--date= "date or time"
-M: Modify Mtime only;
-T: The time after which the revision can be received instead of the current time, in the format [YYMMDDHHMM]
# touch-d "2 days Ago" BASHRC <== date changed to 2 day ago
# touch-t 0709150202 BASHRC <== date changed to 2007/09/15 2:02
The dates in Atime and mtime have changed, but CTime is the time to record the current!
File preset permissions: umask
#umask <== View default settings
Set Umask
#umask 002 <==umask directly after the permission to subtract
Initial permissions for files and directories:
File: (-rw-rw-rw-)
Catalog: (DRWXRWXRWX)
So user-created permissions for files and directories are
[File | directory] Initial permissions-user Umask
Preset umask settings can refer to/ETC/BASHRC the contents of this file, however, it is not recommended to modify the file
File Hidden properties:
However, it is emphasized that the CHATTR directive can only take effect on the Ext2/ext3 file system, and other file systems may not be able to support this command.
Chattr (Profile Hide property)
#chattr [+-=][asacdistu] file or directory name
Options and Parameters:
+: Add a special parameter, other existing parameters will not move.
-: Remove a particular parameter, otherwise the original parameter does not move.
=: Set a certain, and only the following parameters
A: When you set the A property, if you have access to this file (or directory), his access time atime will not be modified, to avoid the slow I/O machine over-access disk. This is helpful for slower computers
S: The general file is written asynchronously to the disk, and if you add s this attribute, when you make any file changes,
The change is "synchronized" to the disk.
A: After setting a, the file will only add data, not delete or modify the data, only the root can be set
C: After this property is set, it will automatically "compress" the file, when it is read will be automatically decompressed, but when stored, will be compressed and then stored, for large files seems to be quite useful.
D: When the dump program is executed, setting the D property will allow the file (or directory) to not be backed up by dump
I: This I can be very powerful! He can make a file "cannot be deleted, renamed, set up a link and cannot write or add information!" Very helpful for system security! Only 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: and S, in contrast, when using U to configure the file case, if the file is deleted, then the data content actually exists in the disk, you can use to rescue the file Oh!
Note: Property settings are common for a and I settings, and many settings must be root to set
More detailed use of your own man
Because these properties are hidden properties, you need to lsattr to see the property
Lsattr (show file hidden properties)
#lsattr [-adr] File or directory
Options and Parameters:
-A: The properties of the hidden file are also displayed;
-D: If a directory is followed, lists only the properties of the directory itself rather than the file name within the destination;
-r: Data along with subdirectories are also listed
With chattr settings, you can use Lsattr to view hidden properties. However, these two directives must be used with special care, otherwise it will cause great distress. For example: One day you are in a good mood, suddenly will/etc/shadow this important password record file to him set to have the attribute of I, then after a few days, you suddenly want to add user, that has been unable to add! Don't doubt, go ahead and take the attributes of I away!
SUID SGID sbit
Set UID
When s this flag appears on the file owner's X permission, such as the/usr/bin/passwd of the file just mentioned
State: "-rwsr-xr-x", at this time is called the Set UID, referred to as SUID special permissions. Features and limitations of SUID:
Valid only for 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 owner of the program.
In addition, the suid can only be used on a binary program and cannot be used on shell script.
Set GID
When s this flag appears in the file group's X permission is called the Set GID, is referred to as SGID special permission.
For 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 permission to the program group.
For the catalog, at this point:
If the user has R and X permissions for this directory, the user can enter this directory;
A valid group of users in this directory will become a group of that directory;
Use:if the user has W permissions in this directory, the group of new files created by the user is the same as the group for this directory
Sticky Bit:
Valid only for directory:
When the user has w,x permissions for this directory, that is, when there is write permission;
When a user creates a file or directory under that directory, only the user and root have the right to delete the file or directory.
Values represent:
SUID 4
SGID 2
Sbit 1
Observation file type: Files
#file file
Search for instructions and documents:
Because we often need to know where the file is placed to be able to import the file for some modification or maintenance actions. Sometimes the file names of some software profiles are constant, but the directories placed by each distribution are different. At this point, you have to use some search instructions to capture the full file name of the configuration file so that you can modify
Search for script file names:
We know that in the terminal mode, two consecutive [tab] keys can be used to know how many instructions the user has to release. Do you know where the full file name of these instructions is placed? For example, where is the common instruction for LS? Find it through which or type!
# which [-a] command
Options and Parameters:
-A: Lists all instructions that can be found in the PATH directory, not just the first found command name
Which default is to find the directory within the PATH specification
Search for file name:
Whereis (looking for a specific file)
# Whereis [-bmsu] file or directory name
Options and Parameters:
-B: Only binary format files are found
-M: Only files found under the manual path of the description file
-S: Only source files are found
-U: Search for other special files not included in the above three items
#locate [-ir] keyword
Options and Parameters:
-I: Ignoring the difference in case;
-R: Can be followed by the normal representation of the display mode
whereis and locate are searched through the database, and the database is built by default once a day (each distribution
is different, the CentOS 5.x is updated every day the database once, so when you create a new file, that also before the database update to search for the file, then locate will tell you "can't find", because the database must be updated, manually update the Locate database method is very simple, direct input " UpdateDB "On it, updatedb instructions will go to read/etc/updatedb.conf This configuration file settings, and then go to the hard disk to search the file name action, and finally update the entire database file. Because UpdateDB is going to search the hard drive, you may wait a few minutes when you execute updatedb.
UpdateDB: According to the/etc/updatedb.conf settings to search the system hard disk file name, and update the database files within the/var/lib/mlocate;
Locate: According to the database records in the/var/lib/mlocate, find the user input keyword file name.
Find command:
#find [PATH] [option] [action]
Options and Parameters:
1. Time-related options: Total-atime,-ctime and-mtime, with-mtime instructions
-mtime N: (n) is a number, meaning a document that has been altered in "one day" prior to the nth day;
-mtime +n: Lists the file names of the files that were changed before n days (excluding the N-day itself);
-mtime-n: Lists the file name of the content that was changed within n days (including the N-day itself).
-newer File:file for an existing file, list file names that are newer than files
2. Parameters related to user or group name:
The UID 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 and corresponds to the account name.
-gid-N is a number, which is the ID of the group name, the GID, which is recorded in/etc/group.
-user name:name for user account name Oh! For example Dmtsai
-group Name:name for the group name Oh, for example, users;
-nouser: Looking for files that have no/etc/passwd in their possession
-nogroup: Find files that do not exist in/etc/group with groups
When you install the software yourself, it is possible that the properties of the software do not have the file owner, which is possible, at this time, you can use
-nouser and-nogroup search.
3. Parameters related to file permissions and names:
-name filename: Search for files named filename;
-size [+-]size: Search for files larger than size (+) or small (-). The sizes of this size are:
C: Represents Byte, K: Represents 1024bytes. So, to find a bigger file than 50KB, is "-size +50k"
-type Type: Search for file types, types are mainly: general normal file (f), device file (b, c), directory (d),
Link file (l), socket (s), and FIFO (p) properties.
-perm Mode: Search file permission "just equals" mode file, this mode is similar to the Chmod property value, for example,
The-rwsr-xr-x property is 4755
-perm-mode: Search file Permissions "must all include mode permissions" 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 permission of-rwsr-xr-x, that is, 4755, will also be listed because the properties of the-rwsr-xr-x already include the properties of the-rwxr--r--.
-perm +mode: Search for file permissions "include any mode permission" file, for example,
We search for-rwxr-xr-x, that is,-perm +755, but a file property is-RW-------will be listed, because he has-rw .... The attribute exists
4. Additional actions to be performed:
-exec Command:command For other instructions, the-exec can then be followed by additional instructions to process the results of the search.
-print: Prints the result to the screen, this action is a preset action
For example:
# Find/-perm +7000-exec ls-l {} \;
Special places in this example are {} and \; and-exec this keyword, the meaning of these things:
{} stands for "content found by find" and, as shown, the result of find is placed in the {} position;
-exec always to \; is the keyword, which represents the start of the Find extra action (-exec) to the end (\;), in which the extra action is within the Find command.
In this case, it is "ls-l {}"! "There is a special meaning in the bash environment, so use a backslash to jump off.
In addition, find can also use wildcard characters to find the file name!
For example, if you want to find out which file name contains httpd files under/etc, then you can do this:
#find/etc-name ' *httpd* '
But since find is searching for the hard drive when it comes to finding data, there's nothing to do with find.
File and directory management of Linux learning notes