File management commands on Linux
Directory Management Commands:
Mkdir:make Directories
mkdir [OPTION] ... DIRECTORY ...
-P: Automatically create parent directory on demand;
-v:verbose, show the detailed process;
-M MODE: direct given permissions;
Note: The path base name is the action object of the command; the path before the base name must exist;
Rmdir:remove Empty Directories
rmdir [OPTION] ... DIRECTORY ...
-P: Deletes a directory, if its parent directory is empty, then delete it;
-V: Display process;
File Management Commands
CP Command: Copy
source file; object file;
Single-source replication: CP [OPTION] ... [-T] SOURCE DEST
Multi-source replication: CP [OPTION] ... SOURCE ... DIRECTORY
CP [OPTION] ...-t DIRECTORY SOURCE ...
Single-source replication: CP [OPTION] ... [-T] SOURCE DEST
If Dest does not exist: Create the file beforehand and copy the source file's data stream into the dest;
If dest exists:
If Dest is a non-directory file: overwrites the target file;
If Dest is a directory file: first create a file with the same name as the source file in the Dest directory and copy its data stream;
Multi-source replication: CP [OPTION] ... SOURCE ... DIRECTORY
CP [OPTION] ...-t DIRECTORY SOURCE ...
If Dest does not exist: error;
If dest exists:
If Dest is a non-directory file: error;
If Dest is a directory file: Copy each file to the target directory separately, and keep the original;
Common options:
-I: Interactive replication, that is, before overwriting to remind users to confirm;
-F: Force overwrite target file;
-R,-r: recursively replicating directories;
-D: Copies the symbolic link file itself, not the source file it points to;
-a:-dr–preserve=all, archive, for the implementation of archiving;
–preserv=
Mode: Permissions
Ownership: Genus and Group
Timestamps: Time stamp
Context: Security label
Xattr: Extended Properties
Links: Symbolic Links
All: Above all properties
MV Command: Move
MV [OPTION] ... [-T] SOURCE DEST
MV [OPTION] ... SOURCE ... DIRECTORY
MV [OPTION] ...-t DIRECTORY SOURCE ...
Common options:
-I: interactive;
-f:force
RM Command: Remove
RM [OPTION] ... FILE ...
Common options:
-i:interactive
-f:force
-r:recursive
Features of Bash
Execution status results of the command
Status result of command execution:
Bash prints this result by the state return value:
Success: 0
Failed: 1-255
Command line expansion
~: Automatically expand to the user's home directory, or specify the user's home directory;
{}: A comma-separated list of paths can be hosted and can be expanded to multiple paths;
Create the/tmp directory: A_c, A_d, B_c, B_d
Touch {A,b}_{c,d}
Created in the/tmp/mylinux directory.
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}}
File meta data
File metadata mainly includes permissions, size, Inode, owner, group, access time, modify time, change time,etc ...
The metadata for the file can be viewed with the stat command.
The touch command can modify the timestamp:
Touch [OPTION] ... FILE ...
-C: Is not created if the specified file path does not exist;
-A: Modify access time only;
-M: only modify Modify time;
-T STAMP
[[Cc]yy] MMDDHHMM[.SS]
Execution result of command alias & Reference command
You can use the alias Name=value form to define a command alias.
The execution result of the reference command:
$ (COMMAND)
or ' COMMAND '
Practice
Displays all files or directories in the/var directory that begin with L and end with a lowercase letter with at least one digit in the middle (which can have other characters).
LS-LD/VAR/L*[0-9]*[A-Z]
Displays a file or directory that starts with any number in the/etc directory and ends with a non-numeric number.
ls-ld/etc/[0-9]*[^[:d Igit:]]
Displays a file or directory in the/ETC directory, beginning with a non-letter, followed by a letter and any other characters of any length.
ls-ld/etc/[^[:alpha:]][a-z]*
Creates a file in the/tmp directory that starts with Tfile, followed by the current date and time, in the form of a filename such as: tfile-2016-05-27-09-32-22.
touch/tmp/tfile-' Date +%y-%m-%d-%h-%m-%s '
Copy all files or directories in the/ETC directory that start with P, ending in Non-numeric, to the/tmp/mytest1 directory.
Cp-r/etc/p*[^0-9]/tmp/mytest1/
Copy all files or directories ending with. D in the/etc directory to the/tmp/mytest2 directory.
Cp-r/etc/*.d/tmp/mytest2/
Copy all the files in the/etc/directory that begin with L or M or N and end with. conf to the/TMP/MYTEST3 directory.
Cp-r/etc/[lmn]*.conf/tmp/mytest3/