LinuxMall.com Got Linux? CD Offer
Newbie's Linux Manual
Command Tutorial #1: cd & ls
by Laurence Hunter
[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip
Welcome to Super-DOS!

That thing that looks like MS-DOS is a Linux terminal (sometimes called a "console"). It's here that all Linux commands are entered. If you're familiar with DOS, then get ready for Super-DOS!

About Paths

Whenever I mention a path, I'm speaking about the route taken to get to a file or directory. (Don't confuse this with PATH which is an "environment variable" - discussed later.)

One thing I should mention - to prevent confusion - is that drive letters don't exist in Linux. There is no A:, C: or D:, only the root directory (/), which contains everything else. You'll also notice that the backslash (\) is never used in Linux, only the forward-slash (/).

Absolute And Relative Paths

We'll be using a file later called fstab. The absolute path to this file is /etc/fstab or in plain English:

"You'll find the fstab file in the etc directory which (like everything else) is in the root directory."

A relative path means just that, relative to the current directory. You can always tell a relative path because it never starts with a /. If you were in /etc and wanted to move to the directory /etc/defaults then instead of entering the absolute path:

cd /etc/defaults

...it's quicker just to enter the relative path:

cd defaults

Ok, now that you have some fundamental knowledge of paths, it's time to learn the two most important commands, cd and ls.

cd - change directory

Examples

cd
Move to home directory of the account you're logged into, e.g. /home/guest.


cd -
Move back to previous directory you were in.


cd ..
Move up to the parent directory, i.e. the directory that holds the directory you're currently in.


cd /usr/docs
Move to the directory docs, which is contained in the directory usr, which like everything else, is contained in the root directory (/).


cd reports
Move to the directory reports, contained in the directory you're currently in.

ls - list [a directory]

Examples

ls
Display the contents of the directory you're currently in.


ls -a
Display every file and directory in the current directory (i.e. including "hidden" files and directories).

Note

To make a file or directory "hidden", begin its name with a ".".


ls -l
Display the files in the current directory, including (from left to right): the file type; permissions; the number of hard links; the owner name; the group name; the size in bytes; and the date the file was last saved.

Note

To combine the above two examples you would enter: ls -al


ls --color
Display the current directory's contents in colour, to indicate what each item represents.

+------------+---------------+
| grey       | regular file  | (often a text file)
+------------+---------------+
| dark blue  | directory     |
+------------+---------------+
| green      | executable    |
+------------+---------------+
| light blue | symbolic link |
+------------+---------------+
| yellow     | socket        |
+------------+---------------+
| brown      | FIFO          |
+------------+---------------+

ls | less
Pipe (pass) the listing of the current directory to the less program, allowing you to scroll up and down a long listing. (That | character is called a "pipe".)

Less Keys

Down cursor = Down 1 line.
Up cursor   = Up 1 line.
Spacebar    = Down 1 screen.
b           = Back up 1 screen.
q           = Quit.
h           = Activate help screen.

ls -l /usr | less
Pipe the listing of the /usr directory (passing all file details (-l)), to the less program.


ls > list.of.files
Either create or overwrite the file list.of.files, with a redirected (>) listing of the current directory, as the file's content.


ls >> list.of.files
The same as above, except this time the listing is appended to the end of the file list.of.files.

[ Home ] [ Contents ] [ Download*] [ Previous ] [ Next ]
* In Linux enter: unzip nlm.zip

W W W . L I N U X D O T . O R G

The Newbie's Linux Manual is reproduced on LinuxMall.com by permission. The Newbie's Linux Manual is written and maintained by Laurence Hunter. You can find much more of Laurence's work at his site: www.Linuxdot.org

© 1999 Linuxdot.org | Manual's Copyright Terms