File directory Management class command vs. Shell features
First, list the contents of the directory.
LS: Lists the contents of the current directory or the specified directory
Usage: ls[options][file_or_dirs]
Options:
Ls-a List all Files
LS-L Display specific information
Ls-r directory recursion
Ls-ld Directory and Symbolic link information
LS-1 File Branch Display
Ls-s order from big to small
Ls-u with-t option, display and press atime new to old sort
Ls-u not sorted by directory store order display
Second, file wildcard characters
*: matches 0 or more characters.
? : matches any single character.
~: Current user home directory.
~username: User home directory.
~+: Current working directory.
~-: Previous working directory
^: Take the reverse.
[0-9]: match a range of numbers
[A-z]: lowercase letters start with lowercase in front of the upper case.
[A-Z]: Start with uppercase letters, start with a lowercase letter, and end with uppercase letters
[WXC]: matches any one of the characters in the list
[^WXC]: matches a character other than all characters in the list
Pre-defined character classes: #man 7 glob
[:d Igit:]: Any number, equivalent to 0-9
[: Lower:]: Any lowercase letter
[: Upper:]: Any uppercase letter
[: Alpha:]: Any case letter
[: Alnum:]: Any number or letter
[: Space:]: space
[:p UNCT:]: Punctuation
Practice:
1. Show all files or directories in the/var directory that start with L, end with a lowercase letter, and have at least one digit in the middle.
First use the touch command to create several files that meet the requirements, and then write out the commands to show them.
ls-d/var/l*[0-9]*[[:lower:]]
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/3A/wKiom1edgbeSSz3cAAAVSUgxbQw877.png "title=" Clipboard.png "alt=" Wkiom1edgbessz3caaavsugxbqw877.png "/>
2. Displays files or directories that start with any digit in the/etc directory and end with a non-numeric number.
Use touch with mkdir to create several conformance items with several non-conformance items and then enter the command to display.
ls-d/etc/[[:d igit:]]*[^[:d igit:]]*
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/85/39/wKioL1edgdSRqu22AAAVt1mpJaU479.png "title=" Clipboard.png "alt=" Wkiol1edgdsrqu22aaavt1mpjau479.png "/>
3. Display a file or directory with a non-letter, followed by a letter and any other length character, in the/etc directory.
Ls-d/etc/[^[:alpha:]][[:alpha:]]*
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/85/39/wKioL1edge_TDhRQAAAHwu0kSls780.png "title=" Clipboard.png "alt=" Wkiol1edge_tdhrqaaahwu0ksls780.png "/>
4. Displays all files or directories that start with a non-numeric end in the/etc directory.
Ls-d/etc/m[^[:migit:]]*
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/3A/wKiom1edggaz0W_QAAAhbx6ar4g247.png "title=" Clipboard.png "alt=" Wkiom1edggaz0w_qaaahbx6ar4g247.png "/>
5. Display all files or directories ending with. D in the/etc directory.
Ls-d/ETC/*.D
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/3A/wKiom1edgiPzs4fBAAAkkTcQwMQ796.png "title=" Clipboard.png "alt=" Wkiom1edgipzs4fbaaakktcqwmq796.png "/>
6. Displays all files or directories ending with. conf, beginning with m,n,r,p, in the/etc directory.
Ls-d/etc/[mnrp]*.conf
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKioL1edgjXBQmvNAAASCcflwaQ664.png "title=" Clipboard.png "alt=" Wkiol1edgjxbqmvnaaasccflwaq664.png "/>
Iii. usage of alias aliases
Alias aliases:
Show all current aliases ~] #alias
Defines alias Name= ' VALUE ' (valid only in memory at that time, which is invalid after exiting the login.) )
Aliases are permanently active:
Valid for current user only: Profile ~/.BASHRC
Valid for all Users: Config file/etc/bashrc
If you want the configuration file to take effect immediately and need to reread the configuration file, there are two ways to reread the configuration file
1:soure/path/to/config_file
2:. /path/to/config_file
Revoke alias: Unalias
How to use: unalias[-a] name [name ...]
Iv. file Management class commands
Stat command:
Stat: Displays the status of a file or file system
Statfile ...
Files: Two types of data
Meta Data: Metadata
Statistics: Data
Time stamp:
Recent access time: When the file data was last read.
Recently changed modify time: the date when the file was most recently added or deleted.
Recently changed change time: When the file source data was last changed (such as size).
Touch Command:
Touch: Time state change
Touch[option] ... FILE ...
-C: The specified file path does not exist when not created;
-A: Modify access time only;
-M: Modify modify time only;
-T STAMP
[[Cc]yy] MMDDHHMM[.SS]
V. File management tools: CP,MV,RM
CP Command: Copy
Single source copy: Cp[option] ... [-T] SOURCT DEST
If Dest does not exist: the implementation creates this file and copies the data flow from the source file to the destination (dest).
If dest exists:
If Dest is a non-catalog file: Overwrites the destination file.
If Dest is a directory file, a file with the same name as the source file is now created in the Dest directory and its data stream is copied.
Multi-source replication: cp[option] ... SOURCT ... DIRECTORY
: Cp[option]...-t DIRECTORY SOURCT
If Dest does not exist: error.
If dest exists:
If the dest is a non-directory file, error.
If Dest is a directory file: Copy each file to the destination file separately and keep the original.
Common options:
-I: Interactive replication, that is, before overwriting to remind the user to confirm.
-F (Force): Forces the overwrite of the target file. (actually delete the source file, copy the new file to the target)
-R: Recursively replicate directories.
-D: Copies the symbolic link file itself, not the source file it points to;
-A: Archive (backup) equivalent to-DR--preserv=all
--preserv[=attr_list]
Mode: Permissions.
Ownership: Belong to the main group
Timestamp: Time stamp
Links: Link
All: All
-P: Copy reserved permissions, belong to the main group, timestamp.
-V: View the specific replication process
MV Command: Move
Cell copy: Cp[option] ... [-T] SOURCT DEST
Multi-source replication: cp[option] ... SOURCT ... DIRECTORY
: Cp[option]...-t DIRECTORY SOURCT
Common options:
-I: Interaction
-F: Mandatory
RM Command: Remove
RM [option] ... FILE ...
Common options:
-I: Interaction
-F: Force delete
-R: Recursive
--no-preserve-root
Tip: You don't want to use aliases to use the original command with a backslash \ ' absolute path '.
Practice:
1. Define alias Baketc daily to backup all files under the/etc/directory to the/testdir/separate new directory, and require the format of the new directory is BACKUPYYYY-MM-DD, the backup process is visible.
Alias baketc= "cp-rv/etc//testdir/back ' date +%f '"
Define Alias-v Display process copy root under ECT file to follow down Testdie under the back plus date directory
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/85/3A/wKiom1edg2_gE6J1AAAG3T7ul4s550.png "title=" Clipboard.png "alt=" Wkiom1edg2_ge6j1aaag3t7ul4s550.png "/>
Backup process
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/85/3A/wKioL1edg4OT2VdGAADfFTDmvdI650.png "title=" Clipboard.png "alt=" Wkiol1edg4ot2vdgaadfftdmvdi650.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/3A/wKiom1edg6LiA9X2AAAIxWtJDV0878.png "title=" Clipboard.png "alt=" Wkiom1edg6lia9x2aaaixwtjdv0878.png "/>
2, first create the/testdir/rootdir directory, in the replication/root all files into the directory, and require the retention of their permissions.
Cp-r--preserv=mode/root/testdir/rootdir
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3A/wKiom1edg7eCCAfmAAAfPGJc7Fg414.png "title=" Clipboard.png "alt=" Wkiom1edg7eccafmaaafpgjc7fg414.png "/>
The previous error was not preceded by a space.
Six Directory Management class commands: Mkdir,rmdir
Mkdir:make Directory
Usage rules: mkdir[options] ... DIRECTORY ...
-P: Automatically create the parent directory as needed;
-v:verbose, show the detailed process;
-M MODE; directly given permissions;
Note: The base name of the path is the action object of the command. The path before the base name must exist.
Rmdir:remove Empty Directories
Usage rules: rmdir[options] ... DIRECTORY ...
-P: Recursive delete.
-V: Displays the procedure.
Practice:
1. How to create/testdir/dir1/x,/testdir/dir1/y,/testdir/dir1/x/a,/testdir/dir1/x/b
/testdir/dir1/y/a,/testdir/dir1/y/b.
MKDIR-PV/TESTDIR/DIR1/{X,Y}/{A,B}
This command, like the multiplication of the polynomial, understands that x and/a,/b combine y with the/a,/b of the back.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/85/3A/wKioL1edhCWy1l12AAAZM-1Xwu4452.png "style=" float: none; "title=" Clipboard.png "alt=" Wkiol1edhcwy1l12aaazm-1xwu4452.png "/>
2, how to create/testdir/dir2/x,/testdir/dir2/y,/testdir/dir1/x/a,/testdir/dir1/b.
Mkdir-pv/testdir/dir2/{x/{a,b},y}
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "spacer.gif"/> 650) this.width=650; "Src=" http ://s3.51cto.com/wyfs02/m01/85/3a/wkiol1edhcwis_tvaaatpu81t5a978.png "title=" Clipboard1.png "style=" Float:none; " alt= "Wkiol1edhcwis_tvaaatpu81t5a978.png"/>
3. How to create/testdir/dir3,/testdir/dir4,/testdir/dir5,/testdir/dir5/dir3
/testdir/dir5/dir4.
MKDIR-PV/TESTDIR/{DIR3,DIR4,DIR5/{DIR3,DIR4}}
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "spacer.gif"/> 650) this.width=650; "Src=" http ://s3.51cto.com/wyfs02/m02/85/3a/wkiom1edhcwwr0aiaaayxkiccke334.png "title=" Clipboard2.png "style=" Float:none; " alt= "Wkiom1edhcwwr0aiaaayxkiccke334.png"/>
V. Index nodes
-
The Inode (index node) table contains a list of all file system files
A node (an index node) is a table item that contains information about the file (source data) including:
File types, permissions, uid,gid connections, file size, timestamp, pointers to data blocks on disk, additional data about files
In a partition, the node number is unique, and the different partition node numbers may be the same, but not a file.
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/85/3B/wKiom1edpX3Sm6TVAADJHZztnyU376.png "title=" Clipboard.png "alt=" Wkiom1edpx3sm6tvaadjhzztnyu376.png "/>
In each partition is such a set of storage file mode, so the node number may be the same.
1. The role of CP in the Inode
Allocate a free inode number, generate a new entry in the Inode table create a directory entry in the directory, and associate the name with the inode number to generate a new file.
2. RM's role in the Inode
-
The number of connections is decremented, thereby releasing the inode number that can be reused
Put data blocks in the free list
Delete a catalog entry
The data is not actually deleted immediately but is overwritten when another file is used, so the data on that block can be retrieved before being overwritten.
3, the role of MV in the Inode
If the target and source of the MV command are in the same file system as the MV command:
Creates a new directory entry with a new file name.
Delete old directory entries that correspond to the old file names.
Does not affect the Inode table (except the timestamp) or the location of the data on the disk: No data is moved.
If the target and source are in a different file system, MV is equivalent to CP and RM
Six, hard link and soft connection
1. Hard Links
-
Creating a hard link adds an additional record entry to reference the file.
Corresponds to a physical file in a partition.
Each directory references the same index node number
Increase number of links at creation time
When deleting files:
1, RM command decrements the Count of links
2, the file must exist, at least one link number
3. The file is deleted when the number of links is zero
Cannot span drives or partitions
Syntax: ln filename [linkname]
2. Soft link
-
A symbolic link points to another file
Ls-l display the name of the link and the referenced file
A symbolic link content is the name of the file it references
The directory can be
Can span partitions
A path to another file whose size is the length of the path string pointed to, and does not increase or decrease the reference count of the target file inode;
Syntax: Ln-s Filename[linkname]
The difference between a hard link and a soft connection:
A hard join refers to a connection made through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). The role of a hard connection allows a file to have multiple valid path names so that users can establish a hard connection to important files to prevent "accidental deletion" of the function. So when you have some important files, you can create a lot of hard links to important files, and only the last link is deleted, the corresponding link will be released.
A soft link file is a bit like a shortcut to Windows.
Personal experience:
A soft link is another file, like a pointer, that moves directly to the file that the soft connection is pointing to, and the soft connection is like another file, so it takes up space.
Hard link It is just an alias of the actual file, its role is to prevent the file is mistakenly deleted, after a hard link to a file, delete any of them, the actual file will not be deleted.
Seven: Determine the contents of the file
1. Files can contain multiple types of data
2. Check the file type and then determine the appropriate open command or application to use
3. File[option]<filename>
OPTION:
-
-B: The file name is not displayed when the file identification results are listed.
-C: Detailed instruction execution process, easy to debug or analyze program execution
-F: Lists the file types of file names in files.
-F: Replace the default ":" Delimiter with the specified delimiter symbol for the output file name
-I: Output MIME type string
-L: Check the file type corresponding to the corresponding soft link
-Z: Try to interpret the contents of compressed files
--help: Show Command online Help
File directory Management class command vs. Shell features