![]() |
![]() |
| Linux news | Newbie's Linux manual | Linux links | Link us | ||
| The Linux columns | Book reviews | ||
| DistroWatch + TuxReports | November 2, 2002 | |
Contents | Previous | Next | Download
Before going any further you need to know about command-switches.
Many commands have switches (sometimes called options, or flags). For instance, the command ls -al (list all files in long format) could take on any of the following forms:
ls -al
ls -la
ls -a -l
ls -l -a
Long-style switches, look as follows:
ls --color
This you could combine, to form something like:
ls -al --color mywork
ls
List contents of the current directory.
The colour of each filename signifies what it represents:
| Colour | Filetype | Notes |
| grey | regular file (usually a text file) | In a white background terminal window these filenames will appear black. |
| blue | directory | |
| green | executable | |
| cyan | symbolic link | Often referred to as a symlink. |
| red | archive | If an archive has an executable permission set it will appear green. |
| magenta | graphic | If a graphic has an executable permission set it will appear green. |
| yellow | block or character device | |
| brown | FIFO (named pipe) |
At beginner 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).
The concept of an executable, permissions, and an archive for those that don't know, will be dealt with later.
Advanced:
In rare instances, magenta can also signify a socket, and a red background and white blinking text can signify an orphan file --a symlink (a file that points to another file), to a nonexistent file.
ls /home
List contents of the /home directory.
ls -a
List all files in the current directory, i.e. including hidden files (sometimes called dot files).
Note:
To make a file/directory hidden, begin its name with a dot (.).
Note:
By entering ls -a, you'll notice that every directory contains the special directories: . and ..
These can be used in a command to denote the current and parent directory, respectively.
ls -l
List current directory in long format, displaying (from left to right): file type and permissions; number of hard links; owner name; group owner name; size in bytes; date file was last modified; file's name. (All explained later.)
Note:
-o is the same as -l but doesn't list group, i.e. owner only.
ls -lh ~/mywork
Same as above, but display the contents of the ~/mywork directory, and file sizes in bytes, kilobytes, megabytes, or gigabytes. (h stands for human readable.)
Further help:
Bytes, kilobytes, megabytes, gigabytes?
ls -R
List current directory and subdirectories, i.e. recursively (-R).
ls | less
Pipe (pass) the listing of the current directory to the less program, allowing you to scroll up and down a long listing.
| Less keys | |
| Down cursor | Down one line. |
| Up cursor | Up one line. |
| Page Down/Spacebar | Down one screen. |
| Page Up/b | Up one screen. |
| q | Quit. |
| h | Display help. |
ls -l /usr | less
Pipe listing of the /usr directory in long format, to the less program.
ls > list.txt
Either create or overwrite the file list.txt, with a redirected (>) listing of the current directory as file's content.
ls mydir >> list.txt
Either create or append to the file list.txt, a redirected (>>) listing of the mydir directory.
Note:
Text displayed to the screen by a command is called standard output, this you can redirect (> or >>) to a text file, or pipe (|) as standard input to another program. Standard input and output are called streams. The usual standard input is the keyboard.
All of the following ls examples, you'll rarely (if ever) use.
To any of the following, add r to reverse order.
ls -t
Sort by modification time, most recent first. Add l for long format.
ls -X
Sort alphabetically by file eXtension.
ls -Shl
Sort by Size (largest first), in human readable long format.
ls -1sSh
List one per line (1), displaying filesize, sorted by fileSize, in human readable form.
ls -1sXh
List one file per line (1), displaying filesize, sorted alphabetically by file eXtension, in human readable form.
ls -I "*.txt" -I "*.zip"
List current directory, Ignoring text and zip files.
Note:
The asterixes (*) shown above, is an example of wildcards. For details see the Wildcards chapter.
ls -F
List Filetype after filename:
| / | directory |
| * | executable |
| @ | symbolic link |
| = | socket |
| | | named pipe (FIFO) |
Note:
Since most Linux distributions now default to colour listings ( if not use: ls --color ), you'll likely only use this option for redirected listings, e.g.:
ls -F mydir > list.txt
ls -ld /usr
List in long format (-l), only the directory (-d) /usr and not its contents.
A handy command that displays a text depiction of a given directory's layout. It may be that you have to install this because it wasn't selected during installation.
tree
Display tree graph of current directory.
tree -d /home > hometree.txt
Display tree graph of /home directory, displaying directories only (-d), and redirect output (>) to hometree.txt.
clear
Clear the console, or terminal window.
Note:
You'll rarely use this command, since it's quicker just to press Ctrl+L. However you'll use it in scripts, multiple semi-colon separated commands, and aliases (all of which will be dealt with later).
pwd
Display current directory's absolute path.
Further Help:
What's an absolute and relative path?
Contents | Previous | Next | Download
| About us | |
| Latest stable kernel: 2.4.19 | Latest development kernel: 2.5.44 Copyright © 1998-2002 Linuxdot.org. Linux ® is a registered trademark of Linus Torvalds. |
|