Linux Learning Series 3---Catalog

Source: Internet
Author: User

The directory is also a file, and its only function is to save the file and its associated information. All files, including normal files, device files, and directory files, will be saved to the directory.

Home Directory

After logging in, your location is your home directory (or login directory), and then you are primarily working in this directory, such as creating files, deleting files, and so on.

Use the following command to access the home directory at any time :

$CD ~$

This represents the home directory . If you want to go to another user's home directory, you can use the following command:

$CD ~username$

You can use the following command to return to the directory where you entered the current directory:

$CD-$
Absolute path and relative path

The Linux directory has a clear hierarchy,/represents the root directory, all directories are located/below, and the location of the file in the hierarchy can be represented by a path .

If a path starts with a/, it is called an absolute path, which represents the relationship of the current file to the root directory . Examples are as follows:

/etc/passwd/users/sjones/chem/notes/dev/rdsk/os3

a path that does not start with a/begins with a relative path, which represents the relationship of the file to the current directory . For example:

Chem/notespersonal/res

You can use the PWD command to get the directory that is currently located :

$pwd/user0/home/amrood$

You can use the ls command to view files in a directory:

$ls dirname

The following example iterates through the files in the/usr/local directory:

$ls/usr/localx11       bin          gimp       jikes       sbinace       Doc          include    Lib         shareatalk     etc          Info       man         ami
Create a Directory

You can use the mkdir command to create a directory with the following syntax:

$mkdir dirname

DirName can be either an absolute path or a relative path. For example

$mkdir mydir$

The Mydir directory is created under the current directory. And AS

$mkdir/tmp/test-dir$

The Test-dir directory is created in the/tmp directory. mkdir does not output any information after the directory is successfully created .

You can also use the mkdir command to create multiple directories at the same time , such as

$mkdir Docs pub$

The Docs and pub two directories are created under the current directory.

Create parent Directory

when creating a directory using the mkdir command, an error occurs if the parent directory does not exist. in the following example, mkdir will output an error message:

$mkdir/tmp/amrood/testmkdir:failed to make directory "/tmp/amrood/test"; No such file or directory$

Adding the- p option to the mkdir command allows you to create the required directories at the first level, even if the parent directory does not exist and does not give an error. For example

$mkdir-P/tmp/amrood/test$

All parent directories that do not exist are created.

Delete Directory

You can use the rmdir command to delete a directory , for example:

$rmdir dirname$

Note: When you delete a directory, make sure that the directory is empty and that no other files or directories are included.

You can also delete multiple directories using the rmdir command:

$rmdir dirname1 dirname2 dirname3$

If dirname1, dirname2, and Dirname3 are empty, they will be deleted. rmdir does not output any information when the directory is successfully deleted.

Change your directory

You can use the CD command to change the current directory into any directory that has permissions, with the following syntax:

$CD dirname

DirName is a path, either a relative path or an absolute path. For example

$CD/usr/local/bin$

You can enter the/usr/local/bin directory. You can use relative paths to enter the/usr/home/amrood directory from this directory:

$CD: /.. /home/amrood$
Renaming a directory

The MV (move) command can also be used to rename a directory with the following syntax:

$MV Olddir Newdir

The following example renames the Mydir directory to the Yourdir directory:

$MV Mydir yourdir$
Point number (.)

A point number (.) Represents the current directory, two point numbers (..) Represents an ancestor directory (parent directory).

the-a option of the LS command can view all files, including hidden files, and the-l option can view all information about a file, in total 7 columns. For example:

$ls-ladrwxrwxr-x    4    Teacher   class   2048  Jul 17.56. drwxr-xr-x   root              1536  Jul 13 14:18.. ----------    1    teacher   class   4210 may  1 08:27. profile-rwxr-xr-x    1    teacher   Class   1948 may  13:42 memo$

Linux Learning Series 3---Catalog

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.