N33-week 2-Sunflower

Source: Internet
Author: User
Tags clear screen directory create echo display

1. What are the file management commands on Linux, their common use methods and their related examples
Touch: Create file and Refresh Timestamp
Touch [OPTION]. FILE:
"1" touch-c file name: Refreshes the timestamp of the file if the file already exists, and creates an empty file if the file does not exist
Example:
Touch-c Tmpchi or Touch Tmpchi
No files in directory create empty file:-rw-r--r--. 1 root root 0 Oct 7 14:18 Tmpchi
File in directory refresh timestamp:-rw-r--r--. 1 root root 0 Oct 7 14:21 Tmpchi
"2" touch-a file name: Change only Atime and CTime
Example:
Touch-a Tmpchi
access:2018-10-07 14:21:42.167194043 +0800
modify:2018-10-07 14:21:01.915193580 +0800
change:2018-10-07 14:21:42.167194043 +0800
"3" touch-m file name: Change only Mtime and CTime
Example:
Touch-m Tmpchi
access:2018-10-07 14:21:42.167194043 +0800
modify:2018-10-07 14:23:43.221195437 +0800
change:2018-10-07 14:23:43.221195437 +0800
"4" touch-t [[CC]YY]MMDDHHMM[.SS]: Specify timestamps for Atime and Mtime
Example:
Touch-t 201809081112.13 Tmpchi
access:2018-09-08 11:12:13.000000000 +0800
modify:2018-09-08 11:12:13.000000000 +0800
change:2018-10-07 14:24:55.220196265 +0800

CP: Copying Files or directories
"1" CP [OPTION] ... [-T] SOURCE DEST: Copying files and changing file names
Cp-i: Tips before overwriting
Example:
The file does not exist, a new file is created
Cp/tmp/tmpchi/app/tmpchi.bak
-rw-r--r--. 1 root root 0 Oct 7 14:34/app/tmpchi.bak
-rw-r--r--. 1 root root 0 Oct 7 14:25/tmp/tmpchi
File already exists, overwrite the file (i-I prompt prior to overwrite)
Cp-i/tmp/tmpchi/app/tmpchi.bak
-rw-r--r--. 1 root root 0 Oct 7 14:36/app/tmpchi.bak
-rw-r--r--. 1 root root 0 Oct 7 14:25/tmp/tmpchi
"2" CP [OPTION] ... SOURCE ... DIRECTORY: Copying files without changing file names
Cp-r,-r: Recursively copy directories and all internal content
Example:
Copy a TMP directory in the app directory (-R recursively copies the TMP directory and all internal content)
Cp-r/tmp/app
Drwxr-xr-t. Root root 4096 Oct 7 14:43 tmp
"3" cp-d: Copy Soft connection Name
Example
If you do not add-D, if you copy a directory, the default copy directory's soft connection points to the corresponding original file, not the soft connection itself
Cp/etc/rc/app
-rwxr-xr-x. 1 root root 2617 Oct 7 15:09/APP/RC
lrwxrwxrwx. 1 root root 7 Sep 21:44/ETC/RC-RC.D/RC
Cp-d/etc/rc/app
lrwxrwxrwx. 1 root root-Oct 7 15:13/APP/INIT.D-RC.D/INIT.D
lrwxrwxrwx. 1 root root one Sep 21:32/etc/init.d-rc.d/init.d\\
"4"--preserv
-rw-r--r--. 1 root root 0 Oct 7 15:23/app/tmpchi
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/tmp/tmpchi
CP--preserv=timestamp: Preserve the timestamp of the source file while copying
Example:
Cp/tmp/tmpchi/app/tmpchi--preserv=timestamp
-rw-r--r--. 1 root root 0 Oct 7 15:22/app/tmpchi
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/tmp/tmpchi
CP--preserv=ownership: Preserve the owner of the source file while copying
Example:
Cp/tmp/tmpchi/app/tmpchi--preserv=ownership
-rw-r--r--. 1 cmx CMX 0 Oct 7 15:25/app/tmpchi
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/tmp/tmpchi
CP--preserv=all equivalent to CP-A: archive, preserving all properties of the source file while copying
Example:
Cp-a/tmp/tmpchi/app/tmpchi or Cp/tmp/tmpchi/app/tmpchi--preserv=all
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/app/tmpchi
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/tmp/tmpchi
Example:
CP--backup=numbered: Target exists, backup plus data suffix before overwriting
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22/tmp/tmpchi
-rw-r--r--. 1 root root 0 Oct 7 15:28 Tmpchi
-rw-rw-r--. 1 cmx CMX 0 Oct 7 15:22 tmpchi.~1~

