1. What are the file management commands on Linux? Common usage and related examples.
Common scenarios include cp, mv, and rm.
Cp [OPTION] source dest // Copy
Option:
-I: indicates whether to overwrite the source file. If the source file is copied and pasted to the target path, if the target path has the same name, the system prompts whether to overwrite the source file, otherwise, no message is displayed.
-R: recursively copy the directory and all internal content. This option is usually required to copy the directory.
-A: Archive. -D: indicates that the source file to which the symbolic link is directed is not tracked, and the linked file is copied directly.
-P: Keep the attribute information of the original file.
-F: force overwrite
-V: Display process
Mv [OPTION] source dest // move
Option:
-I: Interactive
-F: Force
Rm [OPTION] FILE // delete
Option:
-I: Interactive
-F: Force
-R: recursion
2. bash's working features-command execution status return values and command line expansion involved content and its example demonstration.
Expand the command line:
~ : Expand to the user's home directory
~ USERNAME: expands to the Directory of the specified user.
{}: Multiple paths can be expanded. Multiple paths are separated by commas.
For example:/tmp/{a, B, c} is expanded to/tmp/a,/tmp/B,/tmp/c three directories or files
Command execution result Status:
Bash uses special variables $? Save the execution result of the latest command: echo $?
Success: 0
Failed: 1-255
3. Use the command line expansion function to complete the following exercises:
(1) create a_c, a_d, B _c, B _d in the/tmp directory.
[Root @ localhost ~] # Mkdir-v/tmp/{a, B }_{ c, d}
(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
[Root @ localhost ~] # Mkdir-v-p/tmp/{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 are the metadata information of a file, and what are their meanings? How can I view them? How to modify the file timestamp information.
Metadata: metadata, file name, size, and attribute composition
5. How to define the alias of a command and reference the execution result of another command in the command?
The command alias can replace a command with other names.
Define alias:
Alias new_name = 'old _ name option'
For example:
Alias connet = 'ifconfig eno16777736 192.168.1.1'
6. 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 (which can contain other characters) in the middle.
Ls-d/var/l * [0-9] * [[: lower:]
7. Display files or directories starting with any number and ending with a non-number in the/etc directory.
Ls-d/etc/[0-9] * [^ 0-9]
8. 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-d/etc/[^ a-z] [[: alpha:] *
9. Create a file starting with tfile in the/tmp Directory, followed by the current date and time, the file name is like: tfile-2016-05-27-09-32-22.
Mkdir-v tfile-$ (date + % Y-% m-% d-% H-% M-% S)
10. Copy all files or directories starting with p and ending with non-numbers in the/etc directory to the/tmp/mytest1 directory.
[Root @ localhost ~] # Mkdir/tmp/mytest1 [root @ localhost ~] # Cp-a/etc/p * [^ 0-9]/tmp/mytest1
11. Copy all files or directories ending with. d in the/etc directory to the/tmp/mytest2 directory.
[Root @ localhost ~] # Mkdir/tmp/mytest2 [root @ localhost ~] # Cp-a/etc/*. d/tmp/mytest2
12. Copy all files starting with l, m, or n and ending with. conf to the/tmp/mytest3 directory.
[Root @ localhost ~] # Mkdir/tmp/mytest3 [root @ localhost ~] # Cp-a/etc/[lmn] *. conf/tmp/mytest3