list files in linux

How to List Files in Linux

LS command allows you to list files in Linux in many different ways such as by name, by date, by size, recursively within directories. Let us look at how to list files in Linux / Unix in different ways.

 

How to List Files in Linux / Unix

Here are different ways to list files in Linux / Unix.

 

List Files in Linux By Name

You can list files by name in Linux by simply issuing ls command in terminal.

$ ls
test.txt       sample.zip       file.js       app.css
test1.txt      dev.zip          document.jpg  app2.css

 

Bonus Read : How to Install Zip and Unzip in Linux

 

List Files in Linux By Date

You can list files by date in Linux by simply issuing ls -lt command in terminal.

$ ls -lt
total 115784
-rw-rw-r--  1 ubuntu ubuntu   232513 Feb 22 09:26 file.js
drwxr-xr-x 20 ubuntu ubuntu     4096 Jun  4  2018 modules
drwxrwxr-x  7 ubuntu ubuntu     4096 Jun  1  2018 Apps
drwxr-xr-x  3 root   root       4096 May  1  2016 oradiag_root
drwxr-xr-x  3 ubuntu ubuntu     4096 Apr  9  2016 oradiag_ubuntu


In the above command -l option lists all details of each file such as permissions, owner, date time, and file name. The -t option sorts the output by date, latest date first and oldest date last.

If you want to reverse the order of dates use -r option with -lt, that is, ls -lrt

If you also want to list hidden files, include -a option. If you want to display file size in human readable format such as kb, Mb and Gb include -h option.

~$ ls -halt
total 114M
-rw-------   1 ubuntu ubuntu 549K Aug 19 05:30 .mysql_history
-rw-------   1 ubuntu ubuntu  44K Aug 18 14:07 .bash_history
drwxrwxr-x   3 ubuntu ubuntu 4.0K Aug 17 14:25 .virtualenvs
-rw-------   1 root   root    40K Aug 16 11:15 .viminfo
-rw-r--r--   1 ubuntu ubuntu 5.2M Jul  5 05:29 supervisord.log
drwx------   7 ubuntu ubuntu 4.0K Apr  7 06:55 Dropbox
-rw-rw-r--   1 ubuntu ubuntu 228K Feb 22 09:26 file.js
...

 

Bonus Read : How to Get Disk Space in Linux

 

List Files in Linux By Size

You can list files in linux by size using -lS options. By default, linux will list files in decreasing order of size.

$ ls -lS
total 115784
-rw-rw-r--  1 ubuntu ubuntu 81565109 Sep  8  2019 bkp-2019-09-08.sql
-rw-r--r--  1 root   root   14518469 Mar 30  2019 myapp_Friday.gz
-rw-rw-r--  1 ubuntu ubuntu 11390945 Jan  5  2019 awscli-bundle.zip
-rw-r--r--  1 ubuntu ubuntu  5449604 Jul  5 05:29 supervisord.log
-rw-rw-r--  1 ubuntu ubuntu   232513 Feb 22 09:26 file.js
drwxr-xr-x 20 ubuntu ubuntu     4096 Jun  4  2018 node_modules
drwxr-xr-x  3 root   root       4096 May  1  2016 oradiag_root
drwxr-xr-x  3 ubuntu ubuntu     4096 Apr  9  2016 oradiag_ubuntu
drwxrwxr-x  7 ubuntu ubuntu     4096 Jun  1  2018 Apps
-rw-r--r--  1 root   root       1457 Jul 30 12:37 key.pem

 

List Files Recursively with Full Path

You can list files in linux recursively with full path using ls -R command. It will list each directory name and below each directory’s name, linux will list all the files present in that directory.

$ ls -R
.:
Dropbox  mysql_backup.sh  postit.sh  tweet_list  tweet.py App

./App:
Apps  bkp  blog.ods  Getting Started.pdf  Photos  Public

./Dropbox/Apps:
Crossbox

./Dropbox/Apps/Crossbox:


./Dropbox/Public:
How to use the Public folder.rtf

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

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

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!