mv: Moving files or renaming file names
"1" mv [OPTION] ... [-T] SOURCE DEST: Move files and change file names
Example:
Move files under the same directory, rename files if files exist
MV Tmpchi Tmpchixx
-rw-r--r--. 1 root root 0 Oct 7 14:25 Tmpchi
-rw-r--r--. 1 root root 0 Oct 7 14:25 Tmpchixx
Move files under different directories, move and rename
Mv/tmp/tmpchi01/app/tmpchixx
-rw-r--r--. 1 root root 0 Oct 7 16:07/tmp/tmpchi01
-rw-r--r--. 1 root root 0 Oct 7 14:36/app/tmpchixx

Rename: Renaming multiple files
Rename [OPTIONS] expression replacement file ...
Example:
-rw-r--r--. 1 root root 0 Oct 7 16:15 F1
-rw-r--r--. 1 root root 0 Oct 7 16:15 f2
-rw-r--r--. 1 root root 0 Oct 7 16:15 f3
-rw-r--r--. 1 root root 0 Oct 7 16:15 f4
-rw-r--r--. 1 root root 0 Oct 7 16:15 f5
Rename F f00 f?
-rw-r--r--. 1 root root 0 Oct 7 16:15 f001
-rw-r--r--. 1 root root 0 Oct 7 16:15 f002
-rw-r--r--. 1 root root 0 Oct 7 16:15 f003
-rw-r--r--. 1 root root 0 Oct 7 16:15 f004
-rw-r--r--. 1 root root 0 Oct 7 16:15 f005

RM: Deleting files or directories
"1" rm-i: Prompt before deletion
Example:
Rm-i Tmpchi
Rm:remove Regular empty file tmpchi‘?<br/>【2】rm -r:递归删除目录<br/>示例:<br/>cp -r /tmp/gconfd-root /app<br/>drwx------. 2 root root 4096 Oct 7 16:23 gconfd-root<br/>rm gconfd-root<br/>rm: cannot remove Gconfd-root ': is a directory
Rm-r Gconfd-root
Rm:descend into directory ' Gconfd-root '?
Enter Y to delete the directory

mkdir: Creating a Folder
"1" mkdir-p: Create subdirectories under directory containing directory
Example:
Mkdir-p Mylinux
Drwxr-xr-x. 2 root root 4096 Oct 7 16:29 Mylinux
"2" Mkdir-m: Creating a directory is directly specifying permissions
Mkdir-m mylinux: Permissions set to file Master readable, write, execute, the same group of users can read and execute, other users do not have access to
Drwxr-x---. 2 root root 4096 Oct 7 16:35 Mylinux
"3" MKDIR-V: Show Details
Example:
Mkdir-v Mylinux
mkdir:created directory ' Mylinux '

2. Bash's work characteristics the command execution status return value and command-line expansion are involved in the content and its example demonstration
"1" feature
alias Command alias: Defines the alias name, which is equivalent to executing the command VALUE alias name= ' value '
History Command History:
-C: Empty command history
-D 5: Delete the 5th command specified in history
-A: Attach all the commands in memory to the disk command file (. bash_history)
-r: Attach all commands in the disk command file to memory history
-N: Append the new command in the disk command file to memory history
-P: Expand the History command parameter into multiple lines (Execute command But history command does not record)
-S: Expands the history command parameter into one line (can forge the command without executing the command, history-s "RM/")
echo Display character: Echo will send the input string to standard output. The output string is separated by white space characters, and the line number is added at the end,
$ () or ' parameters to print the output of one command to another
Example:
[[email protected]/]# echo "Hello Welcome to $ (hostname)"
Hello Welcome to CENTOS6.CMX
Tab key: Command completion, PATH completion
Command 2Tab all subcommands or file completion
Example:
[[email protected]/]# He double-click the TAB key
Head Help Hexdump
./2tab Show all directories below the root directory, including hidden directories
Example:
[Email protected]/]#.
app/dev/lib64/mnt/root/sys/
bin/etc/lost+found/net/sbin/tmp/
boot/home/media/opt/selinux/usr/
. dbus/lib/misc/proc/srv/var/
2Tab current directory subdirectories, excluding hidden directories
Example:
[Email protected]/]#

