LINUX

LINUX LS指令

介紹

ls指令用來列出檔案(夾)的屬性。

語法

ls [options] [files]

常用的options

-a  List all files, including those whose names begin with a dot.

-l  Long listing, including file attributes. Add the -h option (human-readable) to print file size in kilobytes, megabytes, and gigabytes, instead of bytes.

-G  In a long listing, don't print the group ownership of the file.

-F Decorate certain filenames with meaningful symbols, indicating their types. Appends "/" to directories, "*" to executables, "@" to symbolic links, "|" to named pipes, and "=" to sockets. These are just visual indicators for you, not part of the filenames!

-S  Sort files by their size.

-t  Sort files by the time they were last modified.

-r  Reverse the sorted order.

-R  If listing a directory, list its contents recursively.

-d  If listing a directory, do not list its contents, just the directory itself.

範例

你可以列出當前目錄中的檔案:

⤍ ls

你可以列出指定目錄中的檔案:

⤍ ls dir1 dir2 dir3

你可以列出指定的檔案:

⤍ ls file1 file2 file3

最長使用到的options為-a-lls指令預設會把.開頭的檔案隱藏,使用-a可以列出所有檔案:

⤍ ls
myfile1  myfile2

⤍ ls -a
.hidden_file  myfile1  myfile2

使用-l可以列出檔案的完整資訊:

⤍ ls -l
-rw-r--r--  1  mt  eecsmt  4096  May  27  08:00  myfile1
-rw-r--r--  1  mt  eecsmt  1024  Apr  13  14:00  myfile2

⤍ ls -l myfile1
-rw-r--r--  1  mt  eecsmt  4096  May  27  08:00  myfile1

這些資訊分別為:權限(-rw-r--r--),硬連結數量(1),擁有者(mt),所在群組(eecsmt),大小(4096 bytes),最後修改日期(May 27 08:00),名稱(myfile1)

當然你也可以一次使用多個options來滿足你的需求:

⤍ ls -al
-rw-r-----  1  mt  eecsmt  2048  Mar  28  05:25  .hidden_file
-rw-r--r--  1  mt  eecsmt  4096  May  27  08:00  myfile1
-rw-r--r--  1  mt  eecsmt  1024  Apr  13  14:00  myfile2

發佈留言