Linux Command ls, linuxls

Source: Internet
Author: User

Linux Command ls, linuxls

It has been two years since Ben entered the Linux field. Although he is so familiar with shell commands, he looks back, in fact, I only know a little about the various commands.

At the entry stage of Linux, I tried to solve the problem quickly and enjoy a sense of accomplishment. This is my motivation, I really enjoy this kind of "direct" conversation with the underlying system and solve the problem. However, people cannot stay at that level all the time. The Linux Command Line is profound and profound. I want to upgrade this kind of experience, it is inevitable to re-build the furnace -- Re-recognize the commonly used commands and sort them out in the system's mind, only in this way can we use this powerful tool to solve various problems more effectively and accurately.

Today, I will start with the most basic ls command.
Ls is short for list, as its function is to list or display. The parameter after ls is a common directory. ls will list the files (including directories) under these directories ). The basic format of this command is:
Ls option file list
The options can be omitted. Files in the file list are separated by spaces. The file can be either a directory or a common text file, but it is meaningless to simply display it in the command line. If there is nothing behind ls, the current directory is used as the parameter by default to list the files in the current directory.
* When ls outputs the result, it is ordered alphabetically by column. In fact, you can observe it yourself *

Next we will go to the key topic: ls options.

  • -A: Lists hidden files, including hidden directories.
    Many directories contain hidden files, which start. If the-a option is not added, these files are not output by default. The same is true in the graphic interface. You can open your home directory. What you can see is not all in the home directory. In ubuntu, you can press Ctrl + H ", A large number of other files will appear immediately.

  • -F: add the forward slash "/" to the end of the directory file.
    This parameter is used to distinguish between directory files and common files. In fact, by default, directory files and common files are displayed in different colors in the ls output results. However, some terminals do not support colors, so that all files use the same color, in this case, the-F parameter can be used to differentiate.

  • -R: recursively lists objects in the parameter subdirectories. That is to say, the subdirectory, the Sun Directory, and all files in the descendant directory will be listed.

  • -L: this parameter is also useful for common text files. It lists the detailed information of each file in the form of rows, one row for each file, the information of each row is displayed from left to right in sequence: file type, File Permission, total number of hard links, users and groups to which the file belongs, and file size (in bytes) the last file modification time and file name. As follows:

M @ sys :~ /Program/C_codes $ ll total usage 40drwxrwxr-x 5 m 4096 May 12 19:47. /drwxr-xr-x 9 m 4096 May 6 22:59 .. /drwxrwxr-x 2 m 4096 May 12 20:12 algorithms/-rwxrwxr-x 1 m 7314 May 10 18:26. out * drwxrwxr-x 8 m 4096 May 12 20:12. git/-rw-r -- 1 m 24 May 4 00:15. gitignore-rw-r -- 1 m 1399 April 27 16:16 stone_scissors_cloth.c-rw-rw-r -- 1 m 322 May 12 19:47 test. cdrwxrwxr-x 3 m 4096 April 24 11:24 tools/

What is the total usage above? I haven't figured it out yet. I will add it later.

  • -C: sort by the last modification time of the file, the most recent
  • -D: process all files as normal files. Sometimes we only want to know the information of a directory and do not want to list the files it contains, as shown below:
M @ sys :~ /Program/C_codes/algorithms $ ls-ld/etc/drwxr-xr-x 153 root 12288 May 12 20:16/etc/
  • -R: Reverse Order

  • -S: sort by the actual file size:

M @ sys :~ /Program/C_codes/algorithms $ ls-Sl total usage 40-rwxrwxr-x 1 m 7399 May 12 20:11. out-rw-r -- 1 m 1298 May 6 17:10 heapsort. c-rw-r -- 1 m 1139 May 4 12:25 merge_sort.c-rw-rw-r -- 1 m 915 May 9 13:43 quicksort. c-rw-r -- 1 m 909 May 12 20:12 stack. c-rw-r -- 1 m 782 May 4 14:50 search_array_sum.c-rw-rw-r -- 1 m 687 May 2 21:28 binary_search.c-rw-rw-r -- 1 m 566 May 4 00:10 insert_sort.c-rw-rw-r -- 1 m 97 April 7 16:22 README. md
  • -S: displays the number of blocks allocated to each file. It just explains the total usage of the-l parameter above:
M @ sys :~ /Program/C_codes/algorithms $ ls-sl total usage 408-rwxrwxr-x 1 m 7399 May 12 20:11. out4-rw-r -- 1 m 687 May 2 21:28 binary_search.c4-rw-r -- 1 m 1298 May 6 17:10 heapsort. c4-rw-r -- 1 m 566 May 4 00:10 insert_sort.c4-rw-r -- 1 m 1139 May 4 12:25 merge_sort.c4-rw-r -- 1 m 915 may 9 13:43 quicksort. c4-rw-r -- 1 m 97 April 7 16:22 README. md4-rw-r -- 1 m 782 May 4 14:50 search_array_sum.c4-rw-r -- 1 m 909 May 12 20:12 stack. c
  • -1: Do not squeeze all files in one row. Only one file is displayed in each row. Note that the number "1"
  • -U: sort by the last access time. For more information about-l and-t, see man ls.

The above is the result of my review and I have selected some of my unfamiliar or fun options.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.