Linux Classes
Share This With a Friend  
LINUX CLASSES - FILES

How Do I List My Linux Files?

Listing Files

The ls command lists the names of all (or selected) files in a directory, and tells you about the attributes of those files. Here are some examples: ls lists the files in the current directory.

ls recipes lists the files in another directory using relative addressing.

ls /usr/bin lists the files in another directory using absolute addressing.

By default, ls prints a simple, columnar list of your files; but it will list your files in many different formats if you add one or more flags on the command line. To use any of them, simply type the ls command at the prompt, followed by a space, and then add a switch by typing a hyphen followed by the flag, like this:

$ ls -F

Here are some of the most commonly used ls flags:

a Lists all files, including hidden ones.

l Displays the file list in long format, including file details like size, time stamp, and owner.

F Adds a slash after the name for directories, an asterisk for executables, and an at sign (@) for linked files.

r Reverses the sort order (alphabetic or time).

t Sorts the list by the time each file was created.

Here's a look at the contents of a directory named animals, using some of these flags:

$ ls -F animals
cat_info cow_info dog_info
pig_info slugs/ zippity*

In this case, ls returns just the file names in columnar format, but with a few marks, thanks to the -F flag. The slash suffix on slugs indicates that it is a directory, and zippity is identified as an executable.

$ ls -al animals
-rw-r--r-- 1 hermie users 1758 Mar 17 23:17 .hoohah
-rw-r--r-- 1 hermie users 45090 Mar 23 23:17 cat_info
-rw-r--r-- 1 hermie users 64183 Feb 14 22:07 cow_info
-rw-r--r-- 1 hermie users 115032 Jan 06 11:14 dog_info
-rw-r--r-- 1 hermie users 248 Jan 16 09:18 pig_info
drwxr-xr-x 1 hermie users 1024 Feb 28 06:12 slugs
-rwxr-xr-x 1 hermie users 45198 Jan 23 11:14 zippity

Here, ls has displayed all files in the animals directory, including the hidden hoohah file. In addition to the file name, the file's permissions, owner, group, size in bytes, and date and time of last modification are displayed. (More on permissions later in this section.)

$ ls -lrt animals
-rw-r--r-- 1 hermie users 115032 Jan 06 11:14 dog_info
-rw-r--r-- 1 hermie users 248 Jan 16 09:18 pig_info
-rwxr-xr-x 1 hermie users 45198 Jan 23 11:14 zippity
-rw-r--r-- 1 hermie users 64183 Feb 14 22:07 cow_info
drwxr-xr-x 1 hermie users 1024 Feb 28 06:12 slugs
-rw-r--r-- 1 hermie users 45090 Mar 23 23:17 cat_info

This time, the files are sorted by time stamp, in reverse order. If you have lots of files in a directory, this is a handy way to find out which are the oldest and newest. Also notice that the -l, -r, and -t switches were combined into -lrt in the preceding command. We could just as well have issued the command ls -l -r -t animals.

Previous Lesson: Navigating the File System
Next Lesson: Displaying Linux Files

[ RETURN TO INDEX ]


   

Comments - most recent first
(Please feel free to answer questions posted by others!)

Phantom     (08 Aug 2013, 01:18)
Hi Guys,

Can anyone help on me on how to copy files based on a list to another directory appending its timestamp
Ruan     (26 Oct 2012, 09:49)
Hi
I have files that are date stamped, e.g.
file_201201
file_201202
file_201203
file_201204....

I only want to list files for a specific date range, e.g.
list files between 201203 and 201206.

Is it possible to do this, and if so what is the command?

Thanks
Glenn     (30 Aug 2012, 17:53)
Thank you very much for taking the time for this tutorial. It is very helpful and very selfless of you for this service. People need to be more thoughtful and mindful of your time before asking you to send them this tutorial by mail.
kirti     (06 Aug 2012, 08:33)
Can you please the faster way to list files in linux.

Example: I hv millions of file in a directory. What will be the faster wait to list those file ?? I mean to say which command will give me the output very FAST.

Thanks,
Kirti
theo     (12 Jan 2012, 09:53)
In answer to Nara's question, I would like to suggest the following method:

ls ./rose?

As for the numbering, I'm not sure...
Fred     (20 Dec 2011, 18:06)
I need help with this question

Given these files


