InMotion Hosting Support Center

The ls command is one of the more basic commands in Linux. It is designed to list names and features of files and directories. It can be used for a single file or as many as all files and folders in a selected set of directories.

Command: ls
Synopsis: ls [option]... [file]...

Options:
Below is a list of the options that can be used with the ls command. You can use more than one at a time, making the command more efficient to your needs.

Option Long Name Description
-a --all Lists all files including those that begin with .
-A --almost-all Lists all files except . and ..
-b --escape print octal escapes for nongraphic characters
-B --ignore-backups does not list implied entries ending with ~
-c with -lt: sort by, and show, ctime (time of last modification of file status information) with -l: show ctime and sort by name otherwise: sort by ctime
-C list entries by columns
-d --directory list directory entries instead of contents, and do not dereference symbolic links
-D --dired generate output designed for Emacsâ dired mode
-f do not sort
-F --classify append indicator (one of */=>@|) to entries
-g Works like -l (long list) but does not display owner.
-G --no-group Works like -l (long list) but does not group names.
-h --human-readable when used with -l (long list), prints sizes in human readable format (e.g., 1K 234M 2G)
-H --dereference-command-line follow symbolic links listed on the command line
-i --inode print the index number of each file
-I --ignore=PATTERN do not list implied entries matching shell PATTERN
-k --block-size=1K Displays entry size in kilobytes (rounded up). Long name allows to set block size.
-l Displays entries in a long list format.
-L --dereference when showing file information for a symbolic link, show information for the file the link references rather than for the link itself
-m fills the width of the terminal with a comma separated list of entries
-n --numeric-uid-gid like -l (long list), but lists numeric user and group IDs instead of name
-N --literal prints raw entry names (does not treat e.g. control characters special)
-o like -l, but do not list group information
-p --indicator-style=slash appends a / indicator to directories
-q --hide-control-chars print ? instead of non graphic characters
-Q --quote-name display entries enclosed in double quotes
-r --reverse reverse order while sorting
-R --recursive lists all subdirectories recursively
-s --size print the allocated size of each file, in blocks
-S displays entries sorted by filesize
-t sort by modification time
-T --tabsize=COLS assume tab stops at each column instead of 8
-u with -lt: sort by, and show, access time. with -l: show access time and sort by name. otherwise: sort by access time
-U do not sort; list entries in directory order
-v natural sort of (version) numbers within text
-w assume screen width instead of current value
-x list entries by lines instead of by columns
-X sort alphabetically by entry extension
-1 list one file per line
-Z Display security context so it fits on most displays. Displays only mode, user, group, security context and file name.

Examples

The ls base command

This example displays the base command with no switches or parameters. Note the files and folders are displayed in a row. Directories display in blue and have a trailing slash.

ls
./ ../ error_log images/ index.php testfile.txt

Using the long list option

One of the more common switches, the long listing (-l) displays much more data than the base command. It displays the permissions, the owner, group, size, date last modified, and the name of the file.

$# ls -l
total 32
drwxr-xr-x  3 root    root     4096 Jun  3 10:19 ./
drwxr-x--- 25 root    root     4096 Jun  3 10:16 ../
-rw-r--r--  1 root    root     12523 May  5 13:29 error_log
drwxr-xr-x  2 root    root     4096 Jun  3 10:19 images/
-rw-r--r--  1 root    root       52 May  5 13:29 index.php
-rw-r--r--  1 root    root        0 Jun  3 10:15 testfile.txt

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

   
Social Login Joomla

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!