How to List All Files in a Directory in Linux

Last updated on March 11th, 2021 at 09:33 am

Sometimes you may need to list all files in a directory in Linux, or list all files in directory recursively with full paths of files in directory. Here’s how to list all files in a directory in Linux

 

How to List All Files in a Directory in Linux

Here are the commands to list all files in a directory in Linux.

 

Here’s the command to list all files in a specific directory

$ ls /path/to/dir

 

Here’s an example to list all files and sub folders in a specific directory (e.g /home/products)

~$ ls /home/products
Apps  bkp  blog.ods  Getting Started.pdf  Photos  Public

 

Bonus Read : How to List Files in Linux

 

You can use the -a option to list all files in a directory including hidden files (starting with . filename)

$ ls -a /home/products
.   Apps  blog.ods  .dropbox.cache       Photos
..  bkp   .dropbox  Getting Started.pdf  Public

 

You can use the -l option to list all files in directory with more details such as user permissions, owners, file size, and last modified date

$ ls -l /home/products
total 476
drwxrwxr-x 3 ubuntu ubuntu   4096 Oct  7  2018 Apps
drwxrwxr-x 2 ubuntu ubuntu   4096 Aug 20 06:15 bkp
-rw-rw-r-- 1 ubuntu ubuntu 175560 Apr  6  2018 blog.ods
-rw-rw-r-- 1 ubuntu ubuntu 268860 Feb  5  2011 Getting Started.pdf
drwxrwxr-x 2 ubuntu ubuntu   4096 Oct  7  2018 Photos
drwxrwxr-x 2 ubuntu ubuntu   4096 Oct  7  2018 Public

 

Bonus Read : How to Install Zip and Unzip in Linux

 

You can list all files in a directory recursively using -R option

$ ls -R /home/products
/home/products/:
Apps  bkp  blog.ods  Getting Started.pdf  Photos  Public

/home/products/Apps:
Crossbox

/home/products/Apps/Crossbox:

/home/products/bkp:
an_blog_file.gz  fed_file.gz      myapp_Saturday.gz  myapp_Tuesday.gz
blog_file.gz     myapp_Friday.gz  myapp_Sunday.gz    myapp_Wednesday.gz
db_blog_file.gz  myapp_Monday.gz  myapp_Thursday.gz  wb_blog_file.gz

/home/products/Photos:
How to use the Photos folder.rtf

/home/products/Public:
How to use the Public folder.rtf

 

Hopefully, now you can easily list files in directory Linux / Unix.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!