变更目录
时间:2020-02-23 14:44:57 来源:igfitidea点击:
[theitroad@linux ~]$pwd
列出目录内容
为了列出目录的内容,我们使用ls命令。
[theitroad@linux ~]$ls
如果我们要列出特定目录的内容,比如说根目录内的etc目录的内容,我们将编写以下内容。
[theitroad@linux ~]$ls /etc
如果我们要列出多个目录的内容,比如说etc和根目录内的usr目录的内容,我们将编写以下内容。
[theitroad@linux ~]$ls /etc /usr /etc: ---- content of /etc directory -- /usr: ---- content of /usr directory --
如果要以长格式列出目录的内容,请执行以下命令。
[theitroad@linux GitHub]$ls -l total 0 drwxr-xr-x 13 theitroad staff 442 Jan 15 2014 C-Project drwxr-xr-x 7 theitroad staff 238 Mar 24 2014 Php-Project drwxr-xr-x 12 theitroad staff 408 Sep 4 18:14 UglifyJS2 drwxr-xr-x 18 theitroad staff 612 Mar 24 2014 Web-App drwxr-xr-x 21 theitroad staff 714 Aug 15 2014 bootstrap-datetimepicker drwxr-xr-x 9 theitroad staff 306 Aug 23 21:22 chartjs drwxr-xr-x 8 theitroad staff 272 May 24 2014 database-tutorial drwxr-xr-x 14 theitroad staff 476 Aug 14 2014 datetimepicker drwxr-xr-x 13 theitroad staff 442 Jun 29 2014 fonts drwxr-xr-x 8 theitroad staff 272 Jun 13 2014 gcm drwxr-xr-x 9 theitroad staff 306 Jan 9 14:16 google-services drwxr-xr-x 21 theitroad staff 714 Nov 24 18:22 jQuery-File-Upload drwxr-xr-x 23 theitroad staff 782 Oct 3 15:56 jquery_jeditable drwxr-xr-x 31 theitroad staff 1054 Aug 14 2014 moment drwxr-xr-x 38 theitroad staff 1292 Jan 29 2014 phpredis drwxr-xr-x 14 theitroad staff 476 Sep 6 10:29 theitroad.github.io drwxr-xr-x 43 theitroad staff 1462 Jan 30 2014 zguide
长格式字段
Field | Description |
---|---|
drwxr-xr-x | Access right to the file or directory. If the first character is a dash - then its a regular file. If the first character is d then its a directory. Next 3 characters defines the access rights of the owner. The next 3 characters defines the access rights of the group. Finally the last three characters defines the access right for everyone else. |
13 | Number of hard links. |
theitroad | Username of the owner. |
staff | Name of the group to which the file or directory belongs. |
442 | Size of the file in bytes |
Jan 15 2014 | Last modified timestamp. |
C-Project | Name of the file or directory |
选项和参数
命令之后通常带有一些选项,这些选项可以改变命令的行为,此外,后面还带有一些参数,命令可以对该命令执行某些操作。
以下是命令的一般格式。
[theitroad@linux ~]$command -options arguments
我们看到ls选项-l以长格式列出了目录的内容。
ls命令的常用选项
Option | Description |
---|---|
-a | List all the files including the hidden files which normally start with a dot. For example .log |
-F | This will put a/at the end listed names that are directories. |
-h | This will display the file size in human readable format rather than in bytes. |
-r | This will display the result in reverse order. |
-S | This will sort the result by file size. |
-t | This will sort the result by last modified time. |
变更目录
要从一个目录切换到另一个目录,我们使用cd命令。
[theitroad@linux ~]$cd /etc
它将当前工作目录更改为根目录内的etc目录。
绝对和相对路径名
我们可以使用绝对路径名和相对路径名来更改目录。
文件或者目录的绝对路径名将从根目录/开始。
因此,如果要将当前工作目录从/home/theitroad更改为根目录内的etc目录,则将使用以下绝对路径。
[theitroad@linux ~]$cd /etc
相对路径名从当前工作目录开始。
因此,如果我们考虑以下目录结构。
theitroad | +--doc | | | +-- sample.txt | +--happy.c | +--sheet | +--v1 | | | +--a.csv | +--main.csv
如果我们当前的工作目录是theitroad,那么如果要将目录更改为doc,我们将输入以下命令。
[theitroad@linux ~]$cd doc
同样,如果要将目录从theitroad更改为工作表目录中的v1,则将执行以下相对路径名
[theitroad@linux ~]$cd sheet/v1
移至上级目录
要移至当前工作目录的父目录,我们使用以下命令。
[theitroad@linux ~]$cd ..
文件命令
file命令用于获取文件的简短描述。
[theitroad@linux ~]$file test.php test.php: PHP script text