Linux Basics (ii)--File and directory management __linux

Source: Internet
Author: User
Tags create directory mkdir file permissions

We know that the directory structure of Linux is a tree structure, the top-level directory is the root directory/.

Other directories can be added to the tree by mounting them, and they can be removed by lifting the mount.

Before we start this tutorial, we need to know what absolute and relative paths are. Absolute Path:
The path is written by the root directory/write, for example:/usr/share/doc this directory. relative path:
The path is not written by/write, for example, by/usr/share/doc to the bottom of/usr/share/man, it can be written as: CD. /man This is how the relative path is written.

Common commands for working with catalogs

Let's take a look at a few common directory-processing commands: LS: List directory CD: Toggle directory pwd: Display current directory mkdir: Create a new directory rmdir: Delete an empty directory CP: Copy file or directory RM: Remove files or directories

You can use the man [command] to view the various commands using the document, such as: Man CP.

LS (listing directory)

In Linux systems, the LS command may be the most frequently run.

Grammar:

[Root@www ~]# ls [-aadffhilnrrst] directory name
[Root@www ~]# ls [--color={never,auto,always}] Directory name
[Root@www ~]# ls [--full-time] directory name

Options and Parameters:-A: All files, along with the hidden files (the file at the beginning), are listed together (common)-D: Only the directory itself, not the file data in the directory (commonly used)-L: Long data string, including attributes and permissions of the file, etc. (commonly used)

List all the files in the home directory (including attributes and hidden file)

[Root@www ~]# Ls-al ~

CD (Toggle directory)

The CD is the abbreviation for changedirectory, which is the command to transform the working directory.

Grammar:

CD [Relative path or absolute path]

Create w3cschool.cc directory #使用 mkdir command
[root@www ~] #mkdir w3cschool.cc

#使用绝对路径切换到w3cschool. CC Directory
[Root@www ~]# cd/root/w3cschool.cc/

#使用相对路径切换到w3cschool. CC Directory
[Root@www ~]# CD./w3cschool.cc/

# means to return to your home directory, which is/root this directory
[Root@www w3cschool.cc]# CD ~

# means to go to the current top level directory, which is the meaning of the/root directory;
[Root@www ~]# CD ...

The next few more operations should be able to understand the CD command very well.

PWD (Displays the current directory)

PWD is the abbreviation for print workingdirectory, which is the command that displays the current directory.

[Root@www ~]# pwd [P]
Options and Parameters:
-P: Shows the exact path instead of using the link path.

Example: simply display the current working directory:
[Root@www ~] #pwd
/root <== shows the catalogue ~

Example: Displays the actual working directory, not the directory name of the link file itself
[Root@www ~]# cd/var/mail <== Note that/var/mail is a link file
[Root@www mail]# pwd
/var/mail <== lists the current working directory
[Root@www mail]# Pwd-p
/var/spool/mail <== What's going on. There's a lot of difference between-p
[Root@www mail]# Ls-ld/var/mail
lrwxrwxrwx 1 root Sep 4 17:54/var/mail->spool/mail
# You should know why if you see here. Because/var/mail is a link, connected to the/var/spool/mail
# So, with the PWD-P option, it will not be displayed with the data from the link file, but the correct full path is displayed.

mkdir (Create new directory)

If you want to create a new directory, use MkDir (makedirectory).

Grammar:

mkdir [-MP] Directory name

Options and Parameters:-M: Configuration file Permissions Oh. Direct configuration, do not need to see the default permissions (umask) of the face ~-P: To help you directly to the desired directory (including the previous level of the directory) back to create.

Example: Please try to create a few new directories below////.

[Root@www ~]# Cd/tmp
[root@www tmp]# mkdir test <== Create a new directory for test
[Root@www tmp]# mkdir Test1/test2/test3/test4
Mkdir:cannot Create directory ' TEST1/TEST2/TEST3/TEST4 ':
No such file or directory <== cannot create this directory directly.
[Root@www tmp]# mkdir-p Test1/test2/test3/test4

Add this-p option to help you create a multi-tiered directory yourself.

Example: Create a directory with permissions of Rwx--x--x

[Root@www tmp]# mkdir-m 711 Test2
[Root@www tmp]# Ls-l
Drwxr-xr-x 3 root root 4096 June 12:50 test
Drwxr-xr-x 3 root root 4096 12:53 test1
Drwx--x--x 2 root root 4096 12:54 test2

The Permissions section above, if you do not add-m to enforce the configuration properties, the system uses the default properties.

If we use-M, as in the previous example we give the-M 711来 the permission to give the new directory drwx--x--x.

RmDir (Delete empty directory)

Grammar:

rmdir [-p] Directory name

Options and Parameters:- P: together with the previous "empty" directory also deleted

Delete w3cschool.cc Directory

[Root@www tmp]# rmdir w3cschool.cc/

Example: The directory created in the mkdir example (/tmp) is deleted.

[Root@www tmp]# ls-l <== See how many directories exist.
Drwxr-xr-x 3 root root 4096 June 12:50 test
Drwxr-xr-x 3 root root 4096 18 12

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.