Thursday, 1 January 2009

ls Lists the files in a directory

The ‘ls’ command is used to list the files in a directory. This is similar to the Microsoft ‘dir’ command, but far more powerful. As all hardware, memory etc are treated as a file in *NIX, any device can be accessed as a file – if you know where it is and have the correct permissions.

ls –l
This is a command to list file entries using the 'long format'. This information is valuable. IT includes the file permissions, the size of the file, the file owner and group and it displays the time when the file was last modified. The last modified time is important to note as a change may quickly alter a vigilant system administrator to a change.

ls -a
This command option will list all files – even the hidden ones. In *NIX, a file is “hidden” similar to a Windows hidden file attribute through having a name that starts with a “.” Or full-stop.

ls -r
The “r” flag instructs the ‘ls’ command to display its output in reverse order.

ls –t
The “t” flag instructs the ‘ls’ command to display its output in order of the file timestamp. This allows you to quickly find all files that have been changed in a selected period.

Used together, these options can help you find all of the files in a directory that have been changed within the time that you have been logged into a host. For example, the command combination, ‘ls –altr | pg’ will output all of the files in the current directory in the order of timestamps starting with the most recently altered or added files and working to the oldest. Further, by piping the ‘pg’ (page) command to ‘ls’ you can see the output a single screen (page) at a time (rather than having this scroll past you faster than you can read it).

No comments: