Linux ls command

The ls command is one of the most commonly used commands under linux. The ls command is the same as the dir command under dos. Both are used to list files in a directory. Let's take a look at the usage of ls. 

English full name: List is the meaning of list. When we learn something, we need to know why. When you know what this thing is probably, your mind will associate a lot of things with learning. soon.

 

1. ls -a lists all files under the file, including hidden files starting with "." (the hidden files of files under linux start with . If there is .., it means that there is a parent directory).

 

2. ls -l lists the detailed information of the file, such as creator, creation time, list of read and write permissions of the file, etc.

 

3. ls -F adds a character at the end of each file to indicate the type of the file. "@" means symbolic link, "|" means FIFOS, "/" means directory, "=" means socket.

 

4. ls -s prints the file size after each file. size (size)

 

5. ls -t sort files by time Time (time)

 

6. ls -A lists files other than "." and "..".

 

7. ls -R lists all the files in the subdirectories of the directory, which is equivalent to the "recursive" implementation in our programming

 

8. ls -L lists the link names of the files. Link

 

9. ls -S sort by file size

The above are some usages of the ls command. Of course, there are many that are not listed. You can man it. Help to learn English

ls can be combined with the pipe character "|" to perform complex operations. For example: ls | less is used to implement paging of file lists, ls

 

Calculate the number of files in the current directory

ls -|*|grep "^-"| wc -|

 

Finally, let's talk about the meaning of some file colors of files under linux

Green ----> represents executable files, (green represents the meaning of the pass) hehe

Red ----> represents compressed file

Dark blue---->represents the directory

Light blue----->represents the linked file

Gray ----> represents some other files

 

linux下 ls -l 命令显示结果每一列代表什么意思

 

ls -l(这个参数是字母L的小写,不是数字1)  
    这个命令可以使用长格式显示文件内容,如果需要察看更详细的文件资料,就要用到ls -l这个指令。例如我在某个目录下键入ls -l可能会显示如下信息(最上面两行是我自己加的):  
位置1 2 3 4 5 6 7  
文件属性 文件数 拥有者 所属的group 文件大小 建档日期 文件名  
drwx------ 2 Guest users 1024 Nov 21 21:05 Mail  
-rwx--x--x 1 root root 89080 Nov 7 22:41 tar*  
-rwxr-xr-x 1 root bin 5013 Aug 15 9:32 uname*  
lrwxrwxrwx 1 root root 4 Nov 24 19:30 zcat->gzip  
-rwxr-xr-x 1 root bin 308364 Nov 29 7:43 zsh*  
-rwsr-x--- 1 root bin 9853 Aug 15 5:46 su*  
下面,我为大家解释一下这些显示内容的意义。  
    第一个栏位,表示文件的属性。Linux的文件基本上分为三个属性:可读(r),可写(w),可执行(x)。但是这里有十个格子可以添(具体程序实现时,实际上是十个bit位)。第一个小格是特殊表示格,表示目录或连结文件等等,d表示目录,例如drwx------;l表示连结文件,如lrwxrwxrwx;如果是以一横“-”表示,则表示这是文件。其余剩下的格子就以每3格为一个单位。因为Linux是多用户多任务系统,所以一个文件可能同时被许多人使用,所以我们一定要设好每个文件的权限,其文件的权限位置排列顺序是(以-rwxr-xr-x为例):  
    rwx(Owner)r-x(Group)r-x(Other)  
    这个例子表示的权限是:使用者自己可读,可写,可执行;同一组的用户可读,不可写,可执行;其它用户可读,不可写,可执行。另外,有一些程序属性的执行部分不是X,而是S,这表示执行这个程序的使用者,临时可以有和拥有者一样权力的身份来执行该程序。一般出现在系统管理之类的指令或程序,让使用者执行时,拥有root身份。 
   第二个栏位,表示文件个数。如果是文件的话,那这个数目自然是1了,如果是目录的话,那它的数目就是该目录中的文件个数了。  
    第三个栏位,表示该文件或目录的拥有者。若使用者目前处于自己的Home,那这一栏大概都是它的账号名称。  
    第四个栏位,表示所属的组(group)。每一个使用者都可以拥有一个以上的组,不过大部分的使用者应该都只属于一个组,只有当系统管理员希望给予某使用者特殊权限时,才可能会给他另一个组。  
    第五栏位,表示文件大小。文件大小用byte来表示,而空目录一般都是1024byte,你当然可以用其它参数使文件显示的单位不同,如使用ls –k就是用kb莱显示一个文件的大小单位,不过一般我们还是以byte为主。  
    第六个栏位,表示创建日期。以“月,日,时间”的格式表示,如Aug 15 5:46表示8月15日早上5:46分。  
    第七个栏位,表示文件名。我们可以用ls –a显示隐藏的文件名。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326461145&siteId=291194637