-->
Previous Table of Contents Next


If you installed the Slackware distribution of Linux, you’ll find ls also provides color output for each file type. The color definitions are defined in the configuration file DIR_COLORS in the /etc directory. The default configuration highlights executable files in green, directories in blue, and symbolic links in cyan. To customize the colors, you must copy the DIR_COLORS file to your home directory and change its name to .dir colors. Table 17.2 provides the color definitions available; see the man pages and the DIR_COLORS file for more information.

Table 17.2 DIR_COLORS Values for Creating Color Highlighting

Value Description

0 Restores default color
1 For brighter colors
4 For underlined text
5 For flashing text
30 For black foreground
31 For red foreground
32 For green foreground
33 For yellow (or brown) foreground
34 For blue foreground
35 For purple foreground
36 For cyan foreground
37 For white (or gray) foreground
40 For black background
41 For red background
42 For green background
43 For yellow (or brown) background
44 For blue background
45 For purple background
46 For cyan background
47 For white (or gray) background


NOTE:  For the Red Hat distribution, you must type ls –-color to get the color effect.

More options are available than those shown here. To find them, consult the man pages for ls.

Organizing Files

There are no fixed rules for organizing files in Linux. Files don’t have extensions (such as .EXE for executables) as they do in MS-DOS. You can (and perhaps should) make up your own system of naming files, but the classic system of organizing files in Linux is with subdirectories.

More and more, however, Linux applications that have come from the DOS world are bringing their conventions to Linux. Although they may not require it, vendors encourage you to name files that you use with their applications with certain extensions.

If you’re going to write your own commands, a useful way to organize your directories is to mimic Linux’s use of the /bin, /lib, and /etc directories. Create your own structure of subdirectories with these names, perhaps under your /home directory, and follow the Linux tradition of placing executable commands in your /bin directory, subsidiary commands in your /lib directory, and initialization files in your /etc directory. Of course, you aren’t required to do this, but it’s one way of organizing your files.

You create directories with the mkdir command. Its syntax is simple:


mkdir directory-name

In this syntax, directory-name represents the name you want to assign to the new directory. Of course, you must have write permission in the directory in order to create a subdirectory with mkdir, but if you’re making a subdirectory within your home directory, you should have no problem.

Suppose you’ve written three programs called prog1, prog2, and prog3, all of which are found in $HOME/bin. Remember that $HOME is your home directory. If you want your private programs to run as though they were a standard part of the Linux command set, you must add $HOME/bin to your PATH environment variable. To do so, you would use the following command in the Bourne or Korn shell:


PATH=$PATH:$HOME/bin;export PATH

In the C shell, you would use this command:


setenv PATH “$PATH $HOME/bin”


NOTE:  Remember that $HOME is the placeholder for the complete path that refers to your home directory. If your home directory is /home/ams, $HOME/bin is interpreted as /home/ams/bin.

If your programs call subsidiary programs, you may want to create subdirectories within your $HOME/lib directory. You can create a subdirectory for each program. The private command pgm1 can then explicitly call, for example, $HOME/lib/pgm1/pgm1a.

Similarly, if your command prog1 requires a startup table, you can name that table $HOME/etc/pgm1.rc; your data can be in your $HOME/data/pgm1 directory.

Copying Files

The command for copying files is cp from to. You must have read permission for the file you’re copying from and write permission for the directory you’re copying to (and the file if you’re overwriting an existing file). Other than that, you are not restricted when it comes to copying files.

You need to watch for a few things as you copy files:

  If you copy a file and give it the name of a file that already exists and that you have write permission for, you’ll overwrite the original file.
  If you give the name of a directory as the destination of the cp command, the file is copied into that directory with its original name. For example, if you type the command cp file directory, the file is copied into directory as directory/file.
  You can copy a list of files into a directory with the command cp file1 file2 file3 … directory. If the last item in the list isn’t a directory, an error message appears. Likewise, if any element in the list other than the last item is only a directory, an error message appears.
  Be careful when you use wildcards with the cp command because you can accidentally copy more than you intend to.


NOTE:  Because many Linux users also have MS-DOS files on their systems and usually make the DOS file system accessible from Linux, most of the Linux commands recognize when a file is being copied to or from a DOS partition. Thus, Linux can handle the necessary file translation when copying files. This translation is required because most DOS files embed the carriage return/line-feed characters into an ASCII file to indicate a line break. Most Linux and UNIX systems embed only a line-feed character, called newline, in the file to indicate a line break.


Previous Table of Contents Next