1. What are the file management commands on Linux, their commonly used methods and their related examples?
1) cp function: Used to copy one or more source files or directories to the specified destination file or directory format: cp [option]... source... directory option: -i: Interactive -r, -R: recursive replication of directories and all internal content; -a: Archive, equivalent to-dr --preserv=all - d:--no-dereference --preserv=links --preserv[=attr_list] mode: Permissions ownership: Main group timestamp: linux time stamp links: files are soft links, only soft link files are copied xattr: File extension Properties context: Security Context all: including the aboveThere are -p: --preserv=mode,ownership,timestamp -v: --verbose Show copy process -f: --force forcibly copy files or directories, Example: 1, cp -i [[email , regardless of whether the destination file or directory already exists PROTECTED] ~]# CP -IV /ETC/ISSUE /TMP/      CP: Whether to overwrite "/ Tmp/issue "? y "/etc/issue" -> "/tmp/issue"     2, CP -r [[email protected] ~]# cp -rv /etc/ profile.d/* /tmp/cptest/ "/etc/profile.d/cinder.sh" -> "/ Tmp/cptest/cinder.sh " "/etc/profile.d/colorls.csh " -> "/tmp/ Cptest/colorls.csh " 3, cp -a [[email Protected] ~]# cp -av /etc/rc.d/ /tmp/ "/etc/rc.d/" -> "/ Tmp/rc.d " "/etc/rc.d/rc.sysinit " -> "/tmp/rc.d/rc.sysinit " "/ETC/RC.D/INIT.D" -> "/TMP/RC.D/INIT.D" 2) MV function: Rename a file or directory, or move a file from one directory to another: Mv [option]... source... directory option: -i: Interactive -f: Overwrite the existing file or directory directly if the destination file or directory is duplicated with an existing file or directory    -V: Show examples of moving processes: 1, mv -i [[email protected] ~]# mv -iv /etc/issue /tmp/     MV: Do you want to overwrite "/tmp/issue"? y "/etc/issue" -> "/tmp/issue" 2, [[email protected] ~]# mv -fv /etc/issue /tmp/ "/etc/issue" -> "/tmp/ Issue "3)  RM function: You can delete one or more files or directories in a directory, or you can delete a directory and all of its subordinate files and subdirectories of the format: Rm [option]... file ... Options: -i: Interactive -f: Force Delete -r: Recursive Example: 1, rm -i [[email protected] ~ ]# RM -IV /TMP/ISSUE     RM: Delete normal file "/tmp/issue"? y deleted "/tmp/issue" 2, rm -f [[email protected ] ~]# rm -fv /tmp/issue deleted "/tmp/issue" 3, RM -r [[email protected] ~]# rm -rfv /tmp/nameserver/ deleted/tmp/nameserver/filequeue/oplogsync/00000025.dat deleted/tmp/ nameserver/filequeue/oplogsync/00000011.Dat " deleted"/tmp/nameserver/filequeue/oplogsync/00000016.dat "
2. Bash's work characteristics the command execution status return value and command line expansion are involved in the content and its sample demonstration.
1) View Bash command execution status return value function: command execution end input echo $? If the return value is a number 0 , the command execution succeeds if the return value is non- 0 , the command execution failure example: [[email protected] ~]# ls /etc/passwd /etc/passwd [ [email protected] ~]# echo $? 02] Command line expansion function: ~: expand to the user's home directory ~username: Expand to the specified user's home directory {} : You can host a comma-delimited list and expand it to multiple paths example: 1, ~ [[email protected] ~]# ls -d ~ /root 2, ~username [[email protected] ~]# ls -d ~ Admin /home/admin 3, {} [[email&nbSp;protected] ~]# mkdir -pv /tmp/{a,b,c}/test1 mkdir: Created directory /tmp/a mkdir: created directory "/tmp/a/test1" mkdir: created directory /tmp/b mkdir: created directory "/tmp/b/test1" mkdir: created directory "/TMP/C" mkdir: created directory "/tmp/c/test1"
3. Use the command line expansion function to complete the following exercises:
(1), create the:a_c, a_d, b_c, b_d [[email protected] ~]# under the/tmp directory mkdir -v /tmp/{a,b}_{c,d} mkdir: created directory "/tmp/a_c" mkdir: created directory /tmp/a_d mkdir: created directory "/tmp/b_c" mkdir: created directory "/tmp/b_d" (2), created:mylinux/├── bin├── boot│ under/tmp/mylinux directory └── 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&nbSp;protected] ~] #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}> }mkdir: created directory "/tmp/mylinux" mkdir: created directory "/tmp/mylinux/bin" mkdir: Created directory "/tmp/mylinux/boot" mkdir: created directory "/tmp/mylinux/boot/grub" mkdir: created directory "/ Tmp/mylinux/dev "mkdir: created directory "/TMP/MYLINUX/ETC "mkdir: created directory "/TMP/MYLINUX/ETC/RC.D "mkdir: Created directory "/TMP/MYLINUX/ETC/RC.D/INIT.D" mkdir: created directory "/tmp/mylinux/etc/sysconfig" mkdir: Directory created "/tmp/mylinux/etc/sysconfig/network-scripts" mkdir: created directory "/tmp/mylinux/lib" mkdir: Directory created /tmp/mylinux/lib/modules mkdir: created directory /tmp/mylinux/lib64 mkdir: created directory /tmp/ Mylinux/proc "mkdir: created directory "/tmp/mylinux/sbin "mkdir: created directory "/tmp/mylinux/sys "mkdir: Directory created /tmp/mylInux/tmp "mkdir: created directory "/TMP/MYLINUX/USR "mkdir: created directory "/tmp/mylinux/usr/local "mkdir: Directory created "/tmp/mylinux/usr/local/bin" mkdir: created directory "/tmp/mylinux/usr/local/sbin" mkdir: created directory "/tmp/mylinux/var" mkdir: created directory "/tmp/mylinux/var/lock" mkdir: created directory "/tmp/mylinux/var /log "mkdir: created directory "/tmp/mylinux/var/run "
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.
1) View file original data information [[email protected] ~]# stat /etc/passwd file: "/ETC/PASSWD" file name Size: 1803 Blocks: 8 IO Block: 4096 size of file Device: 805h/2053d Inode: 1968006 Links: 1 Device Information Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) access rights to files Access: 2016-08-11 10:53:07.954380291 +0800 The time the file content was recently visited Modify: 2016-07-28 17:30:17.942011706 +0800 The time the file content was recently modified Change: 2016-08-11 10:53:05.402380179 +0800 The last time the metadata state changed 2) touch function: There are two functions: one is used to put the time of the existing fileThe labels are updated to the current time of the system (by default), their data is preserved intact, and the second is used to create new empty files. Format: Touch [option]... file ... Option: -a: only modify atime -m: modify Mtime only -t STAMP: change Atime,ctime to set to stamp at the same time stamp time format is as follows: [[CC]YY]MMDDhhmm[.ss] -c: If the file does not exist, do not create an example: [[email protected] ~]# touch -t 201609111201 /etc/passwd [[email protected] ~]# stat / etc/passwd file: "/etc/passwd" size: 1803 Blocks: 8 IO Block: 4096 General Documents device: 805h/2053d inode: 1968006 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) access: 2016-09-11 12:01:00.000000000 + 0800 modify: 2016-09-11 12:01:00.000000000 +0800 change: 2016-08-11 11:51:15.299375946 +0800
5, how to define the alias of a command, how to reference the execution result of another command in the command?
Alias function: Used to set the format of the instruction aliases: alias [-p] [name[=value] ... ] Options: - P: Print An example of a command alias that has been set: 1). Define a single command alias [[email protected] ~]# alias la= ' Ls -l --color=auto ' [[email Total dosage of protected] ~]# la /etc/profile.d/ 64 -rw-r--r-- 1 root root 361 10 Month 31 2013 cinder.sh -rw-r--r--. 1 root root 1127 10 Month  17 2013 COLORLS.CSH     2). Cancel a single command do not alias (-a cancel All) [[email protected] ~]# unalias la [[ Email protected] ~]# la /etc/profile.d/ -bash: la: command not foundNote: Aliases defined on the command line are valid only for the current shell process; If you want to be permanently valid, define in the configuration file; ~/.BASHRC is valid for all users:/ETC/BASHRC If the alias name is the same as the original command, execute the original command using \ Command reference commands can be executed using the reverse quotation mark ' command ' or $ [[email protected] ~]# echo $ (head /etc/issue.net) centos release 6.5 (Final) Kernel \r on an \m [[email protected] ~]# echo ' Head /etc/issue.net ' centos release 6.5 (Final) kernel \r on an \m
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.
[Email protected] ~]# touch/var/laa0123123a.txt[[email protected] ~]# ls-d/var/l*[0-9]*[[:lower:]]/var/ Laa0123123a.txt
7. Displays files or directories that start with any number in the/etc directory and end with a non-numeric number.
[[email protected] ~]# touch/etc/000123aasd.txt[[email protected] ~]# ls-d/etc/[[:d igit:]]*[^[:d IGIT:]]/ETC/000123AA Sd.txt
8, Show/etc directory, start with a non-letter, followed by a letter and any other arbitrary length of any character file or directory.
[Email protected] ~]# touch/etc/2a.txt[[email protected] ~]# ls/etc/[^[:alpha:]][[:alpha:]]*/etc/2a.txt
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.
[Email protected] ~]# touch/tmp/tfile-$ (date +%f-%h-%m-%s) [[email protected] ~]# ls/tmp/tfile-2016-08-11-12-33-41/ tmp/tfile-2016-08-11-12-33-41
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.
[[Email protected] ~] #mkdir/tmp/mytest1[[email protected] ~]# cp-a/etc/p*[^0-9]/tmp/mytest1/
11. Copy all files or directories ending with. D in the/etc directory into the/tmp/mytest2 directory.
[Email protected] ~]# mkdir/tmp/mytest2[[email protected] ~]# cp-a/etc/*.d/tmp/mytest2/
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.
[Email protected] ~]# mkdir/tmp/mytest3[[email protected] ~]# cp-a/etc/[1,m,n]*.conf/tmp/mytest3/
Second week homework