1. What are the file management commands on Linux, their commonly used methods and their related examples?
File Management: CP,MV,RM
Cp:
Copy command
Command format:
CP [OPTION] ... [-T] Source (original file) DEST (destination file)
CP [OPTION] ... Source (original file) ... Directory (Directories)
CP [OPTION] ...-t DIRECTORY SOURCE ...
CP SRC DEST
SRC is a file:
If the target does not exist: Creates a new dest and fills the contents of SRC into the dest;
If the directory exists:
If Dest is a file: overwrites the contents of SRC into the dest;
It is recommended to use the-I option for the CP command;
If the dest is a directory: Create a new file with the same name as the original file under Dest and populate the contents of SRC with the new file
CP SRC ... DEST
SRC.: Multiple Files
Dest must exist and be a directory, and other situations will be wrong;
CP SRC DEST
SRC is the directory:
Use option at this time:-R
If Dest does not exist: creates the specified directory and copies all files in the SRC directory to dest;
If dest exists:
If Dest is a file: Error
If Dest is a directory: Copy to this directory
Common options:
-I: Interactive
-r,-r: Recursively copy directories and all internal content;
-A: archive, preserving all attributes of the file, equivalent to-DR--preserv=all
-D: Copy the connection file instead of the source file it points to, do not track the symbolic link--no-dereference--preserv=links
--preserv=[attr_list]
Mode: Permissions
Ownership: Belong to the main group
Timestamp: Time stamp
Links: Link Properties
Xattr: Extended Properties
Context: Security context
All: All
-P:--preserv=mode,ownership,timesamp
-v:--verbose Display Operation process
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/85/EC/wKiom1eu9lzBGE4kAAAnmuAGxgM847.png-wh_500x0-wm_3 -wmp_4-s_2615290387.png "style=" Float:none; "title=" 2.png "alt=" Wkiom1eu9lzbge4kaaanmuagxgm847.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/85/EC/wKiom1eu-oPgUJu2AACyiwb3Ml8189.png-wh_ 500x0-wm_3-wmp_4-s_3367514916.png "title=" 3.png "alt=" wkiom1eu-opguju2aacyiwb3ml8189.png-wh_50 "/>
mv:move; Move file
mv [OPTION] ... [-T] SOURCE DEST
mv [OPTION] ... SOURCE directory
MV [OPTION] ...-t DIRECTORY SOURCE ...
src is a file:
if the target does not exist: Creates a new dest, fills the contents of SRC into dest, and deletes the src file
If the directory exists:
If Dest is a file: equivalent to duplicate name
If the dest is a directory: Create a new file with the same name as the original file under Dest and populate the SRC content in the new file and delete the SRC directory
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/EC/wKioL1eu-piyqrKbAAC3Wzsfk3Q011.png-wh_500x0-wm_3 -wmp_4-s_3805563678.png "title=" 4.png "alt=" Wkiol1eu-piyqrkbaac3wzsfk3q011.png-wh_50 "/>
RM Delete a file or directory
RM [OPTION] ... FILE ...
Common options:
-I: Interactive
-F: Force delete
-R: Recursive delete
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/EC/wKiom1eu_M7wUJ30AAC0Rbl5eoA280.png-wh_500x0-wm_3 -wmp_4-s_1308846982.png "title=" 5.png "alt=" Wkiom1eu_m7wuj30aac0rbl5eoa280.png-wh_50 "/>
2. Bash's work characteristics the command execution status return value and command line expansion are involved in the content and its sample demonstration.
Execution result status of the command
Success/failure: two states
Bash uses a special variable $? Save the execution status result of the most recent command:
0: Success
1-255: Failure
Program execution has two types of results:
The return value of the program:
program execution status results;
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/EC/wKioL1evBOHxCaq3AABQ0OrS5y4821.png-wh_500x0-wm_3 -wmp_4-s_655067673.png "title=" 6.png "alt=" Wkiol1evbohxcaq3aabq0ors5y4821.png-wh_50 "/>
Command line expansion
~: Expand to the user's home directory
~username: Expand the home directory for the development user
{}: Can host a comma-separated list and expand it to multiple paths
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/EC/wKiom1evDheCfKPeAAAu4zcN8qg796.png-wh_500x0-wm_3 -wmp_4-s_4067622459.png "title=" 7.png "alt=" Wkiom1evdhecfkpeaaau4zcn8qg796.png-wh_50 "/>
3. Use the command line expansion function to complete the following exercises:
(1), create/tmp directory: A_c, A_d, B_c, B_d
MKDIR/TMP/{A,B}_{C,D}
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/85/EC/wKiom1evDyfAy1v8AAAodwyMRH8621.png-wh_500x0-wm_3 -wmp_4-s_954636949.png "title=" 8.png "alt=" Wkiom1evdyfay1v8aaaodwymrh8621.png-wh_50 "/>
(2), create/tmp/mylinux directory:
mylinux/
├──bin
├──boot
│ └──grub
├── Dev
├──etc
│ ├──rc.d
│ │ └──init.d
│ └──sysconfig
│ └──network-scripts
├──lib
│ └──modules
├──lib64
├──proc
├──sbin
├──sys
├──tmp
├──usr
│ └──local
│ ├──bin
│ └──sbin
└──var
├──lock
├──log
└──run
[[Email protected]t/]# mkdir-p/ Tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d,sysconfig}/{init.d,network-scripts},lib/modules,lib64,proc,sbin,sys, Tmp,usr/local/{bin,sbin},var,lock,log,run}
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/EC/wKiom1evGuSDeGR0AAAeBvnBIPg422.png-wh_500x0-wm_3 -wmp_4-s_1201269131.png "style=" Float:none; "title=" 12.png "alt=" Wkiom1evgusdegr0aaaebvnbipg422.png-wh_50 "/>
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/85/EC/wKioL1evGuSQ9awhAAAlwmOcvt0506.png-wh_500x0-wm_3 -wmp_4-s_3070623776.png "style=" Float:none; "title=" 13.png "alt=" Wkiol1evgusq9awhaaalwmocvt0506.png-wh_50 "/>
4, what is the metadata information of the file, what does it mean, how to view it? How to modify timestamp information for a file.
Stat/path/to/somefile: Gets the metadata for the development file:
Time Stamp management tool for files
Touch
View file Status: Stat
Three time stamps:
Access time: Atime, reading the contents of a file
Modify Time: Modified, abbreviated to Mtime, change the file contents (data)
Change time: Changed to CTime, meta data changed
Touch [OPTION] ... [FILE] ...
-A: Only modified access time only Atime
-M: Modify only the modified time Mtime
-T STAMP:
[[Cc]yy] MMDDHHMM[.SS]
-C: If the file does not exist, it is not created
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/85/EC/wKiom1evHuiBTS2WAACHH98yv0c761.png-wh_500x0-wm_3 -wmp_4-s_2974350880.png "title=" 21.png "alt=" Wkiom1evhuibts2waachh98yv0c761.png-wh_50 "/>
5, how to define the alias of a command, how to reference the execution result of another command in the command?
Command Aliases (alias)
Implemented by the alias command:
(1) Ailas
Displays all the available command aliases for the current shell process:
(2) Alias Name= ' VALUE '
Defines the alias name, which is equivalent to executing the command value;
Note: Aliases defined on the command line are valid only for the current shell process, and are defined in the configuration file if you want to be permanently valid;
For the current user only: ~/.BASHRC
Valid for all users:/ETC/BASHRC
Note: The new configuration given by the edit configuration will not take effect immediately;
The bash process re-reads the configuration file;
Source/path/to/config_file
. /path/to/config_file
Revoke alias: Unalias
Unalias [-A] name [name ...]
Note: If the alias is the same as the name of the original command, you can use "\command" if you want to execute the original command;
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/85/ED/wKiom1evINuwrQ7BAAB9NnHDOM0687.png-wh_500x0-wm_3 -wmp_4-s_379506563.png "title=" 1.png "alt=" Wkiom1evinuwrq7baab9nnhdom0687.png-wh_50 "/>
6. Display all files or directories in the/var directory that start with L, end with a lowercase letter, and have at least one digit (can have other characters) appear in the middle.
ls-d/var/l*[[:d igit:]]*[[:lower:]]
ls-d/var/l*[0-9]*[[:lower:]]
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/85/ED/wKiom1evI1uzsy3jAAA7KwfLiGU276.png-wh_500x0-wm_3 -wmp_4-s_563143923.png "title=" 2.png "alt=" Wkiom1evi1uzsy3jaaa7kwfligu276.png-wh_50 "/>
7. Displays files or directories that start with any number in the/etc directory and end with a non-numeric number.
ls-d/etc/[[:d igit:]]*[^[:d igit:]]
Ls-d/etc/[0-9]*[^0-9]
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/85/EC/wKioL1evJGCR4JSDAAAdptcCazo002.png-wh_500x0-wm_3 -wmp_4-s_2911245623.png "title=" 3.png "alt=" Wkiol1evjgcr4jsdaaadptccazo002.png-wh_50 "/>
8, Show/etc directory, start with a non-letter, followed by a letter and any other arbitrary length of any character file or directory.
Ls-d/etc/[^[:alpha:]][[:alpha:]]*
Ls-d/etc/[^a-z,a-z][a-z,a-z]*
650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/85/ED/wKiom1evJf7BU0mUAAAfhhJXH8Q818.png-wh_500x0-wm_3 -wmp_4-s_1822063777.png "title=" 4.png "alt=" Wkiom1evjf7bu0muaaafhhjxh8q818.png-wh_50 "/>
9. In the/tmp directory, create a file that starts with Tfile, followed by the current date and time, with a filename such as: tfile-2016-08-06-09-32-22.
Nano/tmp/tfile-2016-08-13-22-09-22
Vi/tmp/tfile-2016-08-13-22-09-23
Vim/tmp/tfile-2016-08-13-22-09-24
touch/tmp/tfile-2016-08-13-22-09-25
echo ' Hello ' >/tmp/tfile-2016-08-13-22-09-26
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/85/EE/wKiom1evROzzoK-MAABf0jbHeek041.png-wh_500x0-wm_3 -wmp_4-s_2477811402.png "title=" 5.png "alt=" Wkiom1evrozzok-maabf0jbheek041.png-wh_50 "/>
10. Copy all the files or directories in the/etc directory to the/tmp/mytest1 directory that begin with P and do not end with a number.
Cp-a/etc/p*[^0-9]/tmp/mytest1/
Cp-a/etc/p*[^[:d igit:]]/tmp/mytest1/
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/85/ED/wKioL1evRSjzt7bdAABa7KqJ5v8053.png-wh_500x0-wm_3 -wmp_4-s_971903218.png "title=" 6.png "alt=" Wkiol1evrsjzt7bdaaba7kqj5v8053.png-wh_50 "/>
11. Copy all files or directories ending with. D in the/etc directory into the/tmp/mytest2 directory.
Cp-a/etc/*.d/tmp/mytest2
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/85/EE/wKiom1evRVvwEamaAAA7tBmkTyQ095.png-wh_500x0-wm_3 -wmp_4-s_3785509633.png "title=" 7.png "alt=" Wkiom1evrvvweamaaaa7tbmktyq095.png-wh_50 "/>
12. Copy all files in the/etc/directory that begin with L or M or N and end with. conf to the/TMP/MYTEST3 directory.
Cp-a/etc/[l,m,n]*.conf/tmp/mytest3
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/85/ED/wKioL1evRXbBfXJ8AAAnkJwl-p4978.png-wh_500x0-wm_3 -wmp_4-s_3983662344.png "title=" 8.png "alt=" Wkiol1evrxbbfxj8aaankjwl-p4978.png-wh_50 "/>
Homework for the second week of 2016-8-13