Get the App
SLTechnology News&Howtos  ›  Servers  › 

Linux file and directory management

Shulou Source: shulou.com Published: 2022-06-02 20:27:22 10月03日 Update

Absolute path:

The path is written from the root directory /, for example: / usr/share/doc.

Relative path:

The path is not written from /, for example, from / usr/share/doc to / usr/share/man, it can be written as: cd.. / man this is how to write the relative path!

Common commands for working with directories

Next, let's take a look at some common commands for dealing with directories:

Ls: listing directories

Cd: switching directories

Pwd: displays the current directory

Mkdir: create a new directory

Rmdir: delete an empty directory

Cp: copy a file or directory

Rm: remove files or directories

Mv: move files and directories or modify the names of files and directories

You can use man [commands] to view the documentation for each command, such as man cp.

Ls (list directories)

In Linux systems, the ls command is probably the most frequently run.

Syntax:

[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 hidden files (beginning with. Listed together (commonly used)

-d: list only the directory itself, not the file data in the directory (commonly used)

-l: long data string list, including file attributes, permissions and other data; (commonly used)

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

[root@www ~] # ls-al

Cd (switch directories)

Cd is the abbreviation of Change Directory, which is the command used to change the working directory.

Syntax:

Cd [relative or absolute path]

# create a runoob directory using the mkdir command

[root@www ~] # mkdir runoob

# change to the runoob directory using an absolute path

[root@www ~] # cd / root/runoob/

# change to the runoob directory using a relative path

[root@www ~] # cd. / runoob/

Go back to your home directory, that is, / root

[root@www runoob] # cd ~

It means to go to the current one-level directory, that is, the one-level directory of / root

[root@www] # cd.

Next, you should be able to understand the cd command a few more times.

Pwd (shows the directory where it is currently located)

Pwd is an acronym for Print Working Directory, that is, a 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 shows the current working directory:

[root@www ~] # pwd

/ root

Tags: Directory file command line number content path parameter syntax commonly used name instance attribute one line representative meaning permission target blank data switch Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology Shulou Tech Info Redmi Linux