How to List Files on Raspberry Pi With the ls Command - Android Tricks 4 All
News Update
Loading...

Saturday, May 8, 2021

How to List Files on Raspberry Pi With the ls Command

While the standard (non-Lite) version of Raspberry Pi OS features a desktop environment for intuitive navigation, sometimes you want to get under the hood. This is where the command-line terminal comes in handy, enabling you to access to a host of powerful Linux commands such as ls to list files.

Access the Terminal

To access the command-line terminal, either click on the black box icon in the top menu bar of the Raspberry Pi OS desktop, or select it from the raspberry icon menu: Accessories > Terminal.

Related: Useful Raspberry Pi Terminal Commands

Use the ls Command

By default upon opening a Terminal window, you’ll be in the /home/pi directory (folder). To list the files and directories in it, type the following command, followed by the Return key.

ls

To list the contents of a different directory, you could use the cd command to switch to it. Alternatively, simply use ls followed by the directory name (with a preceding slash, /). For example:

ls /etc

You can also list the files in a subdirectory. For instance:

ls /etc/alsa

In addition, you can list files in multiple directories by separating their names with a space:

ls /etc /var

List Options

By default, the ls command lists files and directories in alphabetical order. This can be altered by appending the command with an option. For instance:

ls -t

This sorts them by time of creation or modification, with the most recent appearing first.

Other sorting options include -r (reverse alphabetical) and -S (file size).

Another useful option, to show the contents of subdirectories recursively, is:

ls -R

You might also want to see hidden files, such as those whose names start with a period (.). In which case, enter:

ls -a

To see more details for files and directories, in a long listing format, enter:

ls -l

This shows details including the file type, permissions, owner, group, size, date and time.

To see other available options, enter:

ls --help

For more information on all the options and how to use them, check out our full guide on how to use the ls command in Linux.



Comments


EmoticonEmoticon

Notification
This is just an example, you can fill it later with your own note.
Done