官术网_书友最值得收藏!

Combining command options

You have learned a lot of different options that you can use with the ls command. Table 4 summarizes all the options we have used so far.


Table 4: Popular ls Command Options

You will often be wanting to use two or more command options at a time. For example, ls -a -l is commonly used to do a long listing for all the files in a directory.

Also, ls -l -a -t -r is a very popular combination because sometimes you would want to see the listing of the files sorted by modification times (oldest first). For that reason, combining the command options is more efficient and so running the ls -latr command:

elliot@ubuntu-linux:~$ ls -latr 
total 120
-rw-r--r-- 1 elliot elliot 0 Apr 11 2010 file2
-rw-r--r-- 1 elliot elliot 807 Dec 26 23:47 .profile
-rw-r--r-- 1 elliot elliot 3771 Dec 26 23:47 .bashrc
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw-r--r-- 1 elliot elliot 220 Jan 20 17:23 .bash_logout
drwxr-xr-x 6 elliot elliot 4096 Jan 25 22:13 Desktop
-rw-r--r-- 1 elliot elliot 0 Jan 25 23:08 file1
-rw-r--r-- 1 elliot elliot 0 Jan 25 23:27 file3
drwxr-xr-x 3 elliot elliot 4096 Jan 25 23:52 dir1
-rw------- 1 elliot elliot 3152 Jan 26 00:01 .bash_history
drwxr-xr-x 17 elliot elliot 4096 Jan 30 23:32 .

Will yield the same result as running the ls -l -a -t -r command:

elliot@ubuntu-linux:~$ ls -l -a -t -r 
total 120
-rw-r--r-- 1 elliot elliot 0 Apr 11 2010 file2
-rw-r--r-- 1 elliot elliot 807 Dec 26 23:47 .profile
-rw-r--r-- 1 elliot elliot 3771 Dec 26 23:47 .bashrc
drwxr-xr-x 9 root root 4096 Jan 17 04:37 ..
-rw-r--r-- 1 elliot elliot 220 Jan 20 17:23 .bash_logout
drwxr-xr-x 6 elliot elliot 4096 Jan 25 22:13 Desktop
-rw-r--r-- 1 elliot elliot 0 Jan 25 23:08 file1
-rw-r--r-- 1 elliot elliot 0 Jan 25 23:27 file3
drwxr-xr-x 3 elliot elliot 4096 Jan 25 23:52 dir1
-rw------- 1 elliot elliot 3152 Jan 26 00:01 .bash_history
drwxr-xr-x 17 elliot elliot 4096 Jan 30 23:32 .

Before this chapter comes to an end, I want to show you a pretty cool tip. First, let's create a directory named averylongdirectoryname:

elliot@ubuntu-linux:~$ mkdir averylongdirectoryname 
elliot@ubuntu-linux:~$ ls -ld averylongdirectoryname
drwxr-xr-x 2 elliot elliot 4096 Mar 2 12:57 averylongdirectoryname

Tab Completion is one of the most useful features in the Linux command line. You can use this to feature to let the shell automatically complete (suggest) command names and file paths. To demonstrate, type (don't run) the following text on your terminal:

elliot@ubuntu-linux:~$ cd ave

Now press the Tab key on your keyboard, and the shell will automatically complete the directory name for you:

elliot@ubuntu-linux:~$ cd averylongdirectoryname/

Pretty cool! Alright, this takes us to the end of this chapter, and it's time for you to do the lovely knowledge check.

主站蜘蛛池模板: 安仁县| 榆中县| 云梦县| 普兰县| 清水县| 越西县| 玉山县| 洛隆县| 宁津县| 昌黎县| 南川市| 如皋市| 阿图什市| 安阳市| 新乡市| 庆城县| 桐柏县| 花垣县| 南丹县| 元氏县| 调兵山市| 咸丰县| 巴青县| 兴和县| 绍兴县| 西林县| 迁安市| 河北区| 五大连池市| 松阳县| 嵊州市| 义马市| 汤阴县| 昭通市| 井陉县| 黄陵县| 都匀市| 大渡口区| 自治县| 凯里市| 郓城县|