Linux Learning Notes (vi) relative and absolute paths, CD commands, creating and deleting directories Mkdir/rmdir, RM commands

Source: Internet
Author: User
Tags touch command

I. Absolute path and relative path

    • Absolute path

For example, the command to modify the NIC configuration file

Vi/etc/sysconfig/network-scripts/ifcfg-ens33

Over here

/etc/sysconfig/network-scripts/ifcfg-ens33

is the absolute path, the absolute path is from the root directory to the location of the file;

    • Relative path

such as execution

cd/etc/

And then enter

CD Sysconfig

Path Sysconfig is relative to, etc folder, which is the relative path (as opposed to the current folder path)

Second, CD command

    • The CD command is entered into a folder that has been used,

cd/etc/

is entered in the ETC directory;

    • CD-

To enter the last directory in which it was located

For example: The directory where I am now is/etc/sysconfig

Enter the CD at this time-

The ETC directory is returned

Enter the CD again-

and returned to the/etc/sysconfig directory.

    • CD ~

Returns to the user's home directory, as with the individual CD parameter results

Execute CD here ~

Re-enter PWD to view the current directory

Now you can see that the directory is/root

    • Cd..

This command is returned to the previous level directory,

Like in.

/etc/sysconfig

Input

Cd..

Then enter PWD to view the current directory

At this time, you can see that the current directory is, etc

CD again:

The root directory is returned.

Enter the man CD to see the specific usage of the CD

Iii. Creating and deleting catalogs Mkdir/rmdir

    • Create a Directory

mkdir command to create a directory

For example

Mkdir/tmp/123

The/tmp/123 directory is created at this time;

mkdir/tmp/123/456/789 this time error, 456 directory does not exist, that is, the mkdir command can not cascade Create folder execution Mkdir-p/tmp/123/456/789 The directory/tmp/123/456/789 is created,- The P option is to cascade the creation of the directory
    • Delete Directory

The rmdir command is used to delete directories and can only be used to delete empty directories, if there are files or subdirectories in the target directory, then the target directory cannot be deleted, RMDIR-P can cascade delete directory, if the directory is empty

Like I do.

Rmdir-p/tmp/123/456/789

This will show that the TMP directory cannot be deleted because the TMP directory has other files in addition to the 123 directory, and the directory/123/456/789,/123/456,/123 have been deleted.

Four, RM command

RM commands can be used to delete files and directories

For example, I first create a directory

Mkdir-p/tmp/123/456/789

And then create a text

Touch/tmp/123/456/789/123.txt

Perform

Rm/tmp/123/456/789/123.txt

Will ask whether to delete the normal empty file/tmp/123/456/789/123.txt Enter Y for Yes, delete the file;

rm/tmp/123/456/789

This will show that/tmp/123/456/789 is a directory that cannot be deleted,

Create txt text again

Touch/tmp/123/456/789/123.txt

After RM, add-R

Rm-r/tmp/123/456/789

Need to press several times Y, more trouble, at this time after R plus an F

Input

rm-rf/tmp/123/456/789

The directory and its files are deleted successfully


V. Supplementary knowledge

    • When you create or delete a file, the v command after-R or-p displays the command execution process, such as

rm-rfv/tmp/123/456/789

    • History related commands

Enter history to see the most recently entered commands

Input! Touch can quickly enter the last touch command executed,



Linux Learning Notes (vi) relative and absolute paths, CD commands, creating and deleting directories Mkdir/rmdir, RM commands

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.