Second week homework

Source: Internet
Author: User

1. What are the file management commands on Linux, their commonly used methods and their related examples?

The File Management Class command on Linux has copy CP, delete rm, move MV

How to use:

# CP source file or directory destination file or directory

When the source is a file

If the target does not exist, the target file is created and the contents of the source file are populated into the target file;

If the target is a file, the content of the source file is overwritten into the source file;

If the target is a directory, create a new file with the same name as the source file in the destination directory and populate the contents of the source file with the new file

When the source is multi-file, the target must exist, and the directory, the other situation will be error;

When the source is a directory

If the target does not exist, just create the specified directory, copy all the files in the source directory to the target directory;

If the target exists as a file, then an error, such as a directory, such as copying all the files in the source directory to the target directory;

Common options:

-I: Interactive

-R,-r: recursively copy directories and all internal content;

-A: Archive, equivalent to-DR--preserv=all

-P:--preserv=mode,ownership,timestamp

-V:--verbose

Example:

Cp-r/etc/rc.local//tmp/rc/

Cp-a/etc/*.d/tmp/etc


# rm Target File

Common options:

-I: Interactive

-F: Force delete

-R: Recursive

Example:

Rm/tmp/etc/rc.d

Rm-r/tmp/rc/


# MV Move File

Common options:

-I: Interactive

-F: Mandatory

-R: Recursive

Example:

mv/tmp/etc/1.txt/tmp/rc/


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. Execution result status of the command

Success

Failed

Bash uses a special variable $? Save the execution status result of the most recent command;

0: Success

1-255: Failure

2. Command line expansion

~: Expand to the user's home directory

~username: Expand the home directory for the specified user

{}: Can host a comma-delimited list and expand it to multiple paths

Example:

/tmp/{a,b} =/tmp/a,/tmp/b

/tmp/{tom,jerry}/hi =/tmp/tom/hi,/tmp/jerry/hi


3. Use the command line expansion function to complete the following exercises:

(1), create/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

├──tmp

├──usr

│└──local

│├──bin

│└──sbin

└──var

├──lock

├──log

└──run

Mkdir-p/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}


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.

File metadata information has file type, access rights, hard links, file belongs to the main group, file size, timestamp, etc.

The metadata information for the File View command is stat

The command to modify timestamp information for a file is touch where-a modifies the access time,-M modifies the modified time


5, how to define the alias of a command, how to reference the execution result of another command in the command?

The command that defines the alias of a command is the alias command format alias name= ' value ', which defines the alias name, which is equivalent to executing the command VALUE;

The execution result of another command referenced in the command is by using the Pipe command |, the command format is COMMAND1 | COMMAND2 The results of COMMAND2 execution as COMMAND1 input.


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*[0-9]*[[:lower:]


7. Displays files or directories that start with any number in the/etc directory and end with a non-numeric number.

# ls-d/etc/[0-9]*[^0-9]


8, Show/etc directory, start with a non-letter, followed by a letter and any other arbitrary length of any character file or directory.

# ls-d/etc/[^[:alpha:]][[:alpha:]]*


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.

#cd/tmp;touch tfile-' Date +%f-%h-%m-%s '


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.

# 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.

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


Second week homework

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.