Relative and absolute paths of linux knowledge point Review, linux knowledge point

Source: Internet
Author: User
Tags touch command

Relative and absolute paths of linux knowledge point Review, linux knowledge point
2.6 relative and absolute paths

Each file has a file starting from the root. All files have their own paths starting from the root. They are absolute paths, no matter which directory you are in, you can use the path to find the file path. The absolute path is not started by the root. Relative to the path in your location, it is called the relative path, which is relative to the current directory.

[Root @ aminglinux-01 ~] # Pwd view the current path/root [root @ aminglinux-01 ~] # Ls. ssh/authorized_keys this is the relative path, relative to root. ssh/authorized_keys [root @ aminglinux-01 ~] # Cd/etc/sysconfig [root @ aminglinux-01 sysconfig] # ls network-scripts/ifcfg-eno16777736 this is also a relative path, relative to/etc/sysconfignetwork-scripts/ifcfg-eno16777736 [root @ aminglinux-01 sysconfig] # pwd/etc/sysconfig
Cd is equal to change directory pwd to view the current path, where is the directory where the 2.7 cd command

Cd equalsChange directory

Cd command-parameter, "cd-" Enter the last directory, only enter "cd", enter the user's current home directory, that is, the user's home directory when logging on to the system ~ Parameter, "cd ~ "Indicates to switch to the user's home directory, which is equal to the cd command... parameter." cd... "indicates to switch to the upper directory and return the result step by step.
Cd-

The cd-command indicates where your last directory was.

[root@hf-01 ~]# cd /etc/sysconfig[root@hf-01 sysconfig]# cd -/root[root@hf-01 ~]# cd -/etc/sysconfig[root@hf-01 sysconfig]# pwd/etc/sysconfig[root@hf-01 sysconfig]# cd -/root[root@hf-01 ~]# pwd/root[root@hf-01 ~]# cd -/etc/sysconfig[root@hf-01 sysconfig]# pwd/etc/sysconfig
Cd and cd ~

Cd and cd ~ All commands are returned to the user's home directory.

[Root @ hf-01 sysconfig] # cd [root @ hf-01 ~] # Cd/tmp/[root @ hf-01 tmp] # cd [root @ hf-01 ~] # Pwd/root [root @ hf-01 ~] # Cd ~ This ~ Indicates/root
Cd ..

Cd... command to return to the upper directory

[Root @ hf-01 ~] # Cd .. the returned is the root directory, and the [root @ hf-01/] # cd .. [root @ hf-01/] # cd/etc/sysconfig/network-scripts/[root @ hf-01 network-scripts] # pwd/etc/sysconfig/network-scripts [root @ hf-01 network -scripts] # cd .. [root @ hf-01 sysconfig] # pwd/etc/sysconfig [root @ hf-01 sysconfig] # cd .. here we will see step by step back to the upper directory [root @ hf-01 etc] # pwd/etc [root @ hf-01 etc] # cd .. [root @ hf-01/] # pwd/

To view other cd usage, you can use man cd to view all cd usage.

2.8 create and delete the directory mkdir/rmdirmkdir

Mkdir = make directory

Date display current time

Mkdir-p allows you to create a directory-v in a cascading manner to visualize command execution.

When creating a directory, you must pay attention to the absolute path and relative path. The current directory generally uses the relative path, that is, the beginning of the/symbol.

[Root @ hf-01 ~] # Mkdir/tmp/aminglinux [root @ hf-01 ~] # Ls-ld/tmp/aminglinux/drwxr-xr-x. 2 root 6 October 24 05:58/tmp/aminglinux/[root @ hf-01 ~] # Date shows the current time on Tuesday October 24, 2017 05:59:00 CST [root @ hf-01 ~] # Mkdir/tmp/aminglinux/1/2/mkdir: the directory "/tmp/aminglinux/1/2/" cannot be created. If there is no file or directory, the directory/tmp contains the/aminglinux directory, and does not exist/1 and/2 Directory [root @ hf-01 ~] # Ls-l/tmp/aminglinux/total usage 0
Mkdir-p

Mkdir-p supports cascading creation of directories

[Root @ hf-01 ~] # Mkdir-p/tmp/aminglinux/1/2/[root @ hf-01 ~] # Ls-l/tmp/aminglinux/total usage 0drwxr-xr-x. 3 root 14 October 24 06:07 1 [root @ hf-01 ~] # Ls-l/tmp/aminglinux/1 total usage 0drwxr-xr-x. 2 root 6 October 24 06:07 2
Mkdir-pv

Mkdir-pv: You can see the visual process of creating a directory.

[Root @ hf-01 ~] # Mkdir-pv/tmp/aminglinux/2/3/4 mkdir: the directory "/tmp/aminglinux/2" mkdir: created "/tmp/aminglinux/2/3" mkdir: created directory "/tmp/aminglinux/2/3/4"
Rmdirrmdir = remove directory rmdir command can delete directories, but only empty directories can be deleted (files in directories cannot be deleted) rmdir-p (parents) can be cascading to delete empty directories, mistaken directory Deletion

In particular, after deleting a specified directory, if the upper-level directory of the directory has become an empty directory, delete it.

If a non-empty directory cannot be deleted, run the tree Command to view the cascading information of the Directory and install the tree package yum install-y tree.

Touch

When using the touch command to create a directory for a blank file, you must note where your directory is. Run the command to view the current position pwd.

