Linux Basics: 7, Basic Command Introduction (2)

Source: Internet
Author: User

Directory-related commands)


Mkdir

Role: Make directories Create directory

Syntax: mkdir [options] Directory name

Options:

-P Cascade Create directory if the target directory already exists without error

================================================================================== #1, directory files and ordinary files in the same directory are not duplicate, Because directory files and plain files are considered files under Linux [[Email protected] ~]# ls -l test1-rw-r--r--.  1  Root root 60 mar  4 23:17 test1[[email protected] ~]# mkdir  test1mkdir: cannot create directory  ' test1 ': Use of  file exists2,-p parameters [[email  protected] ~]# mkdir aa/bb/ccmkdir: cannot create directory  ' aa/bb/cc ': no such file or directory[[email protected] ~]# mkdir -p  aa/bb/cc                # Plus-P parameter creation succeeded [[email protected] ~]# tree aa                           # Tree command, look at the directory structure AA└── BB&NBsp;   └── cc2directories, 0 files[[email protected] ~]# ls - Ld aadrwxr-xr-x. 3 root root 4096 mar  5 02:44 aa[[email The  PROTECTED] ~]# MKDIR -P AA#AA directory already exists, but adding-P will not error the directory duplication and will not change the contents and properties of the AA directory ================= =================================================================

Rm

Function: Remove files or directories delete file

Syntax: RM [options] File name

Options:

-R recursive recursive delete directory file and its contents

-F force is forced to delete without prompting the user, even if the file does not exist

=================================================================================== #1,-r option [[email  Protected] ~]# ls ./dir1text1[[email protected] ~]# rm dir1rm: cannot  remove  ' Dir1 ': is a directory       #rm不加-r option cannot delete catalog file [[ email protected] ~]# rm -r dir1rm: descend into directory  ' Dir1 '?  yrm: remove regular empty file  ' Dir1/text1 '? yrm: remove  directory  ' Dir1 '?  y#2,-f option [[email protected] ~]# ls dir2test2[[email  protected] ~]# rm -rf dir2                     #并不会做任何提示, directly delete [[Email protected] ~]# ls  badls: cannot access bad: No such file or directory[[email  Protected] ~]# rm -f bad                       #bad文件并不存在, plus-f option will not prompt ================================================================ ===================



Cp

Role: Copy files and directories copying a file

Syntax: CP [option] source file/directory destination file/directory

Options:

-R Recursive replication directory and its contents

-P preserves file timestamp, owner, permission, and other information

================================================================================== #1,-r option [[email  Protected] ~]# ls -l dir3total 0-rw-r--r--.  1 root root 0  mar  5 04:34 test3[[email protected] ~]# cp dir3 dir4cp:  omitting directory  ' Dir3 ' [[Email protected] ~]# cp -r dir3 dir4[[email  protected] ~]# ls -l dir4total 0-rw-r--r--.  1 root root 0  Mar  5 04:35 test3       #可以看出来test3文件的时间戳改变了 # #,-P option [[ EMAIL PROTECTED] HOME]# LL /HOMETOTAL 4DRWX------.  2 nagios nagios  4096 mar  4 04:36 nagios[[email protected] home]# cp -rp  /HOME/NAGIOS /TMP/[[EMAIL PROTECTED] HOME]# LL -D /TMP/NAGIOSDRWX------.  2 nagios nagios 4096 mar  4 04:36 /tmp/nagios   #保留了属主, group, time and authority =========================== =======================================================


Mv

Action: Move (rename) files moving (renaming) file

Syntax: MV [options] source file/directory destination file/directory

Options:

-F force does not prompt when overwriting files

========================================================================= =========== #1,-f options [[Email protected] dir4]# ll test*-rw-r--r--.  1 root root  0 mar  5 04:35 test3-rw-r--r--.  1 root root 0 mar   5 04:53 test4[[email protected] dir4]# mv test3 test4mv:  overwrite  ' test4 '? n                       #因为test4已存在, so you will be prompted to overwrite [[email protected] dir4]#  Mv -f test3 test4[[email protected] dir4]# ll test*-rw-r--r--.  1  root root 0 mar  5 04:35 test4  #查看结果, Test4 has been overwritten ======================== ============================================================


