Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

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

Newbie's Linux Manual
Command Tutorial #1: cd & ls
] [ Download*] [ Previous] [ Next] Home] [ Contents] [ Download*] [ Previous] [ Next] Homepage| The Last 5 Days| The Daily Linux News| The Linux Bits| Newbie's Linux Manual
The Best Linux Sites| Linux Book Reviews| A Windows Vendetta?
Diary of a Linux Newbie| Diary of an Open Source Newbie
The Linux Forum| Just For Fun Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy! Webmaster| Manual's Copyright Terms
[
* In Linux enter: unzip nlm.zip
About Paths

Whenever I mention a 'path', I'm speaking about the route taken to get to a file or directory. There are two types of path: an 'absolute path'; and a 'relative path'.

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."

'Absolute' means it starts from 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 [path] - change directory

Examples:

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 your current directory.


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


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


cd -
Move back to previous directory you were in.

ls [options] [path] - list

Examples:

ls
List the contents of your current directory.


ls /home
List the contents of the /home directory.


ls -a
List all files and directories in your current directory (i.e. including 'hidden' files and directories).

Note:

To make a file or directory 'hidden', begin its name with a dot (.).


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 (usually a text file)
dark blue directory
green executable
light blue symbolic link
yellow block device or character device
brown FIFO (named pipe)
magenta socket
Note:

At newbie level you do not need to know about FIFOs and sockets, and only require limited understanding of block and character devices (used to access hardware). Symbolic links are sort of like 'shortcuts' in Windows.


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.

[
* In Linux enter: unzip nlm.zip
© MM Linuxdot.org |