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

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.

主站蜘蛛池模板: 丁青县| 武城县| 林甸县| 道真| 太仆寺旗| 福鼎市| 东明县| 汝阳县| 津南区| 新乐市| 印江| 城口县| 舞阳县| 阳城县| 玉溪市| 梧州市| 七台河市| 蒲城县| 象州县| 泰州市| 兴和县| 平果县| 新闻| 龙胜| 荆门市| 河间市| 泉州市| 深水埗区| 柳江县| 会泽县| 荃湾区| 屏东市| 五大连池市| 红河县| 星座| 本溪| 合作市| 威宁| 郑州市| 临颍县| 赣榆县|