Doctor Bob
Linux Topic
Search

 
TOURBUS
HOME PAGE
SAVVY
CONSUMER
FREE TECH
SUPPORT

LINUX 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 ]




Ask Bob Rankin - Free Tech Support
<Send This Link to a Friend>         <Help>         <Bookmark This Page>


Copyright © by Bob Rankin
All rights reserved - Redistribution is allowed only with permission.