How Do I List My Linux 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
Comments - most recent first
(Please feel free to answer questions posted by others!)
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
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
ls ./rose?
As for the numbering, I'm not sure...
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
thanks@@@@@@@@@@@@@@@@@
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
i've had previous ones too "rich" to understand
this is a new beginning for a lot of us
THNKX!
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!!
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é
I'm new to this, but enjoy your well written tutorials. Thank You,
Rich
thanks a lot
from China
thnx....
drwx-wx--T 2 root crontab 4096 2010-03-17 21:56 crontabs
What does T flag mean?
Good Evening,
Very interesting, informative, helpful
and Grate. Grateful to you,
Thanking you.
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.
Copyright © by -
All rights reserved - Redistribution is allowed only with permission.

