Linux Basic Learning Four

Source: Internet
Author: User

This time continue to learn Linux basic commands, including stat, touch, CP, MV, RM, tree, mkdir, rmdir

Stat

Command format

Stat [OPTION] ... FILE ...

Command function

Displays the timestamp of the file, i.e. access time, modification time, and change time

Stat [OPTION] ... FILE ...

     [[email protected] ~]# stat newfile       File:  ' NewFile '      Size: 0          blocks: 0          io block:  4096   regular empty file     device: 802h/ 2050dinode: 659584      links: 1     access:   (0644/-rw-r--r--)   Uid:  (    0/    root)     Gid:  (    0/    root)       access: 2016-07-28 10:21:00.272976560 +0800     modify:  2016-07-28 10:21:00.272976560 +0800     change: 2016-07-28  10:21:00.272976560 +0800

Touch

Command format

Touch [OPTION] ... FILE ...

Command function

Change the timestamp of the file

[OPTION]

-A: Sync only atime and CTime

    [[email protected] ~]# touch -a newfile      [[email protected] ~]# stat newfile     File:  ' NewFile '     size: 0         blocks:  0          IO Block: 4096    regular empty file    device: 802h/2050dinode: 659584       Links: 1    Access:  (0644/-rw-r--r--)   uid:   (    0/    root)    Gid:  (     0/    root)     access: 2016-07-28 11:17:31.718974393  +0800    Modify: 2016-07-28 11:17:00.607975533 +0800     change: 2016-07-28 11:17:31.718974393 +0800 

-M: Sync only Mtime and CTime

-T: Use [[CC]YY]MMDDHHMM[.SS] To change the file's Atime and Mtime, if used with-a, change only atime. Can create some illusion of access

     [[email protected] ~]# touch -at 201601011200.30  Newfile          [[email protected] ~]# stat  newfile      File:  ' NewFile '      Size:  0         blocks: 0           IO Block: 4096   regular empty file      device: 802h/2050dinode: 659584      links: 1      Access:  (0644/-rw-r--r--)   Uid:  (    0/     root)    Gid:  (    0/     Root)      Access: 2016-01-01 12:00:30.000000000 +0800      Modify: 2016-07-28 11:17:00.607975533 +0800     change: 2016-07-28  11:20:09.986975310 +0800

-C: If the file does not exist, it is not created

Cp

Command format

CP [OPTION] ... SOURCE ... DIRECTORY

Command function

Copy a file or directory to a specified destination

[OPTION]

-I,--interactive: Interactive replication

-R,-r: recursively replicate directories and all internal content

-v,--verbose: Show Details of replication

-A: Archive all properties of replication resources, often used for file backups

--preserv[=attr_list]: Specifies its attributes when copying resources, including

Mode: Permissions

Ownership: Belong to the main group

Timestamp

Links

Xattr

Context

Note: When copying resources, there are two cases of error

1. Copy multiple files to a folder that is not a directory

2. The copy directory is not using the-R

Attention:

When you copy a file to a file that is not created, you create a new file, the data does not change

When copying files to a directory, create a file with the same name, the data is unchanged

When you copy a directory to a directory that is not created, create a new directory and the data is unchanged

Mv

Command format

MV [OPTION] ... SOURCE ... DIRECTORY

Command function

Move files without preserving the original file

[OPTION]

-i,--interactive: Moving files interactively

Note the same as CP, but change the file name when moving files in the same directory

[email protected] testdir]# Touch FILE1 [[email protected] testdir]# ls FILE1 [[email protected] testdir]# MV FILE1 FILE2 [[email protected] testdir]# ls FILE2

Rm

Command format

RM [OPTION] ... FILE ...

Command function

Delete files or directories

[OPTION]

-i,--interactive: Interactively Delete data

-R,-R,--recursive: recursively delete data

-F: Force delete data

--no-preserve-root: With this command, you can delete root.

     [[email protected] ~]# rm -rf /          rm: it is dangerous to operate recursively on   '/'      rm: use --no-preserve-root to override this  failsafe     [[email protected] ~]# rm -rf / -- no-preserve-root     rm: cannot remove  '/media/Packages/ yum-plugin-tmprepo-1.1.31-34.el7.noarch.rpm ': r     ead-only file  system     rm: cannot remove  '/media/packages/ yum-plugin-show-leaves-1.1.31-34.el7.noarch.rpm       ':  Read-only file  system     rm: cannot remove  '/media/packages/ Yum-plugin-rpm-warm-cache-1.1.31-34.el7.noarch.r    &nbSP;PM ': read-only file system     rm: cannot remove  '/ media/packages/yum-plugin-remove-with-leaves-1.1.31-34.el7.noar     ch.rpm ':  Read-only file system

Special Friendship Tips: Dangerous operation, do not model!

Tree

Command format

tree [OPTION] [FILE] ...

Command function

List the contents of a directory tree

[OPTION]

-D: Show only directories

-L Level: Specifies the number of levels to display

Mkdir

Command format

mkdir [OPTION] ... DIRECTORY ...

Command function

Create a Directory

[OPTION]

-P: There is no error in the parent directory, you can automatically create the required directories

[Email protected] testdir]# RM-RF./* [[email protected] testdir]# ls [[email protected] testdir]# mkdir 1/2/3 Mkdir:cannot Create directory ' 1/2/3 ': No such file or directory [[email protected] testdir]# MKDIR-PV 1/2/3 m kdir:created directory ' 1 ' mkdir:created directory ' mkdir:created directory ' 1/2/3 '

-V: Show more information

-M MODE: Specify permissions directly when creating a directory

RmDir

Command format

rmdir [OPTION] ... DIRECTORY ...

Command function

Delete Empty Directory

[OPTION]

-P: Recursive deletion of the parent empty directory

-V: Show more information



This article is from the "dmwing" blog, make sure to keep this source http://dmwing.blog.51cto.com/11607397/1831621

Linux Basic Learning Four

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.