App etc lost+found Net Sbin tmp
Bin home media opt SELinux usr
Boot lib misc proc srv var
Dev lib64 mnt Root sys
~2tab List of all users
Example:
[Email protected]/]# ~
~abrt/~games/~nobody/~saslauth
~adm ~gdm/~ntp/~shutdown/
~apache/~gopher ~operator/~sshd/
~AVAHI-AUTOIPD ~haldaemon/~postfix/~sync/
~bin/~halt/~pulse ~tcpdump/
~cmx/~lp/~root/~usbmuxd/
~daemon/~mail/~rpc ~UUCP
~dbus/~mysql/~rpcuser/~vcsa/
~ftp ~nfsnobody/~rtkit/
Bash shortcut keys
Ctrl+l=clear: Clear Screen
Ctrl+s: Block Screen output
Ctrl+q: Allow screen output
CTRL + C: Close the current run window
Atl+r: Delete the current entire row
Echo (atl+a) 1000: Output 1000 A
Ctrl + u: Delete from cursor to beginning of command
Ctrl + K: delete from cursor to end of command line
Ctrl + A: The cursor moves to the beginning of the command, which is equivalent to home
Ctrl + E: Cursor moves to the end of the command line, equivalent to end
Ctrl + W: Delete left to the beginning of the word from the cursor
Alt + D: Delete right from cursor to end of word
Ctrl + D: Delete a character at the cursor
Ctrl + H: Delete a character before the cursor

  "2" Command execution status return value use a special variable $ in bash? To save the execution status result of the previous command: 0 for success, 1-255 for failure example: [[[email protected] app] #rm null; echo $?rm:remove regular empty file ' null '? Y0[[email protected] app]# RM null; echo $?rm:cannot remove ' null ': No such file or directory1 ' 3 ' command line expand to some of the symbols that bash can interpret To replace some of the arguments in the command. ~: Expand to the user's home directory; Example: Switch to home directory [[[email protected] app]# CD ~[[email protected] ~]# pwd/root{}: Can host a comma-delimited list, and expand it to multiple paths; Example: Create f01,f02,f03 three files under/tmp/mylinux directory [[email protected]/] #touch/tmp/mylinux/f0{1,2,3}-rw-r--r--. 1 root root 0 Oct 7 16:57 f01-rw-r--r--. 1 root root 0 Oct 7 16:57 f02-rw-r--r--. 1 root root 0 Oct 7 16:57 f03  

3. Use the command line expansion function to complete the following exercise:
(1) to create A/tmp directory: a_c,a_d,b_c,b d
Mkdir/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
MKDIR-P/tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/ Modules,lib64,proc,sbin,sys}

4, what are the file metadata information, what do they mean, and how do I view it? How to modify timestamp information for a file.
Stat file name view meta data (metadata) information:
File:a_c
size:4096 blocks:8 IO block:4096 directory
device:fd00h/ 64768d inode:1048579 links:2
Access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root)
Context:unconfined_u:objec T_r:user_tmp_t:s0
access:2018-10-07 12:01:31.600097235 +0800
modify:2018-10-07 12:01:31.600097235 +0800
change:2018-10-07 12:01:31.600097235 +0800
Three time stamps:
Access time: Access times, atime, read file contents
Modify Time: Modified, Mtime, Change file contents (data)
Change time: CTime, metadata changes
View atime and Mtime,ctime time: Stat file name
Touch-a file name: Change only Atime and CTime (touch-a a_c)
touch-m file name: Change only Mtime and CTime (touch-m a_c)
Touch-t [[CC]YY]MMDDHHMM[.SS]: Specify timestamps for Atime and Mtime (touch-t 201809081112.13 a_c)
Touch-c file name: Refreshes the timestamp of the file if the file already exists, and creates a new file 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?
Command alias: Alias
Defines the alias as if, which is equivalent to executing the command value
Alias if= ' Ifcofig '
Command reference:
Alias pwd= ' ifconfig ': Perform pwd display ifconfig results

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[[:d igit:]] [[: Lower:]] or ls-d/var/l[0-9][[: Lower:]]

7. Displays files or directories that start with any number and end with a non-number in the/etc directory
ls-d/etc/[[:d igit:][^[:d igit:]] or ls-d/etc/[0-9][^0-9]

8, display in/etc directory, start with a non-letter, followed by a letter and any other length of any character file or directory
ls-d/etc/[^[:alpha:]][[:alpha:]] or ls-d/etc/[^a-za-z][a-za-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-05-27-09-32-22
touch/tmp/tfile- date +%Y-%m-%d-%H-%M-%S or touch/tmp/tfile-date +%F-%H-%M-%S

10. Copy all the files or directories in the/etc directory to the/tmp/mytestl directory that begin with P and do not end with a number
Cp-a/etc/p[[: Alpha:]]/tmp/mytest1 or cp/etc/p[^[:d igit:]]/tmp/mytest1

11. Copy all files or directories ending with. d in/etc directory to the/tmp/mytest2 directory
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
Cp-a/etc/[lmn]*.conf/tmp/mytest3

N33-week 2-Sunflower

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.