๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ“ File Management August 28, 2026 4

Linux Command: ls

List directory contents and file information

Terminal โ€” File Management
Command
$ ls -la /home/user
Output
total 48 drwxr-xr-x 6 user user 4096 Mar 14 10:30 . drwxr-xr-x 3 root root 4096 Jan 15 09:00 .. -rw-r--r-- 1 user user 220 Jan 15 09:00 .bash_logout -rw-r--r-- 1 user user 3526 Jan 15 09:00 .bashrc drwxr-xr-x 2 user user 4096 Mar 14 10:30 Documents -rw-r--r-- 1 user user 807 Jan 15 09:00 .profile

The ls command is one of the most frequently used commands in Linux. It lists the contents of a directory, showing files, subdirectories, and their attributes. By default, ls shows the names of files and directories in the current working directory. When used with various options, ls can display detailed information including file permissions, ownership, size, and modification dates. It supports color output to distinguish between file types, and can sort output by name, size, date, or extension. The ls command is essential for navigating the filesystem and understanding what files exist in any given directory. System administrators use it constantly for verifying file deployments, checking permissions, and monitoring directory contents.

Syntax

ls [OPTION]... [FILE]...

Key Options

  • -l โ€” Use long listing format showing permissions, owner, size, and date
  • -a โ€” Show all files including hidden files (starting with .)
  • -h โ€” Human-readable file sizes (KB, MB, GB)
  • -R โ€” List subdirectories recursively
  • -t โ€” Sort by modification time, newest first
  • -S โ€” Sort by file size, largest first

Examples

List all files with details

ls -la /home/user

Output: total 48 drwxr-xr-x 6 user user 4096 Mar 14 10:30 . drwxr-xr-x 3 root root 4096 Jan 15 09:00 .. -rw-r--r-- 1 user user 220 Jan 15 09:00 .bash_logout -rw-r--r-- 1 user user 3526 Jan 15 09:00 .bashrc d

List files sorted by size

ls -lhS /var/log

Output: -rw-r----- 1 syslog adm 15M Mar 14 12:00 syslog -rw-r----- 1 syslog adm 5.2M Mar 14 12:00 auth.log -rw-r----- 1 syslog adm 2.1M Mar 14 12:00 kern.log

List only directories

ls -d */

Output: Documents/ Downloads/ Music/ Pictures/ Videos/

Pro Tips

  • Add "alias ll='ls -lah'" to your .bashrc for a quick detailed listing command.
  • Most modern distros have ls aliased to "ls --color=auto". Blue = directory, green = executable, cyan = symlink, red = archive.
  • For directories with thousands of files, ls can be slow. Use "ls -f" to skip sorting, or "find" for better performance.

Learn more: Full ls reference โ†’

Share this tip