The ls Linux command is used to record information and directories within the present listing. Whilst you sort ls and press Input within the terminal, it is going to show all of the information and folders within the listing you’re recently in. It’s a elementary command that is helping customers navigate and set up their document device via offering an outline of the contents.

You’ll be able to additionally use quite a lot of choices with the ls command to view further main points, akin to document permissions, possession, document dimension, and amendment dates. On this put up, we discover all conceivable makes use of of the ls command.

Common syntax for ls command:

$ ls [OPTION...] [FILE...]
1. Show hidden information
ls -a

This selection will show all of the record of directories, together with hidden information. Hidden information get started with a dot (.)


.  ..  .config  .bashrc  file1.txt  folder1  .hiddenfolder  image.jpg

On this instance, the one dot (.) represents the present listing, and the double dot (..) represents the mum or dad listing. The .config and .bashrc information, along side the .hiddenfolder, are hidden information and directories that may now not be proven with the obvious ls command however are displayed right here as a result of the -a possibility. The opposite pieces are common, non-hidden information and directories.

2. Sorting via document dimension
ls -S

Use the ls -S command to type information and directories via dimension in descending order, after which print them to the terminal.



On this instance, file_large.mp4 is the biggest document, and textfile.txt is the smallest document. The directories folder1/ and folder2/ also are indexed, however the -S possibility doesn’t believe their sizes within the sorting. If you wish to see the sizes along side the information, you’ll mix the -S possibility with the -l possibility, like ls -lS.

3. Show information in lengthy structure
ls -l

The -l possibility presentations the contents of the listing in a extra detailed approach. Showing the document’s proprietor and workforce, closing changed time, and extra.


overall 48
drwxr-xr-x 5 person person 4096 Aug  6 10:30 Paperwork
-rw-r--r-- 1 person person  123 Aug  6 10:20 document.txt
drwxr-xr-x 2 person person 4096 Aug  6 10:15 Track
-rwxr-xr-x 1 person person 2048 Aug  6 10:10
drwxr-xr-x 3 person person 4096 Aug  6 10:05 Footage

Right here’s a breakdown of what every phase manner:

  • drwxr-xr-x: The document permissions (e.g., d signifies a listing, rwx manner learn, write, and execute permissions for the landlord).
  • 5: The selection of exhausting hyperlinks to the document or listing.
  • person: The landlord of the document or listing (indexed two times, as soon as for the landlord and as soon as for the crowd).
  • 4096: The document dimension in bytes.
  • Aug 6 10:30: The date and time the document or listing used to be closing changed.
  • Paperwork: The title of the document or listing.
4. Kind via date and time
ls -t

This command types information via closing changed time. Essentially the most just lately edited information will seem on the best of the output, making them simple to search out.


record.txt  symbol.png  challenge/  notes.docx  old_data.csv

On this instance, record.txt is essentially the most just lately changed document, whilst old_data.csv is the oldest. If you happen to have been to run the command in a special listing or at a special time, the output would range in accordance with the information and their amendment instances in that exact listing.

5. Show best directories
ls -d */

Use this command to record the sub-directories aside from all different information.


Right here’s a pattern output for the command, assuming you’ve 3 directories named Paperwork, Footage, and Track within the present listing:

Paperwork/  Footage/  Track/

Every listing title is adopted via a slash (/), indicating that this is a listing.

6. Record information and save effects to a document
ls > [filename]

The ls > [filename] command means that you can save the output of the previous command to a document.


The command ls > filename.txt doesn’t show any output within the terminal. As an alternative, it redirects the output of the ls command to a document named filename.txt.

If you happen to have been to run the ls command in a listing containing information and folders, the names of the ones information and folders can be written to filename.txt. You wouldn’t see anything else within the terminal itself.

Right here’s an instance of what may well be within filename.txt if the listing contained 3 information and one folder:


The precise contents would rely at the information and directories provide within the present listing the place the command used to be run.

7. Record document homeowners with their ID
ls -n

This selection presentations the landlord and workforce as UID and GID.


drwxr-xr-x 2 1001 1001 4096 Apr  1 12:34 directory1
-rw-r--r-- 1 1001 1001    0 Apr  1 12:34 file1.txt
-rwxr-xr-x 1 1002 1002  123 Apr  1 12:34

On this instance, the primary column displays the document permissions, the second one column displays the selection of exhausting hyperlinks, the 3rd and fourth columns display the person and workforce IDs, the 5th column displays the document dimension in bytes, and the 6th and 7th columns display the date and time of the closing amendment. The closing column displays the title of the document or listing.

Extra Linux instructions:
Listing Operations rmdir · cd · pwd
Report Operations cat · cp · dd · much less · ls · mkdir · mv · tail · tar · zip
Report Machine Operations chown · mkfs
Networking ping · curl · wget · iptables
Seek and Textual content Processing in finding · grep · sed · whatis
Machine Knowledge and Control env · historical past · best · who
Consumer and Consultation Control display screen · su · sudo

The put up Record Information and Folders in Linux gave the impression first on Hongkiat.

WordPress Website Development Source:

[ continue ]