-r--r--r-- 1 student users 88 2006-12-03 08:01 final_a
drwxr-xr-x 2 student users 4096 2006-12-03 08:00 final_b
-rw-r-xr-x 1 student users 0 2006-12-03 08:00 final_c
Yogesh     (15 Nov 2011, 12:22)
the good place to lern linux(Red Hat)

thanks@@@@@@@@@@@@@@@@@
W Dean     (04 Oct 2011, 20:34)
ls -t does not use creation time, but modification time. Do you know any way to get ls to display the creation time? (Neither do I. I used to have a binary . . .)
Nara     (01 Sep 2011, 05:33)
Im new to Linux and was wondering if i can get some help on smething.
I want a command to display contents in a folder that match a string and i came up with this "ls -F $DIRECTORY" where $DIRECTORY is the directory entered by user to search for the files from but i want to display only files called "rose1 rose2 rose3 etc" in that folder and it has to be displayed vertically and numbered as
1 rose1
2 rose2
3 rose3

im lost here and thus dont know wat to do..
Please help
Mike     (01 Jun 2011, 16:44)
excellent tutorials, the cream of the crop
i've had previous ones too "rich" to understand
this is a new beginning for a lot of us
THNKX!
Anand     (25 May 2011, 07:37)
Very Very useful to the linux beginners.
Apple     (04 Mar 2011, 09:36)
Good morning Sir,

These are very helpful lessons!
I have two questions: how can i only list the most recent 10 files? how can i only list files that are executable? Thanks so much!!
Jay     (26 Feb 2011, 15:23)
A Brilliant Help. Can't thank you enough. The language is almost as if to give the user a live experience. \m/
miss K     (26 Jan 2011, 16:27)
Wow! I can finally understand this. I have been studying Linux in college for my degree,and the textbook might as well be written in a foreign language. Thank you Doctor Bob for making it simple for me I may be able to keep up my GPA now!
Dave M.     (19 Jan 2011, 00:02)
I am trying to save a file onto my laptop that I can access at a later time with a program like "Ultra Edit" is this possible. The file is an operating file for a modem. the reason I wish to do this is to compare a couple of different versions of the same s/ware. Please help!!!
rene     (16 Jan 2011, 10:07)
Hi there,

I'm looking for a command that lists al filenames on my disk (recursive). My goal is to spot bad characters and rename those files. So the path should be included.

Thank,
René
Rich     (31 Dec 2010, 14:24)
Hi Bob,
I'm new to this, but enjoy your well written tutorials. Thank You,
Rich
trakglurtaink     (26 Dec 2010, 13:09)
2.8 engine ford 95 mazda protege lx twt car fabric shop lincoln hyundai forum elantra
loonglovehu     (23 Oct 2010, 10:30)
a good place to learn linux(ubuntu)
thanks a lot
from China
Bob Rankin     (06 Sep 2010, 09:43)
@Charles - Ummm, I don't know! From the help info, it sure looks like it should.
Charles     (27 Aug 2010, 17:50)
If you don't mind me asking, why does ls -R *sh not list all the files in current and sub-directories that end in sh?
Bob Rankin     (17 Aug 2010, 10:09)
@Gurkin - Sounds like the stick bit. See http://en.wikipedia.org/wiki/Sticky_bit
Raman     (17 Aug 2010, 06:10)
These lessons are really helpful...
thnx....
Gurkin Max     (19 Apr 2010, 13:39)
I have listed files attribute for /var/spool/cron/crontab :
drwx-wx--T 2 root crontab 4096 2010-03-17 21:56 crontabs
What does T flag mean?
Pawan Kumar G     (16 Apr 2010, 05:55)
Sir,
Good Evening,

Very interesting, informative, helpful
and Grate. Grateful to you,
Thanking you.
AJITH KUMAR G     (27 Feb 2010, 10:32)
Sir,
Good Evening,

Very interesting, informative, helpful
and Grate. Grateful to you,
Thanking you.


I welcome your comments. However... I am puzzled by many people who say "Please send me the Linux tutorial." This website *is* your Linux Tutorial! Read everything here, learn all you can, ask questions if you like. But don't ask me to send what you already have. :-)

NO SPAM! If you post garbage, it will be deleted, and you will be banned.
*Name:
Email:
Notify me about new comments on this page
Hide my email
*Text:
 
 


Ask Bob Rankin - Free Tech Support


Copyright © by - Privacy Policy
All rights reserved - Redistribution is allowed only with permission.