The Linux ls command displays files and subdirectories in your current location, making it a handy first step when navigating the terminal. Learn how options reveal hidden files, show useful details, and sort directory contents—small changes that make a long file list easier to read.

Multiple Choice

What command allows you to list files and directories in a Linux system?

The command that allows you to list files and directories in a Linux system is 'ls'. This command is short for "list" and is widely used in the Linux and Unix command-line environments to display the contents of a directory. When you use the 'ls' command, it shows a list of files and subdirectories in the current directory by default. Additionally, 'ls' can accept various options to modify its output, such as displaying hidden files, providing detailed information about each file, or sorting the output in different ways. Other potential options like 'dir' may be found in certain contexts (notably in DOS or Windows environments), but 'ls' is the standard and most widely recognized command for listing files in Linux. The terms 'list' and 'show' are not standard commands within the Linux command-line interface, making them unsuitable for this task. Thus, 'ls' is the correct and fundamental command to use for viewing directory contents in Linux.

Getting to Know ls: The Linux Command That Shows What’s Around

A Linux terminal can feel like a quiet room with all the furniture hidden. You know the files are there, but the screen won’t show them until you ask. The command that opens the view is ls. Run it in a directory, and Linux prints the names of the files and folders inside. It’s a small command with a big role: helping you see where you are and what you can work with.

The name is short for “list,” and it belongs to the family of core tools found across Linux and Unix systems. You’ll use it in a home folder, on a remote server, or while checking a project directory. Its basic form is refreshingly simple:


ls

With no extra instructions, ls displays the visible contents of your current directory. That’s often all you need. But Linux gives the command a few useful switches, so the same simple tool can reveal much more than a row of names.

Start with the current directory

When you open a terminal, you’re usually “in” a particular directory. Think of it as your current spot in a building. Running ls is like looking around the room before deciding where to go next.

The output might look like this:


Documents  Downloads  notes.txt  projects

Each entry is a file or directory. Directories may contain more files and directories, much like folders on a desktop. To see what’s inside one, pass its name to ls:


ls Documents

You don’t have to move into that directory first. You can also inspect a location by giving its path:


ls /var/log

That command lists the contents of /var/log, a common place for system log files. Paths can be relative to your current location or begin at the root directory, marked by /. This flexibility comes in handy when you’re checking several locations and want to stay put.

Hidden files aren’t really gone

A plain ls output can leave out some files. In Linux, a name that begins with a dot is treated as hidden in ordinary directory listings. Common examples include .bashrc and .config. These files often store settings, so they’re easy to miss if you only ask for the basic view.

Use the -a option to display all entries, including hidden ones:


ls -a

You may see . and .. in the results. They’re special directory references: . means the current directory, while .. means its parent. They’re not ordinary files, but they’re useful when navigating from the command line.

A related option is -A:


ls -A

It also shows hidden entries, but leaves out . and ... That can make the result a little less cluttered. Which form is more helpful depends on what you’re trying to inspect.

When names aren’t enough

Sometimes, a filename tells you very little. Is it a regular file or a directory? Who owns it? When was it last changed? The long format gives you more context:


ls -l

A line of output may look like this:


-rw-r--r-- 1 sam staff  842 Nov 20 10:14 notes.txt

The first group of characters shows the file type and permissions. The next fields include the number of links, owner, group, size, modification date, and name. At first glance, it can look like a jumble. With time, though, it becomes a compact status report.

The permission marks are especially useful on a server. They indicate who can read, change, or run a file. If a script won’t run, or a user can’t open a file, the long listing can offer an early clue. It won’t explain every problem by itself, but it gives you a solid starting point.

Want a more readable file size? Add -h to the long format:


ls -lh

Instead of reporting a size as a large count of bytes, it can show a friendlier value such as 12K or 4.2M. The -h option works best alongside a format that includes sizes, such as -l.

Put useful options together

Linux commands often let you combine short options. For instance:


ls -lah

This is a compact way to request a long listing, readable file sizes, and hidden entries. The same command can be written with spaces between options:


ls -l -a -h

Both forms work. Combined flags are common in terminal use, though spelling them out can make a command easier to read when you’re new to it.

You can also change how entries are ordered. By default, names are generally shown alphabetically. To sort by the most recent modification time, use:


ls -lt

Add -r to reverse the order:


ls -ltr

That places older entries first and newer ones later, which can be handy when you want the latest file near the bottom of a long listing. To sort by file size, use -S:


ls -lS

There’s no single display that suits every situation. A quick glance may call for plain ls; a server check may call for ls -lah. The useful skill is knowing what detail you need, then asking the command to show it.

Read the output with care

ls reports what it can see, but it doesn’t change files or open them. That makes it a safe first step when you’re unfamiliar with a directory. Still, a listing can be incomplete if you forget that hidden files are left out, or if a directory’s permissions prevent you from reading its contents.

It’s also worth noticing that names may contain spaces. A file called annual report.txt appears as one name, even if the terminal output makes the spacing look like a gap between entries. When referring to such a name in another command, you’ll usually need quotes:


cat "annual report.txt"

That detail matters because the shell treats spaces as separators unless you tell it otherwise. The listing shows the name; the shell rules determine how you refer to it.

For especially long output, send the results through a pager:


ls -la | less

The vertical bar passes the output from ls into less, where you can scroll through it one screen at a time. Press q to leave the pager. On a server with many files, that’s easier than watching a flood of text race past.

A small command with everyday value

Other systems may offer commands such as dir, and some shells provide alternate names or tools. But ls is the standard command you’ll encounter across Linux and many Unix-like environments. Learning it pays off because file management starts with knowing what’s present.

That’s the quiet strength of ls: it helps turn an unfamiliar directory into a place you can navigate. Start with the basic listing, add -a when hidden settings matter, and use -l when ownership, permissions, or dates are important. A few letters can make the terminal feel less like a blank room and more like a map.