Linux commands one of the Learning Notes directory and file basic operations

Source: Internet
Author: User
Tags file copy

Directory Operations

CD: Enter directory

Basic format: CD directory name

Example:

1), in the current directory into the subdirectory A, enter "CD a"

2), in the current directory into the root directory of the subdirectory TMP, enter "Cd/tmp"


Cd.. : Returns to the top level directory

Basic format: CD.

Example: Current directory/tmp/sa/eet

1), return to the previous level directory, enter "CD."

2), return to the TMP directory, enter "CD." /..”


LS: Displays files and subdirectories in the directory

Basic format: LS [-optional]

Example: Current directory/tmp

1), display the files and directories in the current directory, enter "LS"

2), display files and directories in the/home directory, enter "Ls/home"


PWD: Show directory full path information

Basic format: PWD


mkdir: Creating a new Directory

Basic format: mkdir directory Name

Example: Current directory/tmp/sa/eet

1), create a directory named ABC in the current directory, enter "mkdir ABC"

2), create a directory named group1 in the root directory, and enter "Mkdir/group1"

3), create such a set of directories under the current directory group/user/id, enter "Mkdir-p group/user/id"

4), create such a set of directories under the root directory/ie/temp/hi, enter "Mkdir-p/ie/temp/hi"


MV: Renaming and moving directories

Basic format:

Rename: MV old directory name new directory name

Move: The path of the directory to which the MV moves

Example: Current directory/Home

1), rename directory AAA to BBB, enter "MV AAA BBB"

2), move the current directory AAA directory to the root directory, enter "MV AAA/"

3), move the a_1 directory under the root directory to the current directory, enter "Mv/a_1/home"


Cp-r: Copy Directory

Basic format: Cp-r the directory name after the copy of the directory name to be copied

Example: Current directory/Home

1), the current directory named ABC directory copy, and named CBA, enter "CP-R ABC CBA"

2), copy the current directory named ABC directory to the/tmp directory, the copied name is still ABC,

Enter "Cp-r abc/tmp"

3), copy the current directory named ABC directory to the/tmp directory, and rename it to CBA,

Enter "Cp-r ABC/TMP/CBA"

4), copy the CBA directory in the/tmp directory to the current directory, after the name is still CBA,

Enter "Cp-r/tmp/cba/home"

5), copy the CBA directory under the/tmp directory to the current directory, and rename it to ABC,

Enter "Cp-r/tmp/cba/home/abc"


RM-R: Deleting a directory

Basic format: Rm-r the name of the directory to delete

Example: Current directory/Home

1), delete the directory named ABC under the current directory, and enter "RM-R ABC".

If the directory to be deleted is an empty directory, it will be deleted directly;

If the deleted directory is not empty, you will be prompted "rm:descend into directory ' abc '?", as long as

Enter "Y".

2), delete the AAA directory under the/tmp directory, enter "Rm-r/tmp/aaa"


RM-RF: Forcibly deleting a directory

Basic format: RM-RF the name of the directory to delete

Note: Use this command without any hint, you must confirm the path before use, so as to avoid accidental deletion of the damage


File operations

Touch: Create a new file

Basic format: Touch file name

Example: Current directory/Home

1), create a file named Big in the current directory, enter "Touch Big"

2), create a file named Small in the root directory, enter "Touch/small"

3), create a file named Middle in the/tmp directory, enter "Touch/tmp/middle"


CP: Copying files

Basic format: CP old filename New file name

Example: Current directory/Home

1), the current directory will be named big file copy, and renamed to Bigger, enter "CP big bigger"

2), copy the file named big in the current directory to the/tmp directory, the file name is still big,

Enter "CP Big/tmp/big"

3), copy the file named small in the current directory to the/tmp directory, and rename it to smaller,

Enter "CP Small/tmp/smaller"

4), copy a file named middle in/tmp directory to/usr, the file name is still middle,

Enter "Cp/tmp/middle/usr/middle"

5), copy a file named list in the/tmp directory to/usr and rename it to List.bak.

Enter "Cp/tmp/list/usr/list.bak"


RM: Deleting files

Basic format: RM file name

Example: Current directory/Home

1), the file named same in the current directory, enter "RM Same",

Return to the prompt "Rm:remove regular empty file ' same '?", enter "Y" after the prompt

2), delete the file named Tnsname.bak in the/tmp directory, enter "Rm/tmp/tnsname.bak",

Return back with the hint "rm:remove regular empty file ' Tnsname.bak '?",

Enter "Y" after the prompt


RM-RF: Forcing files to be deleted

Basic format: RM-RF file name

Note: Use this command without any hint, you must confirm the path before use, so as to avoid accidental deletion of the damage


MV: Renaming and moving files

Basic format:

Rename: mv old filename New file name

Move: The path of the file names to be moved by the MV

Example: Current directory/Home

1), rename the file named Sam in the current directory as Sam.bak, enter "MV Sam Sam.bak"

2), move the file named Sam in the current directory to the/tmp directory, the file name is still Sam,

Enter "MV Sam/tmp"

3), move the file named Sam in the current directory to the/tmp directory, and rename it to Sam.bak,

Enter "MV Sam/tmp/sam.bak"

4), move the file named Test in the/tmp directory to the/usr directory, the file name is still test,

Enter "MV/TMP/TEST/USR"

5), move the file named Test in the/usr directory to the/tmp directory, and rename it to Test.bak,

Enter "Mv/usr/test/tmp/test.bak"


Cat: View File contents

Basic format: Cat file name

Example: Current directory/Home

1), view the file named GIF in the current directory, enter "Cat gif"

2), view the file named Hill in the/tmp directory, enter "Cat Hill"


Head-n: Viewing the contents of the top n rows of a file

Basic format: Head-n file name

Example: Current directory/Home

1), view the contents of the first 10 lines of the file named GIF in the current directory, enter "Head-10 gif"

2), view the contents of the first 2 lines of the file named Hill in the/tmp directory, enter "Head-2 Hill"


Tail-n: Viewing the contents of n rows after a file

Basic format: Tail-n file name

Example: Current directory/Home

1), view the contents of the 10 lines after the file named GIF in the current directory, enter "Tail-10 gif"

2), view the contents of the 2 rows of the file named Hill in the/tmp directory, enter "Tail-2 Hill"


Tail-f: Real-time monitoring of file changes

Basic format: Tail-f file name


MORE: Paging backward to view the contents of a file

Basic format: More file name

Note: Use this command to view only the contents of the file backwards, paging backward by pressing the SPACEBAR


Less: Paging forward and backward to view file contents

Basic format: Less file name

Note: Use this command to page back and press the up and down arrows


===========================================================================================

This article is only for my study notes, a lot of command usage is not complete

PS: If there are errors or omissions in this article, please correct

Linux commands one of the Learning Notes directory and file basic operations

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.