1. Linux What are the file management class commands on, their common usage methods, and their associated example demos.
# File and directory list view:ls
# File Contents view:Cat, TAC
# Modify the file timestamp or create a new file:Touch
# File Editor: VI, Nano
file Management:CP, MV, RM,
(MkDir, RmDir: creating, deleting Directories)
(1) , copy command:CP
Format:
Cp[option] ... [-T] SOURCE DEST
Cp[option] ... SOURCE ... DIRECTORY
CP [OPTION] ...-t DIRECTORY SOURCE ...
Description: 1. If the target does not exist, create a new destination file and populate the target with the contents of the source file.
2. If the directory exists:
(1) The target is the document, covering
(2) target directory: Create a new file with the same name as the original file under the target path and populate the content
3. If the source file is multiple files, the destination must be present and the directory, and other situations will be faulted.
4.If the source file is a directory,the CP command does not recursively copy files and cannot be copied.
The option to use at this time:-R
(1) if the target does not exist, the directory is created and all files in the source directory are copied to the target.
(2) if the target exists and is a file, an error
(3) if the target exists and is a directory, copy it directly.
Common options:
-I: interactive
-r,-r: Recursively copy directories and all internal content
-A: archive (must retain the original appearance of the file when copying, including the modified time), equivalent to-DR--preserv=all preserve the properties of the file
Note: Replication modifies the file's source data,
-d:--no-dereference,--preserve=links Copy only the file itself, not the link it points to
--preserv=[attr_list]: Preserves the properties of the file,
The default reservation is not followed by the parameter : Mode,ownership,timestamps.
Mode: Permissions
Ownership: Belong to the main group
Timestamp: Time stamp
Links: Link Properties
Xattr: Extended Properties, hiding properties
Context
All
-P:--preserv=mode,owership,timestamp
-V:--verbose
-F:--force: Mandatory
(2), move command:MV:--move
Format:
MV [OPTION] ... [-T] SOURCE DEST
MV [OPTION] ... SOURCE ... DIRECTORY
MV [OPTION] ...-t DIRECTORY SOURCE ...
Common options: same as CP command
-I: interactive ( prompts you to do this)
-F: mandatory
(3), delete command:rm:--remove files or directories
format:rm [OPTION] ... FILE ...
Options:
-I: Interaction. Under administrator, all the RM defaults are with the -i option, and each action automatically prompts for the need to delete
-F: Forced execution
-r,-r: Recursive Delete, use this command to delete the directory and prompt action
Note: Under administrator, you can not delete the root directory by default /, if you do not want to delete, use the-RF parameter
such as rm-rf/tmp/soso/: Forcibly delete the/tmp/soso directory and its contents
2. Bash the command execution status return value and command-line expansion are involved in the work feature and its example demonstration.
(1)Bash command execution status return value use special variable $? Save
0, Success
1: Failure
echo $? Show Execution status
(2) command line expansion:
~: Expand to the user's home directory
~username: Expand the home directory for the specified user
{}: can host a comma-delimited list and expand it to multiple paths
For example:/tmp/{a,b} =/tmp/a,/tmp/b
3.Use the command line expansion function to complete the following exercises:
(1) , creating the/tmp directory:a_c,a_d, B_c, B_d
MKDIR-PV/TMP/{A,B}_{C,D}
(2) , create the/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
For:
Mkdir-pv/tmp/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}
4, what is themetadata information of the file, what does it mean, how to view it? How to modify timestamp information for a file.
A: The metadata of a file is used to record a lot of information about a file, such as
Size: Sizes,
Device: The location of the file
Uid: Owner,
Gid: The group that belongs to,
Blocks: Block Size,
Links: Link Quantity
Time stamp:
Access: Accessing Time
Modify: Modification Time,
Change: Changing Time
Wait a minute
Meta Data View:stat Command
to modify the timestamp of a file, use the Touch command:
format:touch[option] ... FILE ...
Parameters:
-A: Change only atime(access time)
-M: Change only mtime(Modify time)
-T STAMP: Specifying time modifications
[[Cc]yy] MMDDHHMM[.SS]
-C: not created if the file does not exist.
Note:touch file , the file is created by default if the file does not exist.
5, how to define the alias of a command, how to reference the execution result of another command in the command?
A : command aliases are defined using alias
(1)alias: Displays all the available command aliases for the current shell process
Alias Name= ' VALUE '
Defining aliases NAME, which is equivalent to executing the command VALUE
Example:alias cdnet= ' cd/etc/sysconfig/network-scripts
define the command alias cdnet and assign a value to the CD command after it
(2) The execution result of another command referenced in the command can be piped.
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*[0-9]*[[:lower:]]
For example:
[[email protected] var]# ls-d/var/l*[0-9]*[[:lower:]]
/var/l12d/var/l1c/var/l3b/var/l3k/var/labc8dfdse
7. Displays files or directories that start with any number in the/ etc directory and end with a non-numeric number.
Ls-d/etc/[0-9]*[^0-9]
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:]]*
or ls-d/etc/[^a-z][a-z]*.
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.
Create file:touch/tmp/tfile-' Date +%f-%h-%m-%s '
Create directory:mkdir/tmp/tfile-' Date +%f-%h-%m-%s '
All files or directories that start with P and that end with a non-number in the/etc Directory arecopied to the/tmp/mytest1 directory.
Mkdir/tmp/mytest1
Cp-a/etc/p*[^0-9]/tmp/mytest1
Copy all files or directories ending with. D in the/ etc directory into the/tmp/mytest2 directory.
Mkdir/tmp/mytest2
Cp-a/etc/*.d/tmp/mytest2
copy all files in the /etc/ directory that begin with L or m or n and end with. conf to the/tmp/mytest3 directory.
Mkdir/tmp/mytest3
Cp-a/etc/[lmn]*.conf/tmp/mytest3
This article is from the "Set Sail" blog, please make sure to keep this source http://mystery888.blog.51cto.com/9560453/1837788
Marco Linux Training second week course assignment