Marco the second week of operation of the 3rd phase of operation

Source: Internet
Author: User
Tags touch command

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

CP [option] SRC ... DEST

SRC is a single file:

If Dest does not exist, a new dest is created and the content in Src is populated into dest

If dest exists:

If Dest is a file, the content in SRC is overwritten in dest

If Dest is a directory, copy src to dest and keep the original

SRC is multiple files:

Dest must be a directory and exist, other situations will be wrong

SRC is the directory:

Recursive replication using the-R option

If Dest does not exist, create a new dest directory and copy the contents of SRC to dest

If dest exists:

If Dest is a file, an error will be

If Dest is a directory, copy the SRC directory to the dest directory

Common options:

-P: Equivalent to--preserve=mode,ownership,timestamps, reserved permissions, owner, time, etc.

-D: Equivalent to--no-dereference--perserv-links Copy the symbolic link file itself instead of the target file it points to

-A: Equivalent to-DR--preserve=all, archive, retain all the original attributes

-I: Interactive option to perform dangerous actions will ask the user

-f:--force, Enforcement

-r-r: Recursive replication

-V: Show more information

Example:

[Email protected] tmp]# cp/tmp/passwd/tmp/test

[Email protected] tmp]# cp-a/TMP/DIR1/TMP/DIR2

Mobile: MV

MV [option] SRC ... DEST

SRC is a single file:

If the dest does not exist, move the SRC and rename it to Dest

If dest exists:

If Dest is a file, overwrite the content in src to dest and delete the SRC

If Dest is a directory, move SRC to dest and keep the original

SRC is the directory:

Dest must be a directory

If the dest does not exist, move the SRC and rename it to Dest

If dest exists, move the SRC directory to the dest directory

Common options:

-I: Interactive options

-f:--force, Enforcement

Example:

[Email protected] tmp]# MV Test./dir1

[Email protected] tmp]# Mv/tmp/dir1/test/tmp/test2

Delete: RM

RM [option] ... FILE ...

-R recursion, delete directory

-F Force Execution

-I: Interactive options

--no-preserve-root Force Delete/

Example:

[Email protected] tmp]# rm-f test2

[Email protected] tmp]# RM-RF Dir1

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) Bash command execution status return value use Special variable $? Save

0, success

1: Failure

echo $? Show Execution status

(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

For example:/tmp/{a,b} =/tmp/a,/tmp/b

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

(1), create/tmp directory: A_c, A_d, B_c, B_d

TOUCH/TMP/{A,B}_{C,D}

(2), create the/tmp/mylinux directory:

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}

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.

The metadata for a file is used to log many information about a file, such as

Size: Sizes,

Device: The location of the file

Uid: Owner,

Gid: The group that belongs to,

Blocks: Block Size,

Links: Link Quantity

Time stamp:

Access: Accessing Time

Modify: Modification Time,

Change: Changing Time

Wait a minute

Meta Data View: Stat command

To modify the timestamp of a file, use the Touch command:

Format: touch[option] ... FILE ...

Parameters:

-A: Change only atime (Access time)

-M: Change only Mtime (Modify time)

-T STAMP: specifying TIME modifications

[[Cc]yy] MMDDHHMM[.SS]

-C: Not created if the file does not exist.

Note:touch file, the file is created by default 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?

(1) Alias

Displays all command aliases available in the current shell process

(2) Alias Name= ' VALUE '

Defines the name of the alias, which is equivalent to executing the command value

Attention:

After the definition is only valid for the current shell process, want to be permanently effective, to be defined in the configuration file;

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.

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.

Mkdir/tmp/mytest1&&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.

Mkdir/tmp/mytest2&&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.

Mkdir/tmp/mytest3&&cp-a/etc/[l,m,n]*.conf/tmp/mytest3


Marco the second week of operation of the 3rd phase of operation

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.