Linux directory

A directory is also a file whose sole function is to hold files and their associated information. All files, including normal files, device files and directory files, will be saved to the directory.
After logging in to the home directory

, your location is your home directory (or login directory). Next, you mainly perform operations in this directory, such as creating files, deleting files, and so on.

The home directory can be accessed at any time with the following command:
$cd ~
$
here~ is the home directory. If you want to enter another user's home directory, you can use the following command:
$cd ~username
$ To
return to the directory where you were before entering the current directory, you can use the following command:
$cd -
$
absolute path and relative path

Linux directory has clear Hierarchy, / represents the root directory, and all directories are located under /; the location of files in the hierarchy can be represented by paths.

If a path begins with /, it is called an absolute path; it represents the relationship of the current file to the root directory. For example:
/etc/passwd
/users/sjones/chem/notes
/dev/rdsk/Os3
A path that does not start with / is called a relative path, which indicates the relationship between the file and the current directory. For example:
chem/notes
personal/res To
get the current directory you can use the pwd command:
$pwd
/user0/home/amrood

$
To view files in a directory, use the ls command:
$ls dirname
The following example will traverse the files in the /usr/local directory:
$ls /usr/local

X11 bin gimp jikes sbin
ace doc include lib share
atalk etc info man ami
Create a directory

You can use the mkdir command to create a directory, the syntax is:
$mkdir dirname
dirname can be an absolute path or a relative path. For example
$mkdir mydir
$
will create the mydir directory in the current directory. Another example is
$mkdir /tmp/test-dir
$
will create the test-dir directory in the /tmp directory. mkdir does not output any information after successfully creating a directory.

You can also use the mkdir command to create multiple directories at the same time. For example,
$mkdir docs pub
$
will create two directories, docs and pub, in the current directory.
When creating a parent directory

using the mkdir command to create a directory, if the parent directory does not exist, an error will be reported. In the following example, mkdir will output an error message:
$mkdir /tmp/amrood/test
mkdir: Failed to make directory "/tmp/amrood/test";
No such file or directory
$
Add the -p option to the mkdir command to create the required directory level by level, even if the superior No error will be reported if the directory does not exist. For example
$mkdir -p /tmp/amrood/test
$
will create all parent directories that do not exist.
Deleting a directory

You can use the rmdir command to delete a directory, for example:
$rmdir dirname
$
Note: When deleting a directory, make sure that the directory is empty and will not contain other files or directories.

You can also use the rmdir command to delete multiple directories at the same time:
$rmdir dirname1 dirname2 dirname3
$
If dirname1, dirname2, and dirname3 are empty, they will be deleted. rmdir does not output any information after successfully removing a directory.
To change the directory

, you can use the cd command to change the current directory and enter any authorized directory. The syntax is:
$cd dirname
dirname is a path, which can be a relative path or an absolute path. For example
$ cd /usr/local/bin
$
You can enter the /usr/local/bin directory. The /usr/home/amrood directory can be accessed from this directory using a relative path:
$cd ../../home/amrood
$
rename directory

The mv (move) command can also be used to rename a directory, the syntax is:
$mv olddir The following example newdir
will rename the mydir directory to yourdir directory:
$mv mydir yourdir
$
dot (.)

A dot (.) represents the current directory, two dots (..) represent the parent directory (parent directory) .

The -a option of the ls command can view all files, including hidden files; the -l option can view all information about the file, with a total of 7 columns. For example:
$ls -la
drwxrwxr-x 4 teacher class 2048 Jul 16 17.56 .
drwxr-xr-x 60 root 1536 Jul 13 14:18 ..
---------- 1 teacher class 4210 May 1 08: 27 .profile
-rwxr-xr-x 1 teacher class 1948 May 12 13:42 memo
$

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326993906&siteId=291194637