Listing files and directories
You can list the files and subdirectories in your current directory (the
one you are in at the moment) by entering ls and pressing
the Enter key.
[sparc03]...kaputnik>ls
letter.txt news bin hotstuff
mail work prog
[sparc03]...kaputnik>
The above list shows seven items in the directory. Some items are files
and some are directories, but from this list there is no way of telling
which are which. The ls command also does not normally
list hidden files. Listing hidden files is explained below.
Distinguishing files from directories and executables
To get a listing that distinguishes directories and executables from files,
use the -F option after the ls command. Using
the above example, the ls -F command would give the following
list
[sparc03]...kaputnik>ls -F
Letter.txt News/ bin/ HotStuff/
Mail/ Work/ prog*
[sparc03]...kaputnik>
The -F option displays a slash (/) after directories and an asterisk
(*) after executable files. From this list, you can see that
- Letter.txt is a file.
- prog is an executable file (a file you can run as a program).
- The other items are directories.
Getting information about the files
The -l option provides a long listing that displays the
- Unix file permissions
- File owners
- File sizes
- Modification dates
- File names
[sparc03]...kaputnik>ls -l
total 16
-rw-r--r-- 1 kaputnik 1753 Feb 10 09:55 Letter.txt
drwx------ 4 kaputnik 2048 Nov 8 11:12 Mail
drwxr-xr-x 3 kaputnik 2048 Jan 30 16:26 News
drwxr-xr-x 13 kaputnik 2048 Feb 10 09:52 Work
drwx------ 3 kaputnik 2048 Oct 27 09:47 bin
-rwx------ 2 kaputnik 9087 May 19 1992 prog
drwx------ 2 kaputnik 2048 May 19 1992 HotStuff
[sparc03]...kaputnik>
The dash at the beginning of the first line means that item is a file
and not a directory. The 'd' at the beginning of the second line identifies
that item as a directory. The string of characters following the dash or
'd' designates the security on the file: who can view or otherwise manipulate
the file. File security is explained in another section.
In the example above, kaputnik is the loginID of the file's owner. The
number preceding the date indicates how many bytes the file or directory
uses (the file's size). If the date is not one from the current year it
will include only the month and year. The last field is the file or directory
name.
Including both the -l and the -F options combines their
effects to produce a comprehensive long listing:
[sparc03]...kaputnik>ls -lF
total 16
-rw-r--r--- 1 kaputnik 1753 Feb 10 09:55 Letter.txt
drwx------- 4 kaputnik 2048 Nov 8 11:12 Mail/
drwxr-xr-x 3 kaputnik 2048 Jan 30 16:26 News/
drwxr-xr-x 13 kaputnik 2048 Feb 10 09:52 Work/
drwx------- 3 kaputnik 2048 Oct 27 09:47 bin/
-rwx------- 2 kaputnik 9087 May 19 1992 prog*
drwx------- 2 kaputnik 2048 May 19 1992 HotStuff/
[sparc03]...kaputnik>
Listing hidden files
A file or directory whose name begins with a period (as in ".login") is
known as hidden because commands such as ls don't normally
list them. Entering the command ls -a (which means list
all) will list hidden files and directories.
[sparc03]...kaputnik>ls -a
.login News
.mylogin Work
.mycshrc bin
Letter.txt HotStuff
Mail prog
[sparc03]...kaputnik>
Files that are 'hidden' are called dotfiles because they have a dot (period)
at the beginning. Although directories can be 'hidden' with a preceding
dot (as in the ".elm" directory), you'll rarely hear anyone talking about
dot-directories. This is because you don't usually alter a directory to
change the way a program functions; you change the files inside the directory.
Dotfiles typically establish personal settings for programs and your
Unix environment. For example, the ".mylogin" file is where you should
put certain customizations.
You can create problems for yourself if you delete a hidden file required
by the system or a program. Please read all sections of Customizing your account before you modify any
of your hidden files.
Entering the command ls -al lists all files in current
directory in a long list format.
Summary
ls list the contents of a directory (DOS equivalent is dir)
ls (quick list)
ls -l (detailed
list)
ls -a (includes hidden files)
ls -al (shows all files)
Last modified
July 20, 2004
by cawalker
|