Listing files

To list files in a directory, you can use the ls command. There are multiple

ways of invoking this command. By default, if you type ls without any

arguments, the command will present a list of all files in the current

directory.

For example:

root@deepOfix:~# cd / <ENTER>

root@deepOfix:/# ls <ENTER>

bin boot cdrom dev etc home initrd lib media mnt opt proc root sbin srv sys tmp usr var

As you can see, this lists the contents of the root directory. However,

this does not tell about the details of the files - who owns the file or

directory, what is their size, when was it last modified and so on. To see all

this information about the listed files and directories, you can use the

ls command with the -l switch:

root@deepOfix:~# cd /usr/share/common-licenses/ <ENTER>

root@deepOfix:/usr/share/common-licenses# ls -l <ENTER>

total 88

-rw-r–r– 1 root root 6111 1996-12-16 08:28 Artistic

-rw-r–r– 1 root root 1499 1999-08-26 17:36 BSD

-rw-r–r– 1 root root 17992 1999-09-16 23:14 GPL-2

-rw-r–r– 1 root root 25284 2000-02-02 22:11 LGPL-2

-rw-r–r– 1 root root 26528 2003-07-21 20:25 LGPL-2.1

  • The first column in this listing shows the permissions of the file.(File permissions are discussed later on in this article.)
  • The third and fourth columns specify the user and group which owns the file.
  • The fifth column is the size of the file (in bytes).
  • The sixth and seventh columns shows the last modified date and time of the file respectively.
  • The last column shows the exact name of the file.

The second column can be ignored at present.

You can also provide ls with the name of the directory to list.

root@deepOfix:/usr/share/common-licenses# ls / <ENTER>

bin boot cdrom dev etc home initrd lib media mnt opt proc root sbin srv sys tmp usr var

You can also use wildcards when listing files. To list all files in the

`/bin directory that start with the letter z, you can use:

root@deepOfix:~# ls -l /bin/z*

-rwxr-xr-x 4 root root 53676 2005-05-21 10:31 /bin/zcat

-rwxr-xr-x 2 root root 1974 2005-05-21 10:31 /bin/zcmp

-rwxr-xr-x 2 root root 1974 2005-05-21 10:31 /bin/zdiff

-rwxr-xr-x 3 root root 3030 2005-05-21 10:31 /bin/zegrep

-rwxr-xr-x 3 root root 3030 2005-05-21 10:31 /bin/zfgrep

-rwxr-xr-x 1 root root 1525 2005-05-21 10:31 /bin/zforce

-rwxr-xr-x 3 root root 3030 2005-05-21 10:31 /bin/zgrep

-rwxr-xr-x 1 root root 103 2005-05-21 10:31 /bin/zless

-rwxr-xr-x 1 root root 1886 2005-05-21 10:31 /bin/zmore

-rwxr-xr-x 1 root root 3518 2005-05-21 10:31 /bin/znew

The actual output of these command on your server might differ.

 
help/command-line/listing-files.txt · Last modified: 2009/07/24 02:08 by gaurav     Back to top