How to List the Files inside of a Folder using the Terminal on Linux Mint

Share
In this tutorial, we'll learn how to list the files and folders inside a directory using the terminal on Linux Mint. This will allow us to browse our files in the terminal without needing to use file manager or a GUI.

List Files of the Current Working Directory

To list the files of the of the current working directory, the simplest although incomplete method is to execute the following terminal command [how?]:

ls

This will list all files in the current working directory, except the dotfiles. Just like how some file managers treat dotfiles like hidden files, the ls command also hides them by default.

The "ls" terminal command being executed. Its output are multiple words in blue separated by spaces: Desktop, Documents, Downloads, Music, Pictures, Templates, and Videos.
The ls command and its output on Linux Mint.

Observe that the output matches what you would see in the file manager.

A window titled "Home." The menubar contains File, Edit, View, Go, Bookmarks, Help menus. An address bar with a left arrow, right arrow, and up arrow buttons, next to a set of three buttons, one being a left arrow button, the middle being an icon of a house labelled virtual-curiosities, and the right being a right arrow button. At the right side, five icons whose purpose is difficult to tell: a "return" shaped arrow, a magnifying glass, four squares forming a larger square, 3 squares at left of 3 lines, and 6 small rectangles. On the left pane, a list of locations to navigate: My Computer (expanded) including Home, Desktop ,Documents, Music, Pictures, Videos, Downloads, Recent, File System (with a filling bar under the label), Trash; Devices (collapsed), Network (Collapsed). The main pane has several folder icons, most with a matching icon on the folder: Desktop, Documents (with a paper icon), Downloads (down arrow), Musci (music note), Pictures (camera), Public (3 connected dots), Templates (fading paper icon), Videos (reel). At the bottom, a status bar with 3 buttons at the left, the message "8 items, Free Space: 39,1 GB", and a slider at the right.
Nemo's main window, displaying a user's home directory.

What do the Colors in ls Mean?

By default, ls on Linux Mint is aliased to ls --color=auto, which prints colored output. The exact colors used depends on the configuration of the terminal and the $LS_COLORS environment variable. Some of them are:

  • Blue for folders.
  • Purple for image and video files.
  • Green for executable files (with x permission).
  • White for other files.
  • Cyan for symlinks.
  • Red for dangling symlinks (when the target doesn't exist).
  • Yellow for devices (on /dev).

See [https://askubuntu.com/questions/17299/what-do-the-different-colors-mean-in-ls] (accessed 2025-03-15) for a more complete answer.

List All Files Including Dotfiles

To list all files INCLUDING the dotfiles, we use the --all argument, or the -a flag.

ls --all
ls -a

Either of the commands above will list the files including the dotfiles. The options -A (--almost-all) will skip printing . and .. which otherwise will appear on every directory.

List Files of a Specific Directory

The first non-optional argument we pass ls can be a filepath to a directory we want to list the files of, in case we don't want to list files from the current working directory.

ls ~/Downloads

Above, ls will list the files of ~/Downloads instead of of the current working directory.

List Only Files of a Directory, Not Folders

There is a terminal command to list only the files of a directory, but it's not perfect. On Linux, something inside a directory can be a file, a directory, or a symlink, and a symlink may be a symlink to a file or to a directory. There is no way to know what the symlink points to without resolving it, and in general commands don't resolve them, they just list them.

We can make ls display a / after directories with the -p flag. We can then filter them out using grep and the -v (--invert-match) option. This will remove the directories from the list, but not the symlinks, so it's not perfect. For example:

ls -p | grep -v / 

List Files with More Information

It's possible to view more information about the files in a folder using the -l option, which is for long listing format. This format looks like this:

drwxr-xr-x 4 john john   4096 Mar  7 21:33  Pictures

Let's understand what these columns mean.

1: the first character is - for files, l for symlinks, and d for directories. Then a RWX triplet.

2: the number counts how many hard links the inode has. If you don't use this feature, this number should always be 1 for files. For folders (which you shouldn't be able to hard link), the number may seem random, but there is actually some logic in it!

Every folder has a hard link to all of its subfolders. Every folder also has a hard link to itself (.). Every folder also has a hard link to its parent folder (..). This means the number of hard links a folder has is 2 plus the number of subfolders it contains!

3: this is the user that owns the file.

4: this is the group associated with the file. This is identical because when you create a user a group is created with the same name.

5: this is the file size: 4096 bytes. This number will be a multiple of the block size of the disk, e.g. 4096 bytes, then 8192 bytes, and so on. This increases linearly for a small number of blocks (around ten), until the inode runs out of direct pointers to blocks. Then it must use indirect pointers which have an overhead.

6: this is the modification date of the file. You can also access this using stat filename.txt.

7: the filename of the file, surrounded by single quote characters if it contains space characters.

Written by Noel Santos.

About the Author

I'm a self-taught Brazilian programmer graduated in IT from a FATEC. In a world of increasingly complex and essential computers, I decided to use my technical expertise in hardware, desktop applications, and web technologies to create an informative resource to make PC's easier to understand.

View Comments