Linux常用命令使用--ls, cd, pwd

# Exercise 1 - ls, cd, pwd

## 1.Experiment Introduction

#### 1.1 Experiment Content

This experiment will introduce the use of ls, cd, pwd commands in Linux commands.

#### 1.2 Experimental Knowledge Points

- ls Command
- cd Command
- pwd Command

#### 1.3 Experiment Environment

The experimental environment used in the course is Ubuntu Linux 14.04 64-bit version. The program will be used in the experiment:

- Xfce terminal

## 2.Experiment Procedure
- ls
- cd
- pwd

### 2.1 ls Command

The ls command is the most commonly used command in linux, and the ls command is an acronym for list.

Ls is used to print a list of current directories. If ls specifies a different directory, then the list of files and folders in the specified directory will be displayed.

By using the ls command, you can view not only the files contained in the linux folder, but also file permissions (including directories, folders, and file permissions) and directory information, and so on.

**(1) Command Format**

> ls [OPTION]

**(2) Common Parameters**

| Parameter | Description |
| --------- | ------------------------------------------------------------ |
| -a | -all List all files in the directory, including hidden files beginning with . |
| -l | In addition to the file name, the file permissions, owner, file size, etc. are listed in detail. |
| -d | -directory displays the directory as a file instead of the file in it |
| -h | –human-readable List file sizes in an easy-to-understand format (eg 1K 234M 2G) |
| -t | Sort by file modification time |

**(3) Common Examples**

**Example 1:** List the details of all the files and directories in the /home folder. You can use the following command:

```
ls -a -l /home
ls -al /home
```

To make it easier to see the test results, we first create a test file. Here we will use the cd and touch commands. We will learn later so that We are not explain it here. Create commands are as follows:

```
cd /home
sudo touch labex.txt
```


The two commands above perform the same result. The result is as follows:

Note the red box above, **d** stands for directory, **-** indicates that files, files, and directories display different colors.

**Example 2:** List the contents of all the file directories starting with "d" in the current directory. You can use the following command:

```
ls -l d*
```

Here for the sake of showcase, we create 2 test files. touch command is used here which will be explained later:
```
sudo touch data.txt
sudo touch date.txt
```


**Example 3:** List the size of all the file directories in the /home directory in an easy-to-understand format. You can use the following command:

```
ls -alh /home
```

1. List the size of all file directories beginning with "d" in the /home directory in an easy-to-understand format.
2. List all directories in the /home directory that begin with "s".

### 2.2 cd Command

The cd command can be said to be the most basic command statement in Linux. Other command statements are to be operated on using the cd command. The cd command is an abbreviation of change directory, which switches the current directory to the specified directory.

**(1) Command Format**

> cd [Directory ]

**(2) Common Examples**

**Example 1:** From the current directory enter into the system root directory, you can use the following command:

```
cd /
```

**Example 2:** From the current directory enter into the parent directory, you can use the following command:

```
cd ..
```

.. represents the parent directory

**Example 3:** Entering the current user's home directory from the current directory, you can use the following command:

```
cd ~
```

~ Indicates the current user's home directory, not the same concept as the system root directory

**Example 4:** From the current directory into the previous directory, you can use the following command:

```
cd -
```

- Indicates last entered directory
### 2.3 pwd Command

Use the pwd command in Linux to see the full path to the "current working directory". Simply put, every time you operate in the terminal, you will have a current working directory. When you are not sure about the current location, pwd is used to determine the exact location of the current directory within the file system.

The pwd command is an acronym for Print Working Directory.

**(1) Command Format**

> pwd [OPTION]

**(2) Common Parameters**

| Parameter | Description |
| --------- | ------------------------------------------------------------ |
| -P | Display actual physical path instead of using link path |
| -L | When the directory is a connection path, the connection path is displayed |

**(3) Common Examples**

**Example 1:** To display the path of the current directory, use the following command:

```
pwd
```

**Example 2:** To display the physical path of the current directory, use the following command:

```
pwd -P
```

**Example 3:** To display the connection path of the current directory, use the following command:

```
pwd -L
```

**(4) Questions**
### 3.Reference Link

Please note this tutorial is translated from an awesome Chinese blog. Refer to the blog post for [ a daily Linux command]( http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html). Thanks to the excellent tutorial provided by the author [ Peida]( http://www.cnblogs.com/peida).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值