[Root @ hf-01 ~] # Rmdir/tmp/aminglinux/2 rmdir: Delete "/tmp/aminglinux/2" failed: the directory is not empty. ** this indicates that rmdir can delete the directory, but the premise is that this directory is empty ** [root @ hf-01 ~] # Rmdir/tmp/aminglinux/2/3/4 then the 4 directory is deleted [root @ hf-01 ~] # Touch/tmp/aminglinux/2/3/1.txt then create a file in the directory [root @ hf-01 ~] # Ls/tmp/aminglinux/2/31.txt[ root @ hf-01 ~] # Tree/tmp/aminglinux/if there is no tree command, then yum install-y tree/tmp/aminglinux/── 1 │ ── 2 └ ── 2 └ ── 3 └ ── 1.txt 4 directories, 1 file [root @ hf-01 ~] # Rmdir/tmp/aminglinux/2/3 rmdir: Delete "/tmp/aminglinux/2/3" failed: the directory is not empty and cannot be deleted, because the directory contains a file [root @ hf-01 ~] # Rmdir/tmp/aminglinux/2/3/1.txt rmdir: Delete "/tmp/aminglinux/2/3/1.txt" failed: Not a directory ** if you do not want to delete it, use the rm command **
Rmdir-p

Rmdir-p (parents) can cascade to delete empty directories.

[Root @ hf-01 ~] # Rmdir-p/tmp/aminglinux/1/2 rmdir: delete directory "/tmp/aminglinux" failed: directory not empty [root @ hf-01 ~] # Tree/tmp/aminglinux/here we will find that the two directories/1/2 have been deleted/tmp/aminglinux/── 2 └ ── 3 └ ── 1.txt 2 directories, 1 file
2.9 rm command

Rmdir has some limitations. Only directories can be deleted, but files cannot be deleted.

Rm = remove

The rm command can delete files and non-empty directories. (If you use the rm command separately, you will be prompted to delete the files.)-f (force) is executed forcibly. Only files can be deleted, directory-r cannot be deleted, which is equivalent to the process of deleting these directories in the-recursive cascade mode. A file exists. The file is deleted first, and then the running result is visualized when the directory-v is deleted, it is recommended that you add the "v" visual result rm-rfv. After adding the "-f" option, if the file or directory does not exist, no prompt will be generated.

HistoryCommand to view the commands used

Use! The command will go to history to execute the last command.

Wildcards. For all examples in the table, rm-rf/tmp/hf/2/3/*. txt deletes all txt files in the directory.

When the man command is used, view a specific character. When searching, add the search character Directly/with a space and press Enter. When you want to exit, press q to exit!

[Root @ hf-01 ~] # Rm/tmp/aminglinux/2/3/1.txt rm: Do you want to delete the common empty file "/tmp/aminglinux/2/3/1.txt "? Y will prompt whether to delete the file here [root @ hf-01 ~] # Tree/tmp/aminglinux // tmp/aminglinux/── 2 ── 32 directories, 0 files [root @ hf-01 ~] # Touch/tmp/aminglinux/2/3/1.txt[ root @ hf-01 ~] # Touch/tmp/aminglinux/2/3/2.txt[ root @ hf-01 ~] # Rm/tmp/aminglinux/2/3/1.txt 2.txt press the tab key twice to list the files in the directory [root @ hf-01 ~] # Rm/tmp/aminglinux/2/3 /*. txt can be directly expressed as rm/tmp/aminglinux/2/3/* rm: Do you want to delete the common empty file "/tmp/aminglinux/2/3/1.txt "? Nrm: Do you want to delete the common empty file "/tmp/aminglinux/2/3/2.txt "? N [root @ hf-01 ~] # Rm-f/tmp/aminglinux/2/3/*. txt if it is too difficult to confirm each deletion, you can add-f (force) force Delete [root @ hf-01 ~] #! Treetree/tmp/aminglinux // tmp/aminglinux/── 2 ── 32 directories, 0 files (! Tree indicates the history command, the last recently executed tree Command) using the tree Command to view, found that the file under the directory has been deleted [root @ hf-01 ~] # Rm-rf/tmp/aminglinux/2 there will be no prompt here, will directly delete the file and directory [root @ hf-01 ~] #! Treetree/tmp/aminglinux // tmp/aminglinux/0 directories, 0 files [root @ hf-01 ~] # Mkdir-pv/tmp/aminglinux/2/3/then join the new directory mkdir visually: the directory "/tmp/aminglinux/2" mkdir: created directory "/tmp/aminglinux/2/3/" [root @ hf-01 ~] # Touch/tmp/aminglinux/2/3/1.txt new file [root @ hf-01 ~] # Touch/tmp/aminglinux/2/2.txt[ root @ hf-01 ~] #! Treetree/tmp/aminglinux // tmp/aminglinux/── 2 ── 2.txt └ ── 3 └ ── 1.txt 2 directories, 2 files [root @ hf-01 ~] # Rm-rfv/tmp/aminglinux/2/3/visualization force Delete deleted directory "/tmp/aminglinux/2/3/1.txt: "/tmp/aminglinux/2/3/" we will find that the files under the directory are deleted, and then in the delete directory [root @ hf-01 ~] #! Treetree/tmp/aminglinux // tmp/aminglinux/── 2 ── 2.txt 1 directory, 1 file [root @ hf-01 ~] # Rm-rfv/tmp/aminglinux/2/3/If you delete a non-existent directory, you will find no prompts. This is because the-f option is added, which indicates that the directory is forcibly deleted, whether or not it exists [root @ hf-01 ~] # Rm-rv/tmp/aminglinux/2/3/when removing-f, you will be prompted that the directory does not exist rm: You cannot delete "/tmp/aminglinux/2/3 /": there is no file or directory

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.