Document commands)


Touch

Action: You can modify the file time parameter and create it when the touch target file does not exist.

Syntax: Touch filename

PS: Time parameter contains

Atime:accesstime access time;

Mtime:modifytime Modify content time;

Ctime:changetime changing the file permission time

=============================================================================== #1, modify time parameters [[email protected ] ~]# stat test11        #查看test11文件的状态信息   file:   ' test11 '   Size: 3                blocks: 8          io block:  4096   regular filedevice: 802h/2050d      inode:  12121       Links: 1Access:  (0644/-rw-r--r--)    uid:  (    0/    root)    Gid:  (     0/    root) Access: 2015-03-05 04:44:01.088979285 +0800modify:  2015-03-05 04:43:53.537979166 +0800change: 2015-03-05 04:43:53.537979166 +0800[ [EMAIL PROTECTED]&Nbsp;~]# touch test11       #touch一下 [[email protected] ~]#  stat test11        #再看一下, found three time changes   File:  ' test11 '   Size: 3                Blocks: 8          IO Block: 4096    regular filedevice: 802h/2050d      inode: 12121        Links: 1Access:  (0644/-rw-r--r--)   Uid:  (     0/    root)    Gid:  (    0/     root) access: 2015-03-05 05:26:11.701977204 +0800modify: 2015-03-05  05:26:11.701977204 +0800change: 2015-03-05 05:26:11.701977204 +0800#2, create a regular file [email  protected] ~]# ll test*-rw-r--r--.  1 root root 3 Mar  5 05:26  Test11-rw-r--r--.  1 root root 6 Mar  5 04:44 test22[[email  Protected] ~]# touch test33[[email protected] ~]# ll test*-rw-r--r--.   1 root root 3 mar  5 05:26 test11-rw-r--r--.  1 root  Root 6 mar  5 04:44 test22-rw-r--r--.  1 root root 0 mar   5 05:28 test33========================================================================== ======

Cat

Function: View the contents of the document and output it in the terminal interface

Syntax: Cat filename

PS: You can enter characters that are hit on the keyboard by using cat > File

================================================================================[[email protected] ~]# cat > Test22hahahahagood #按下ctrl +d Exit [[email protected] ~]# cat test22hahahahagood===================== ===========================================================

Tac

Effect: The content order of the cat output is reversed

Syntax: TAC filename

More

Function: Split screen output document content, can page down to view.

Syntax: more filename

How to operate: press the SPACEBAR to turn the screen down

Less

Function: Split screen output document content, you can page up or down to view the line.

Syntax: less filename

Operation mode:

Press the SPACEBAR to turn the screen down;

Press up and down arrows to turn the line;

Press J, move down one line, press K, and move up one line;

Press CTRL+F, PAGE down;

Press CTRL+B, PAGE up;

Press Shift+g to go to the top of the document;

Press Shift+g to go to the bottom of the document.

Head

Function: Standard output document header n rows

Syntax: head [options] filename

Options:

-N Outputs the header of the document in rows (e.g. head-n number of rows Filename/head-number of rows filename)

PS: Without the-n parameter, the default output is the first 10 lines.

Tail

Function: standard output document trailing n rows

Syntax: tail [options] filename

Options:

-N Outputs the header of the document in rows (e.g. tail-n number of rows Filename/tail-number of rows filename)

-F Dynamic Display (when viewing a document, the output of the tail changes dynamically if the document content changes)

-F adds a-retry to the-f base, not commonly used.

PS: Without the-n parameter, the default output after 10 lines.


This article is from the "30 Demon People" blog, please make sure to keep this source http://301ren.blog.51cto.com/8887653/1617374

Linux Basics: 7, Basic Command Introduction (2)

Related Article

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.