File management commands on Linux
Directory management command:
Mkdir: make directories
Mkdir [OPTION]… DIRECTORY...
-P: automatically create the parent directory as needed;
-V: verbose. Detailed process is displayed;
-M MODE: Grant permissions directly;
Note: The Path base name is the target object of the command. The path before the base name must exist;
Rmdir: remove empty directories
Rmdir [OPTION]… DIRECTORY...
-P: After a directory is deleted, if its parent directory is empty, it will be deleted together;
-V: Display process;
File management commands
Cp command: copy
SOURCE file; target 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 this file in advance and copy the data stream of the source file to DEST;
If DEST exists:
If DEST is a non-directory file, it overwrites the target file;
If DEST is a directory File: 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 and keep the original name;
Common options:
-I: interactive replication, that is, reminding the user to confirm before overwriting;
-F: forcibly overwrite the target file;
-R,-R: recursively copy the directory;
-D: Copy the symbolic link file instead of the source file to which it points;
-A:-dR-preserve = all, archive, used for archiving;
-Preserv =
Mode: permission
Ownership: Owner and group
Timestamps: Timestamp
Context: Security label
Xattr: Extended Attributes
Links: symbolic link
All: all of the above attributes
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
Bash features
Command execution status result
Command execution status result:
Bash outputs this result through the returned state values:
Success: 0
Failed: 1-255
Command line expansion
~ : Automatically expand to the user's home directory or the specified user's home directory;
{}: A comma-separated path list can be carried and expanded into multiple paths;
Create a_c, a_d, B _c, and B _d in the/tmp directory.
Touch {a, B }_{ c, d}
Create/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 metadata
File metadata mainly includes permissions, sizes, inode, owner, group, access time, modify time, change time, etc...
You can run the stat command to view the file metadata.
The touch Command can modify the timestamp:
Touch [OPTION]… FILE...
-C: The specified file path is not created if it does not exist;
-A: Only access time is modified;
-M: only modify time is modified;
-T STAMP
[[CC] YY] MMDDhhmm [. ss]
Command alias & command execution result
You can use alias name = value to define the command alias.
Command execution result:
$ (COMMAND)
Or 'command'
Exercise
Show all files or directories in the/var directory that start with l and end with a lowercase letter, and contain at least one digit (may have other characters) in the middle.
Ls-ld/var/l * [0-9] * [a-z]
Displays the files or directories in the/etc directory that start with any number and end with a non-number.
Ls-ld/etc/[0-9] * [^ [: digit:]
The/etc directory starts with a non-letter and is followed by a file or directory with a letter and any other characters of any length.
Ls-ld/etc/[^ [: alpha:] [a-z] *
Create a file starting with tfile, followed by the current date and time under the/tmp directory, with a file name like a tfile-2016-05-27-09-32-22.
Touch/tmp/tfile-'date + % Y-% m-% d-% H-% M-% s'
Copy all files or directories starting with p and ending with non-numbers in the/etc directory 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 files starting with l, m, or n in the/etc/directory and ending with. conf to the/tmp/mytest3 directory.
Cp-r/etc/[lmn] *. conf/tmp/mytest3/