Site hosted by Angelfire.com: Build your free website today!

"But what … is it good for?" – Engineer at the Advance Computing Systems Division of IBM, 1968, commenting on the microchip.

Operating Systems

File Systems

Goals

When you complete this section you will be able to:

  1. Discuss the file naming conventions used by DOS, Linux, and Windows
  2. Navigate through several directories using DOS, Linux, and Windows
  3. Describe the file attributes used by DOS, Linux, and Windows
  4. Demonstrate various directory and file manipulation techniques using DOS, Linux, and Windows
  5. Describe the method used by DOS and Linux to allocate disk space for files
  6. Discuss cross linking and lost clusters and how scandisk repairs these problems

Lessons

Theory - This file contains the background and theory you'll need to successfully complete the lab exercises for this lesson. You should read this first.

DOS Lab - This is the Disk Operating System (DOS) lab manual. It contains activities and exercises to help you understand the theory as it applies to DOS.

Windows 98 Lab - This is the Windows 98 lab manual. It contains activities and exercises to help you understand the theory as it applies to Windows 98.

Windows XP Lab - This is the Windows XP lab manual. It contains activities and exercises to help you understand the theory as it applies to Windows XP.

Linux Lab - This is the Linux lab manual. It contains activities and exercises to help you understand the theory as it applies to Linux.

Skill Check - This set of questions will quiz your understanding of the operating system theory and practice presented in this lesson.

Challenge - This set of advanced lab exercises is designed to help you apply your understanding to new challenges.

Introduction

This section covers the way operating systems handle files. It is important that an operating system stores files on a hard drive in such a way that they can be recovered again. In this lesson, you'll learn how that happens.


Theory

This section is the longest - and most involved - in this tutorial. In this chapter you will learn how to manipulate directories and files. More importantly, you will learn how an operating system manipulates these structures. The challenge is significant - but when you finish this work you will have a much better understanding of file and directory systems. Besides, I needed something to fill out this book.

Naming

File names are merely ways for a human to identify a specific set of bytes on a computer’s hard drive. Let’s face it, the computer doesn’t need file names - it only needs to know where that set of bytes starts and ends. It’s humans who need a "name crutch."

Over time, the programmers for various operating systems have devised rules for file names on their system. Unlike a lot of human activities, you can’t break the rules for file names or the operating system won’t be able to store (or retrieve) the file. While you may want your income tax file to go away, when the IRS calls you’ll be glad to get it back - so follow the rules when you name the file.

DOS

With DOS, a file name is restricted to eight characters, a "dot," and a three-character extension. This scheme is often called the "8.3" file name rule. (Note: with the DOS that’s built into Windows 95 and Windows 98, file names can be as long as 255 characters - but for this book we’ll consider file names as they are defined in a pure DOS environment.)

DOS is not case sensitive, so George.txt, george.txt, and gEoRgE.TxT are all the same name. Do not use a space or any of the following characters in a file name:

: " / \ | < > * ?

These file names are legal (note, the last name does not have an extension - this is legal in DOS):

These file names are not legal:

The file extension often indicates the type of data contained in the file. The following table lists typical file extensions found in DOS (though certainly not all of them).

Extension Meaning
file.asc An ASCII text file
file.bak A backup file
file.bat A batch file (a simple program)
file.bmp A bitmap file (a picture)
file.com A command file (a program)
file.dll A dynamic link library (used by programs)
file.doc A Word document
file.exe An executable file (a program)
file.ini A program's initialization file
file.log A log (or record) of some program's activity
file.pif A Program Information File (used by Windows when starting DOS programs)
file.sys A system file (helps initialize system settings)
file.tmp A temporary file
file.txt A text file
file.xls An Excel spreadsheet

You may wonder what the heck all those tildes ("~") are doing in the filenames on your computer. (You have probably never typed that character in your life. Do you even know where it is on the keyboard?) Windows 95 and 98 permits long filenames (up to 255 characters), but DOS cannot handle filenames that long. Therefore, Windows provides an alias (or "fake name") for files where the first six letters of the file name are combined with a tilde and a number. Windows also changes the name to all uppercase and then appends the file extension. If two files happen to end up with the same name in a directory, then Windows increments the number in order to create unique names for every file. For example:

Windows Name DOS Name
CorporateJet.doc CORPOR~1.DOC
CorporateLogo.bmp CORPOR~1.BMP
CorporateExpensives.xls CORPOR~1.XLS
CorporateBoard.doc CORPOR~2.DOC
CorporateSecrets.doc CORPOR~3.DOC
JoeStreeter.doc JOESTR~1.DOC

Linux

In Linux, file names can be up to 255 characters and can contain any letter, number, or symbol on the keyboard. While Linux does not require the use of a file extension (like DOS), certain programs expect specific extensions, so they have been commonly adapted for use in Linux.

While any symbol can be used in a filename, you would be wise to avoid some symbols since they have a special meaning to the Linux system (reminds me of special places I avoid - but I digress). For example, the symbol * is a "wildcard" character used for searching for a specific file. While you could name a file "my*file" you would then have problems finding that file in a search. You’ll find most Linux filenames are composed of letters, numbers, and only the underscore ("_"), period (".") and comma (",") symbols. This set will give you plenty of naming possibilities and not run the risk of creating a hard-to-find file name.

Linux filenames are also case sensitive. That means the names George.txt, george.txt, and gEoRgE.TxT are all different files. You’ll find one trick that Linux programmers use is to insert upper-case letters in a filename to make it easier to read, like: MyVacationPhotos or GeorgesLastResume. (Oops, better not lose that file - I may need it again.)

The file extension often indicates the type of data contained in the file. The following table lists typical file extensions found in Linux.

Extension Meaning
file.bak A backup file
file.bas A Basic program source code
file.bin An executable binary program
file.c A C program source code file
fle.dat A data file
file.doc A documentation file
file.hlp A help file
file.lib A library file used by a program linker
file.man A manual page (a type of help file)
file.obj An object file (compiler output)
file.tex Input for the TEX program
file.txt A text file

You may be interested to know that in Linux if you start a filename with a period then that name will be hidden when you list the contents of a directory. This is not a security feature since the command line that lists the filenames has an option to see all the hidden files as well. However, if you can hide the names of all the system files then you can find those you have created much quicker.

Windows

In windows, filenames can be up to 255 characters but, like DOS, cannot contain the following:

: “ / \ | < > * ?

Windows filenames are case sensitive. That means the names George.txt, george.txt, and gEoRgE.TxT are all different files. Windows files use the same extensions as those found in DOS, so you may want to take a look at the table of those extensions found a bit earlier in this document.

Navigation

Imagine two students. One is very well organized and carefully files away notes at the end of each day’s lecture. That student’s desk is never cluttered and papers are always where they belong. (Kind-a makes you sick, doesn’t it?) The other student is more like me - think “slob.” If I needed to find last month’s rent receipt I would dig for several hours on my desktop hoping to catch a glimpse of the coffee-stained document - but my neat-nick buddy would just look in the “rent” folder and have the receipt in about 30 seconds. (Kind-a makes you sick, doesn’t it?)

Every operating system organizes electronic files in some sort of container, usually called a “directory” (though Microsoft chose to call their containers “folders”). Moreover, every disk must have a “master directory” that contains all other directories. This organization is for the sake of humans who must try to find a given file. For example, if you had a word processing file named CongoHistory but just had all your files in a single large location (like the rent receipt on my desk) it may take you a long time to find your history file. However, if you organize your word processing files so that all the history files are in a container called “history” then the CongoHistory file would be much easier to find.

The “master directory” mentioned above is usually called the “root directory”. From the root, all other directories are built and all files are stored. As we begin to navigate around a disk you’ll often find yourself looking at the root directory. If you don’t quite understand the concept of “root directory” don’t worry about it yet. As you work with the disk in the exercises below the concept of “root directory” should become clearer. (I wonder, if you made a copy of the root directory could you call that the “square root?”)

There is one other important directory: the “working directory.” A hard disk is full of directories (perhaps dozens of ‘em on even a small system), but you can access only one at a time. The directory you are currently working with is called the “working directory.” It’s easy to change the working directory; in fact, changing the working directory is a routine practice as you work with files. Why should you worry about the “working directory?” Any commands you issue will effect the working directory and no others. For example, if you ask the operating system to list the files so you can see what’s there, it will list only the files in the working directory. You should note that sometimes the “working directory” is called the “current directory.”

Linking

Because of the way Linux works, you can link two or more files. This is not possible with DOS or Windows so the concept may be a bit foreign at first. However, linking adds a great potential to the operating system. (To be fair, Windows does permit you to create “shortcuts” - which are something like links. However, linking can take place across several different file systems and even over the Internet so it is a more powerful utility than shortcuts.)

With Linux, suppose you have a file called salary.txt in your home directory. You would like Bill to be able to access that file and even work on it if he chooses. However, Bill may get tired of constantly navigating through the Linux system to find your file. To make things easier for Bill, he can create a link to your file in his home directory. Then, whenever he opens the file in his home directory with vi, it will actually open the file that exists in your home directory. Bill will never actually have a copy of the file in his directory – he’ll be linked to your file. This way, you won’t end up with multiple copies of a file – and no one knowing which is the most accurate. Linking leads to some very interesting collaborative writing possibilities.

To create a link to a file, use this command:

ln existing-file new-link

For example, if George had a file called money.txt, Martha could link to that file with this type of command:

ln home/george/money.txt finance

Martha would then end up with a file on her computer called finance – but if she opened that file with vi she would actually be editing the file on George’s computer called money.txt.

You may be interested to know that in the last example (George and Martha), if George deleted money.txt from his home directory, the file would not just disappear. George would no longer have a copy of the file, but Martha’s link would change so she would become the owner of the file and it would exist in her home directory with the name finance. To actually delete a file in Linux you also have to delete all links to the file.

File Allocation

The operating system must have a method of keeping track of file locations. Without this, a new file could overwrite an existing file and you’d end up with a real mess. You’ll find DOS/Windows and Linux use two very different methods to keep track of files.

DOS/Windows Method

For simplicity, I will only use the term DOS in this section; however, DOS and Windows share the same file allocation method. Of course, you would expect that since Windows is based on DOS.

With DOS, a directory entry contains this information for each file:

You no doubt already knew that the directory kept the file names - and it isn’t too tough to figure out what those other elements are - but what the heck is this “pointer to FAT” thing?

When you create a new file, DOS must find a spot for that file on the hard drive (duh!). You may already know that the hard drive is divided into numerous “allocation units” - or places to store in information. (If you don’t mind, I’ll refer to “Allocation Units” as AUs - this will save me several seconds of typing and a second saved is a second earned (or something).) If you create a new Word document that needs five AUs for storage, DOS will find five empty spots for your file - but then it’s important for DOS to remember exactly which units were used to store the file or it would be lost forever (rather like some of the stuff I have in boxes in a storage shed I rent).

To help recover stored files, DOS maintains a File Allocation Table (usually abbreviate “FAT”) that has an entry for every allocation unit on the disk - something like a table of pointers to allocation units. Using the information in the FAT, DOS can recover the file whenever needed. The FAT also records information about any allocation units that should not be used because they are reserved or damaged. The FAT is so important that DOS keeps two copies so if one gets damaged the backup can be used. If both copies of the FAT get damaged the entire disk becomes trash! (Be sure to offer a FAT sacrifice to the gods from time to time.)

The figures below will help you figure out what’s going on in the FAT.

Directory
File Name First AU
fileone 1
filetwo 4
filethree 12
filefour 6
filefive 10

The first is a representation of a directory table for your disk. Notice you have five files stored on the disk and the directory notes certain information about each file. Of course, not all the information is in my example table - just the file name and a pointer to the first allocation unit (that keeps this example simple enough for me to follow).

File Allocation Table (FAT)
AU Number Next AU
1 2
2 8
3 X
4 5
5 17
6 7
7 11
8 0
9  
10 13
11 15
12 0
13 0
14  
15 0
16  
17 18
18 19
19 0
20 X

In this simple File Allocation Table (FAT) you'll notice that each of the AUs include a pointer to the next AU in order. To find a file, DOS follows the directory’s pointer to the File Allocation Table to find out where the requested file starts. For fileone, you’ll notice that the directory points to AU one and the FAT shows the next AU used by this file is number two. The FAT then shows that AU number two is linked to AU number eight. Finally, AU number eight is linked to zero - or the end of the chain. To recover fileone, DOS would get the first part of the file from AU one, then the next part from AU two, and then the last part from AU eight. These three allocation units are linked in the FAT so a single file can be recovered. Pretty neat, isn’t it?

The FAT also lists AUs that cannot be used. You’ll notice that AU 3 and AU 20 have an “X” in the FAT. This tells the FAT that these AUs are unusable for some reason.

Finally, DOS uses the FAT to determine where to store the next file. If the user created filesix the first AU for that file must be number nine since it’s the first available open AU. If filesix is big enough to need another AU then DOS will use number 14, then number 16.

Of course, the example above is very much simplified. It shows only 20 Allocation Units when most disks have thousands. You’ll notice that the FAT has an entry for every AU - just as it does in a true system. Finally, the directory is rather small when in a real system the directory would list hundreds of files. However, the purpose of this example is to simplify file allocation so you can understand what’s going on. Just multiply this figure by about a thousand and you’ll get some idea of what DOS does for a living.

FAT 32

Here is one last note about FAT. You may have heard about “FAT 32” that is used by Windows 98. With DOS and Windows 3.1, 3.11, and 95 the FAT used a 16-bit “word.” I know that doesn’t mean anything to you, but you should know that the result is that FAT 16 could only store a table for 2 Gbytes of disk space. This is why a large drive formatted with Windows 95 had to be partitioned into smaller 2 Gbyte drives. When Microsoft created Windows 98 they changed the FAT to use a 32-bit “word.” This means that the FAT can now keep information for drives up to 2 terabytes (that’s trillions of bytes - or 2000 GBytes!).

There is also some change in the size of each allocation unit. I haven’t pointed out before, but size does matter (at least for allocation units). Imagine you typed a short letter home to Mom and that letter needs only 5 Kbytes of storage. If the size of the AU is 5 Kbytes the letter will fit nicely into only one AU. However, if the size of the AU is 10 Kbytes then the letter will occupy only half of the AU - and the rest of the space in that AU will be wasted. A 2-Gbyte disk formatted with FAT-16 uses a 32 Kbyte AU. That means that a lot of space is wasted on the disk if it has relatively small files. (For the record, most files on any hard drive are much smaller than 32 Kbytes.) FAT 32, though, uses a much smaller AU size - 4 Kbytes for a 2 Gbyte hard drive. With FAT-32, small files will waste far less space on the disk since they are being stored in smaller AUs.

If you are using Windows 98 and you have a hard drive that is 2 Gbytes or larger, you should consider converting your disk to FAT 32. If you do, you will not be able to boot your computer again with DOS 6.0 (since it still expects a 16-bit FAT); then again, when was the last time you wanted to boot your computer with DOS 6.0? The savings in disk space and efficiency will more than make up for any potential inconvenience in the loss of DOS 6.0.

Linux Method

With Linux, the method used to keep up with file storage is much different then that used by DOS/Windows. Linux programmers decided to create a table of “i-nodes” (that stands for “index nodes”) and store all the file’s information in an i-node rather than using a linked list.

Image - Linux I-Nodes

Figure 1 - Linux I-Nodes

The figure above will help you with the concept of i-nodes. With Linux, a file is stored on the disk using storage “blocks” (they are about like the “allocation units” used in DOS). Then, Linux creates an i-node for the file. The i-node contains the file’s attributes and a pointer to each block used by the file. For short files (again, most files on the computer are rather short) an i-node is large enough to contain the pointers to every block used by the file.

What about long files, though? If a file is so long that it needs more blocks than can be addressed in a single i-node, Linux uses “indirect blocks.” The last three addresses of an i-node contain pointers to a single indirect block, a double indirect block, and a triple indirect block (in that order).

If a file becomes too large for an i-node to contain all the block pointers, Linux will use the single indirect block - which contains space for more pointers. This is almost like an extension to the i-node. If that is still not enough block addresses then Linux will use a double indirect block - this block contains pointers to more i-node blocks that contain pointers to disk addresses. The ultimate is the triple indirect block. It contains pointers to pointers to i-node blocks! Most files are so short that they only need the i-node pointer spaces - but the indirects are available if needed - and can point to huge files. Fortunately, Linux takes care of all this pointing automatically - aren’t you glad?

File Allocation Problems

The DOS/Windows file scheme introduces two potential problems: crosslinking and lost allocation units. (Please note that I have been using the term “allocation unit” throughout this chapter. These units are also called “clusters.” Thus, you will more commonly hear of “lost clusters” rather than “lost allocation units.” I’ll use the term “lost clusters” for the rest of this chapter since it is more common.)

You may wonder how these problems come up. That is because Windows keeps the FAT in the computer’s memory while you are actually using it. When it’s time to shut down the computer, the FAT (along with other files) are written to the hard drive for safekeeping – as long as the computer is shut down properly. If, though, you shutdown the computer improperly (for example: just turn the power switch off), the FAT will not be saved on the hard drive. When you next start the computer it will report that it was shutdown improperly and begin scandisk – which will attempt to repair the FAT. (NOTE: scandisk is covered elsewhere in this class.)

The moral of the story, then, is: Always shutdown the computer using the procedure in the “Start” menu – or else…

Crosslinking

If the FAT is changed so that two files seem to be using the same chain these files are said to be cross-linked. Using the example first presented in the figure above, suppose the FAT was changed to look like this:

Directory
File Name First AU
fileone 1
filetwo 4
filethree 12
filefour 6
filefive 10

The disk's directory is shown above. It has not changed in this example.

File Allocation Table (FAT)
AU Number Next AU
1 2
2 8 5
3 X
4 5
5 17
6 7
7 11
8 0
9  
10 13
11 15
12 0
13 0
14  
15 0
16  
17 18
18 19
19 0
20 X

Notice that fileone has been corrupted. Its chain should read 1, 2, 8 but the link at 2 has been changed to point to 5. Now, fileone will use this chain: 1, 2, 5, 17, 18, 19. It will contain part of fileone and part of filetwo: these two files are crosslinked (ominous organ music swells in the background).

To fix this problem scandisk will create two files and then delete the bad chain. One file will contain the chain 1, 2, 5, 17, 18, 19 and one will contain the chain 4, 5, 17, 18, 19. Of course, the second chain is filetwo but the first chain is garbage. In this case you have lost what was originally in fileone. Scandisk will warn you that you had a crosslinked file and tell you the names of the two it created so you can check to see which is a good file and which is garbage. You can then take out the garbage (that is, delete the bad file).

The worst problem with a crosslinked file is that most files on your computer are programs - not data. If a program gets crosslinked it will not run and you will have to re-load the program. If the program that was crosslinked happens to be Windows, then you will have to reinstall Windows (and lose all the information you had on the disk).

Can you say, “Backup regularly?”

Lost Clusters

Lost clusters are a problem caused, again, by improperly shutting down the computer. If the FAT had an extra zero (the “end of file” marker) accidentally inserted then any part of the file’s chain after that zero is gone.

For example, imagine that location 11 in the FAT illustrated in the figure above had a zero rather than a 15 (you can write it in there if you want – go ahead, it won’t hurt anything). The chain for filefour would then become 6, 7, 11 rather than 6, 7, 11, 15. The last cluster is now gone and scandisk reports that it is “lost.”

If that should happen, filefour would be corrupted. If that file happened to be just a text file (like a Word document) you could probably still recover it, but the last few pages of the file would be gone. What’s more likely is that the file is a program and without its ending it would simply not run. If that program happened to be Windows - well, you know what that means…

Scandisk will offer to convert lost clusters into files for you. In the case of filefour that I’m using as an example, you would end up with whatever is in location 15 as a “lost cluster” file (scandisk will name it something like file0000.chk). It’s not very likely that the recovered cluster will be of any use. Again, most files on your computer are programs so converting a portion of a program to a file will be worthless. The figure below shows what a recovered lost cluster would look like when you open it with the DOS editor. It’s not too pretty, is it? Generally, if scandisk reports lost clusters you may as well just let it delete them and be done with it.

Image - A Recovered Lost Cluster

Figure 2 - A Recovered Lost File Cluster

Linux

Due to the way Linux manages file allocation (the i-node thing), there is no danger of getting files crosslinked or generating lost clusters - these problems simply do not exist in Linux. That is why I did not discuss this issue for the Linux operating system.

Summary

In this lesson I introduced you to a number of issues concerning the way an operating system manages files. You should remember these points:

It is important that you learn how the operating system handles files. Good luck as you work with the labs for this lesson!


DOS Laboratory

Navigation

When you first start DOS, the "Windows" directory will be the working directory.

Image - DOS Startup Screen

Figure 1 - DOS Startup Screen

You always know the name of the working directory since it’s listed beside the DOS prompt. In Figure 1 the working directory is "Windows" on the "C:" drive.

To change the working directory, issue the command cd (for "change directory") followed by the destination directory. In DOS, the root directory is called "\" (that’s just a single back-slash). To change to the root directory, use this command:

cd \

Image - DOS Root Directory

Figure 2 - DOS Root Directory

Notice that the DOS prompt now shows the working directory as “\” on the C: drive - which is the root. Can you tell what other command I also issued to get to Figure 2 from Figure 1 ? (Hint: it was one of the first DOS commands you learned - way back in the lab manual for the Introduction).

Just for practice, try changing directories to windows\command. That screen should look like Figure 3 .

Image - Working Directory

Figure 3 - The Windows/Command Working Directory

Now that you know how to navigate between directories, it’s important to be able to list the files that are in a particular directory. With DOS, the command to list the files is dir (that stands for “directory”). The files in the directory will scroll by on the screen and continue scrolling until they are all listed.

When I entered dir in the c:/windows/command directory I got this listing:

Image - A File Listing

Figure 4 - File Listing for the Command Directory

Because there were more files than would fit on one screen, a number of file names scrolled by and disappeared off the top of the screen - but it eventually stopped. If you wanted to read one of the names that were at the top of the list you had to be a pretty fast reader!

At the bottom of the listing you can see that this directory contains 50 files and 3 sub-directories. All the files in this directory take about 1.89 Mbytes.

Let’s look at a single line in Figure 4 so you know what information is there - then we’ll look at some options for the dir command. The last file listed on this screen is:

ZIP  EXE      117,247   11-04-97     1:20a   zip.exe

On this line, the first items are the DOS file name (ZIP.EXE), followed by the file size (117,247 bytes). Next is the date and time the file was last modified (11-04-97 1:20a).

The last item on the line deserves a bit of explanation. This is the Windows file name. Even if the file has a long name or contains characters that are illegal in DOS, the Windows name will be in the last column. This is a function of Windows and is only found in the version of DOS that comes with Windows. If we had used a “pure” DOS system the last column (the Windows name) would not be available.

You can get a listing of only the files that start with a certain letter and help to cut down on the size of the list. For example, to see all the files that start with the letter “c” in the command directory, enter:

dir c*.*

The result of that command is:

Image - The "C" Files

Figure 5 - Listing Only The "C" Files

You’ll notice that only those files that begin with the letter “c” are in the list (there are only five of them).

But what’s that "*" for? In DOS you can use two different “wildcard” symbols when you list the contents of a directory. The * symbol tells DOS to ignore any following letters. For example, “c*.*” matched choice.com and chkdsk.exe because they both started with a “c” and DOS ignored all other letters in the filename. If I had asked for a list of “ch*.*” files then DOS would have matched only choice.com and chkdsk.exe - but none of the others.

The other wildcard character is the question mark. When DOS sees a question mark in the dir request it will ignore only that one letter - but must match all others. For example “?ar.txt” would match far.txt, car.txt, and par.txt but not star.txt.

DOS includes a few options for the dir command. In DOS, a command’s options are called “switches.” I don’t think it has anything to do with the hickory switch my daddy kept in the corner of the living room for David and me - it is more related to the type of switch used to send a train down a different track. By adding switches you can change the way a DOS command works - send it down a different track, so to speak.

You can use more than one switch at a time. For example: dir /p /w is a perfectly legal command.

Here are the more common switches for dir. Following this table, you can see example screens using some of these switches.

Switch Action
/p Pause after each screen of information
/w Use a wide listing format
/on Sort (or order) the list by name
/os Sort by size (smallest first)
/od Sort by date (oldest first)

Image - A Wide Directory Listing

Figure 6- Directory Listing with Wide Switch (dir /w)

Image - A Directory Listing Showing Several Options

Figure 7- Directory Listing Ordered By Size And Paged Output (dir /os /p)

Attributes

DOS files include four attributes that can be remembered with the acronym RASH:

To see a file’s attributes, use the command attrib. You will likely want to limit the scope of this command by adding a file specification. For example, to see the attributes on all the .sys files in the root directory, enter this command while the root directory is the working directory:

attrib *.sys

You can see the result of this command below:

Image - The File Attributes

Figure 8 - Attributes For System Files

You’ll note that MSDOS.SYS has the Archive, System, Hidden and Read Only attribute turned on while CONFIG.SYS has only the Archive attribute turned on.

You can use attrib to turn on or off any of the attributes. For example:

attrib –a *.sys

will turn off all archive attributes for the .sys files. (Note, the only attribute you can change on a hidden file is H. To set or reset any other attributes for hidden files you need to unhide them first, change the attribute, then re-hide them.)

Image - Changing An Attribute

Figure 9 - Changing An Attribute

In Figure 9 I attempted to turn off the archive attribute for all the .sys files in the root directory. You can see that CONFIG.SYS started with the archive attribute turned on, then ended with it turned off. You will also note that attrib did not change the archive attribute for any of the hidden files.

Directories

To make a new directory with DOS, use the command mkdir dirname (the command stands for “make directory”). When you enter that command DOS will create a new subdirectory in the working directory and name that sub-directory dirname. Here’s an example:

Image - Making A New Directory

Figure 10- Making A Directory

You will note that I’ve created a directory called mytest. After I made the directory I listed all the files in the root directory that start with "myt" and, sure enough, there is a sub-directory called mytest.

To remove a directory, enter the command rmdir dirname (the command stands for “remove directory”). DOS will then remove the directory.

Note: before DOS can remove a directory it must be empty - no files. So before you remove a directory you must delete all of the files in it.

In the following example I removed mydir that I had created above:

Image - Removing A Directory

Figure 11- Removing A Directory

File Operations

Generally, the operating system must permit the user to create, destroy, view, and change any file. The operating system should also have a way for the user to find files on the drive. In this section we’ll look at these operations for each of the operating systems.

You should note that most operating systems have several methods to complete these actions. I will present only one in this book, but you may discover other methods that are easier for you.

Note: For all the exercises in this section use the root directory.

Create A File

Under DOS there is no way to just create an empty file. The most common method for creating a new file is to use an application that creates one. For example, you could use a text processor to create a new text file. For this book, I created a file using the DOS editor. To start the editor I entered this command:

edit mytest.txt

Note: It is also fairly common to copy an existing file then rename it to some new name. Then the user can change the new file in any way desired.

Image - Starting The DOS Editor

Figure 12- Starting the DOS Editor

When the editor started, I typed a few lines of text:

Image - Entering Text Using The DOS Editor

Figure 13- The DOS Editor

To save the file, I pressed the ALT key on the keyboard. This highlighted the menu at the top of the screen. I next pressed the F key (for File), which made a drop-down menu appear. I then pressed the “S” key (for “Save”). You can also use your mouse in this editor – so you could have simply clicked File then Save.

Note: if you do not see the menu at the top of the screen it’s because the screen has been automatically scrolled down one line to give you the greatest possible typing area. You can use your mouse and move the scrollbar on the right to view the top of the screen.

To exit the editor, I pressed the ALT key - then F - then X. (You’ll see what this combination of keys does if you try it out.)

When I finished this exercise I had created a new file called “mytest.txt”:

Image - A Directory Showing The New File

Figure 14- Directory Listing Showing Mytest.txt

View Contents

Sometimes you will want to just peek inside a file to see what’s there. The DOS command to do that is type. When I entered type mytest.txt this is what I got:

Image - "Typing" A Document

Figure 15- Viewing a File Using Type

If you happen to type an executable file (like one with an .exe or .com file extension) your screen will quickly fill with gibberish. If it happens to be a large file it may take several seconds for all that stuff to scroll by - but just let it keep going. It will eventually stop and you can get back to work.

Copy

To create a copy of a file use the copy command. This command takes the form copy source destination - or “copy from this source to that destination.” I entered this command to copy mytest.txt:

Copy mytest.txt mytest2.txt

Image - The Copy Command

Figure 16- Copying a File

You can see that DOS reported that the file was copied, but then I listed all the files starting with “myt*.*” in the directory to be sure. At the bottom of the listing you’ll note mytest.txt and mytest2.txt are the same size - 78 bytes. I could type both files to be sure they are the same.

Move

The move command is very similar to the copy command - except with move you end up with only one copy of the file - it’s just in a new directory. To move a file you specify the source and destination, just like copy. I decided to move mytest2.txt to the Windows directory:

move mytest2.txt windows\mytest2.txt

Image - Moving A File

Figure 17- Moving A File

You’ll note that DOS reported the file moved OK. Then I listed the contents of the directory again and found mytest2.txt had vanished.

I could have also renamed the file as I moved it. If I had entered this command:

move mytest2.txt windows\newfile.txt

The file would have been moved to the Windows directory and been renamed to newfile.txt.

Rename

You can rename a file with the DOS ren command (that stands for “rename”). However, there is another method that you’ll probably prefer since it’s the same as is used in Linux (thus, there’s less for you to remember - and that can only be a good thing). If you move a file into the same directory but call it something else it will be renamed. I entered this command:

move mytest.txt mytest3.txt

Image - Renaming A File

Figure 18- Renaming A File By Moving It

Append

It is sometimes useful to be able to append one file onto the end of another. In DOS you can do this with the copy command. If DOS sees more than one source file it will copy them all into a single destination file (merging them one after the other).

For this example, I made two copies of mytest.txt and called them mytest2.txt and mytest3.txt. Then I copied all three into a file called bigfile.txt. Here’s the command (notice: there are no spaces in the source file list):

copy mytest.txt+mytest2.txt+mytest3.txt mytest4.txt

Image - Appending A File

Figure 19- Using Copy To Append Files

You’ll notice that mytest4.txt is now 235 bytes big - which is 3 X 78 bytes (allowing for rounding error). What do you suppose you’ll see if you type mytest4.txt?

Delete

Now, we get to delete all the files we’ve just created. The command for delete is del.

First, in the root directory enter these commands:

del mytest4.txt
del mytest.txt
del newfile2.txt
del newfile3.txt

Now, change to the Windows directory and del mytest2.txt

Find

Unfortunately, in DOS there is no find command. I should clarify this statement - there actually is a “find” command but it finds a string of words inside a known file. For example, you could “find” the string “Hello” inside some text file. However, there is no command to help you find lost files in DOS. The only thing you can do is to repeatedly use the dir command in every directory until you find your file. This is not too handy. Of course, you probably won’t use DOS all that often so missing this function shouldn’t be a great handicap for you.


Windows XP Laboratory

Navigation

With Windows XP, managing directories and files is done through a Graphic User Interface (GUI). You will use your mouse and “point and click” to access folders and files. You should note that Microsoft renamed “directories” to “folders” so when you see something about a “folder” in Windows that is the same idea as a “directory” in DOS or Linux.

To start navigating within Windows, double-click on “My Computer” and then double-click on the C: drive. You will get a screen that looks something like this:

Image - The C Drive

Figure 1 - The C: Drive

Note that this is the C: drive on my home computer - the actual folders and files you see on your computer will be different from Figure 1, but the screen should be similar. (No, you cannot come to my house to do your homework so the screens look the same - nice try.)

To open a sub-folder (like Windows), double-click on the folder’s name with your mouse. To close a folder click on the x in the top right corner of the screen.

There are numerous options for file display in Windows. You’ll have to set your computer so it matches your own preference. You may want to explore in the View menu to set the viewing options you like.

Attributes

With Windows, you can check or change a file’s attributes by right-clicking on the file’s name then selecting properties. Once you click on Properties, the dialog box illustrated in Figure 2 pops up. Notice that two of the four attributes are available to set (Archive is manipulated on the "Advanced" button). I can check or uncheck any of the boxes to turn that attribute on or off.

Figure 2 - General File Properties

On the Custom tab for your file's properties, you can add descriptors for many different properties. I've added an "Owner" and "Purpose" descriptor, but there are dozens of other properties available you can change.

Figure 3 - Custom File Properties

The "Summary" tab has both an advanced and simplified view. Figure 4 shows the simplified view. Notice that I've added a number of descriptive phrases to this document.

Figure 4 - Simplified Summary File Properties

In the Advanced Summary view you can see a lot of information about the file, including its size and the date it was last modified (the date is scrolled off the bottom of the screen in Figure 5).

Figure 5 - Advanced Summary File Properties

File Operations

Create

With Windows, all files are created by some application (like Word or Excel). To create a file, simply start some application then save a file within that application.

View Contents

To view the contents of any file, double-click on that file. Windows will start whatever application created the file, then open the file in that application. For example, if you had a file called mytest.doc then Windows would assume it is a Word document (since it has a file extension of .doc). If you double-click on the file name, Windows will open Word, then open the file in Word.

Copy

You can make a copy of a file by right-clicking on the file name and choosing copy. This will create a copy of the file in the computer’s memory. You can then open another directory and choose paste to create a copy of the file in that directory.

Move

You can move a file by right-clicking on the file name and choosing cut. This will create a copy of the file in the computer’s memory and delete the original. You can then open another directory and choose paste to place the file there.

Rename

You can rename a file by right-clicking on the file name and choosing rename. You can then enter a new name for the file.

Append

There is no way to append files in Windows. You must open a file with the application, then use that application to append other files.

Delete

You can delete a file by right-clicking on the file name and choosing delete.

Search

Windows has a very rich search capability. When you click on Start – Search you will see this screen:

Figure 6 - Finding Files With Windows

The left side of the screen is a short wizard to guide you through the various search options. For this exercise, I selected "Documents" and got the screen illustrated in Figure 7:

Figure 7 - Specifying Advanced Characteristics for a File Search

Using the various attributes on the left side of the screen, you can narrow your search down to only recent files, phrases found in the document's name or even within the text, its location, its size, or other advanced characteristics.

Finding files is one of Windows really shining points. You’ll like using it if you ever lose a file on your hard drive.


Linux Laboratory

Navigation

When you start Linux, your working directory will be a special directory that was created just for you by the Linux system administrator (don’t you feel special?). Learning the complete Linux directory structure is beyond the scope of this class (you can learn that in the Unix class), but you should know that when a new user is added to the Linux system that user gets a personal directory. You should keep all your files and other work in your personal directory (it’s called your “home” directory).

In Figure 1 you’ll note that the Linux prompt includes two bits of helpful information. The first is who is logged onto the system (selfg@localhost) and the second is the working directory (cis140). When you first log on you will see a prompt something like mine except, of course, it will have your logon identification instead of mine and you may be in a different working directory.

[selfg@localhost cis140]$

Figure 1 - The Command Prompt

While the working directory is listed in the prompt, you can view the entire directory path (starting from the root) by using the command pwd (that stands for “present working directory”).

[selfg@localhost selfg]$ pwd
/home/selfg

[selfg@localhost selfg]

Figure 2 - The PWD Command

Linux reported in Figure 2 that my working directory is /home/selfg. This means when I installed this system and created a user called selfg, Linux created a directory called home, then it put my directory (selfg) in home. For most of your work in Linux you can forget about all the directories at a higher level than (or preceding) your home (or "main") directory – you’ll find nothing of interest there until you become a system administrator. All the examples in this book are taken from my home directory – and you should be using yours.

Of course, then name of your home directory will be different from mine. The computers in our lab all have a student account called "student," which is what you should be using. For many of the exercises in this lab you will use a set of directories and files that came with your boot up disk. You should transfer them to the Linux hard drive and then complete this lab. (Don't worry, I'll talk you through the "copy your files over" process.) You can find a structure of the cis140 directory at the end of this document.

[selfg@localhost selfg]$ pwd
/home/selfg
[selfg@localhost selfg]$ cd cis140
[selfg@localhost cis140]$ pwd
/home/selfg/cis140

[selfg@localhost cis140]

Figure 3 - CD To CIS140 Then PWD

In Figure 3, I changed to the cis140 directory using the cd command and then used pwd to see the working directory. By comparing this with the previous screen you can see how the result of pwd changed when I changed directories.

[selfg@localhost systems]$ pwd
/home/selfg/cis140/biology/human/systems
[selfg@localhost systems]$ cd
[selfg@localhost selfg]$ pwd
/home/selfg

[selfg@localhost selfg]

Figure 4 - Changing To Home Directory

Using the structure of cis140 found at the end of this document, I changed to one of the lower-level directories, and then issued a pwd command. You can see I’m in a directory called systems that’s several levels deep in cis140.

Then I issued a cd command without any options or specifications. I next checked my working directory (using pwd) and found I’m back in my home directory. This is a wonderful feature in Linux. If you are working deep in some directory structure you can always return to your home directory by just entering cd with no options. If Dorothy had this capability the Oz movie would have been really short!

[selfg@localhost cis140]$ ls
biology chemistry physics vi.txt
[selfg@localhost cis140]$

Figure 5 - The LS Command

Now that you know how to move between directories, you need to learn how to see what files are in the directory. The simplest file listing command is ls (for “list”). In Figure 5 you can see I’ve listed the files in the CIS140 directory. There are several - but three of them are directories and not simple files. There is only a file in my home directory - or is there?

I happen to know that there is one hidden file. This is not a “secret” file, but just one that I don’t ever need to access (I don't want to accidentally delete it). Linux also commonly hids various configuration files so you don't delete or change them. File names that start with a dot are hidden from the ls command. To see the hidden files I have to use an -a switch (for “all”) on the ls command. You can see the command and it’s resulting list in Figure 6.

[selfg@localhost cis140]$ ls
biology chemistry physics vi.txt .vi.txt
[selfg@localhost cis140]$

Figure 6 - Listing All Files With ls -a

Now you know the value of hiding some files. For example, in my home directory (that's at /home/selfg) I actually have over 25 files - but I never need to access most of them (they contain certain systems information that never changes). If I had to wade through that long list of files just to find one that I created it would make my job harder - so Linux automatically hides those files I do not normally need to see. Remember, this is not a security feature (since I can see those files anytime I want), it’s just convenience.

There are two hidden files that deserve special mention: the “.” (called “dot”) and “..” (called “dot-dot”) files. These two files appear in every directory in a Linux system and are very useful once you get good with Linux. The “dot” file is shorthand for the current working directory and the “dot-dot” file is shorthand for its parent directory. While this does not make much sense at this point, when you begin to copy and move files you’ll find a use for these two special notations.

If you want to practice with the “dot-dot” notation, you can do this:

  1. Change to the cis140/chemistry/organic directory (use cd to do this)
  2. From cis140/chemistry/organic enter the command cd .. (that’s cd – space – dot – dot)
  3. Check your working directory (use pwd)
  4. Again enter the command cd .. (that’s cd – space – dot – dot)
  5. Check your working directory (use pwd)
  6. Return to your home directory (remember the shortcut for this action?)

Files and directories have a number of attributes that you may want to know but cannot see from a simple ls command. For that reason, many people prefer to use the -l switch (that's an "L" - for “long”). Notice the command I used in Figure 7.

[selfg@localhost cis140]$ ls -la
total 28
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 .
drwx--x--x 31 selfg selfg 4096 Aug 10 16:05 ..
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 biology
drwxrwxr-x 7 selfg selfg 4096 Aug 10 16:05 chemistry
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 physics
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 .vi.txt
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 vi.txt
[selfg@localhost cis140]$

Figure 7 - Listing Of CIS140 Directory

Note: This command listed all the files (that’s why I put the “a” in the group of switches) and gave me a long listing so I could have a bit more information about each file than just a name. Notice that when you add more than one switch you only need to put the dash one time - then simply list all the switches after the dash. Do you think it makes any difference what order you use for the switches? Would ls -al work as well as ls -la? Try it and see.

Let’s analyze a single file’s entry. One entry in the list looks like this:

drwxrwxr-x    5 selfg    selfg        4096 Aug 10 16:05 physics

The first character indicates the file’s type. There are five types of files in Linux:

The next nine characters (rwxr-xr-x) are the security settings for this file. I’ll skip these settings for now, but will cover them in the security lab manual.

The 5 is the number of links to this directory. You can create links to files so other users can work with you on a collaborative project. So why does the physics directory have 5 links? Each of the files contained in that directory is automatically linked to its parent directory when it's created - so that gives physics five links.

The first selfg is the directory’s owner and the second selfg is its group. We’ll discuss these concepts more when we discuss Linux security.

The directory’s size is 4096 bytes and it was last accessed on Aug 10 at 16:05 (Linux uses a military-style clock, so 16:05 is 4:05 pm).

Finally, the example directory’s name is physics.

Given all this, how many files are in this directory? How many sub-directories? (You’ll have to count ‘em - get busy!)

Attributes

You may remember that DOS files include four attributes:

The Linux operating system does not include file attributes. (That’s pretty simple, isn’t it?) Instead:

Directories

To make a new directory with Linux, use the command mkdir dirname (the command stands for “make directory”). When you enter that command Linux will create a new subdirectory in the working directory and name the new directory dirname. Here’s an example:

[selfg@localhost cis140]$ ls
biology chemistry physics vi.txt
[selfg@localhost cis140]$ mkdir math
[selfg@localhost cis140]$ ls
biology chemistry math physics vi.txt

[selfg@localhost cis140]$

Figure 8 - Making A Directory

In the figure above, I first listed all the files in CIS140, then made a directory called math. Then I listed all the files again so you can see that math was, in fact, created and added to the list of files.

To remove a directory, enter the command rmdir dirname (the command stands for “remove directory”). Linux will then remove the directory. NOTE: before Linux can remove a directory it must be empty – no files inside. So before you remove a directory you must delete all files in it.

In the following example I removed math, which I had created above.

[selfg@localhost cis140]$ ls
biology chemistry physics vi.txt
[selfg@localhost cis140]$ mkdir math
[selfg@localhost cis140]$ ls
biology chemistry math physics vi.txt
[selfg@localhost cis140]$ rmdir math
[selfg@localhost cis140]$ ls
biology chemistry physics vi.txt

[selfg@localhost cis140]$

Figure 9 - Removing A Directory

File Operations

Generally, the operating system must permit the user to create, destroy, view, and change any file. The operating system should also have a way for the user to find files on the drive. You should note that Linux (like most operating systems) have several methods to complete these actions. I will present only one in this manual, but you may discover other methods that are easier for you.

Note: For all the exercises in this section, use the cis140 directory. The structure of that directory is listed at the end of this section.

Create

In the DOS lab I had you create a new file by using an editor. That method is also available with Linux, but there is also a way to create an empty file without starting an editor: touch. The touch command is used to update a file’s time and date - but if you touch a file that does not exist Linux will create it for you. I created many of the files in your cis140 directory using touch. Here's how to create a new file with touch:

[selfg@localhost cis140]$ ls -l
total 16
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 biology
drwxrwxr-x 7 selfg selfg 4096 Aug 10 16:05 chemistry
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 physics
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 vi.txt
[selfg@localhost cis140]$ touch mytest.txt [selfg@localhost cis140]$ ls -l total 16
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 biology
drwxrwxr-x 7 selfg selfg 4096 Aug 10 16:05 chemistry
-rw-rw-r-- 1 selfg selfg 0 Aug 10 16:19 mytest.txt
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 physics
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 vi.txt [selfg@localhost cis140]$

Figure 10 - Creating A File With Touch

You’ll notice that I first listed the files in cis140, then executed touch, then listed them again (using the long form). You’ll see that in the second listing the file mytest.txt now exists and it is 0 bytes big - it’s an empty file.

Of course, an empty file doesn’t normally do us a lot of good, so let’s enter some “stuff” in mytest.txt. Use the vi editor to enter a line or two of text in mytest.txt. I have included a vi tutorial elsewhere, so you may need to complete that lesson before you finish this.

Enter the following lines in mytest.txt:

This is a test of Linux’ file handling capability.
I will enter a few lines of text, and then use these lines
to test this system.
Wish me luck!

When you have completed entering this information, you can exit vi and list the files in cis140. You’ll now note that mytest.txt has 145 bytes instead of the 0 it had earlier.

Note: the actual size of your file may be a bit different from mine. That just means you may have entered an extra space or some other character in your file. Don't worry about minor differences in the file size.

[selfg@localhost cis140]$ ls -l
total 16
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 biology
drwxrwxr-x 7 selfg selfg 4096 Aug 10 16:05 chemistry
-rw-rw-r-- 1 selfg selfg 145 Aug 10 16:19 mytest.txt
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 physics
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 vi.txt [selfg@localhost cis140]$

Figure 11 - Listing Showing Larger mytest.txt

You have now created a file using touch and put information into that file using vi. You could have just as easily created a new file by opening a blank document in vi then saving it.

View Contents

To view the contents of your file use the cat command (that stands for “concatenate”).

[selfg@localhost cis140]$ cat mytest.txt
This is a test of Linux' file handling capability.
I will enter a few lines of text, and then use these lines
to test this system. Wish me luck! [selfg@localhost cis140]$

Figure 12 - Viewing the Contents Of A File With Cat

Copy

To copy a file with Linux use this command: cp source destination. I created a copy of mytest.txt like this:

[selfg@localhost cis140]$ ls
biology chemistry mytest.txt physics vi.txt
[selfg@localhost cis140]$ cp mytest.txt mytest2.txt
[selfg@localhost cis140]$ ls
biology chemistry mytest2.txt mytest.txt physics vi.txt

[selfg@localhost cis140]$

Figure 13 - Copying a File In Linux

Move

To move a file with Linux use this command: mv source destination. I moved mytest2.txt to another directory like this:

[selfg@localhost cis140]$ ls
biology chemistry mytest2.txt mytest.txt physics vi.txt
[selfg@localhost cis140]$ mv mytest2.txt biology/mytest2.txt
[selfg@localhost cis140]$ ls
biology chemistry mytest.txt physics vi.txt
[selfg@localhost cis140]$ cd biology
[selfg@localhost biology]$ ls
botany human mytest2.txt zoology

[selfg@localhost biology]$

Figure 14 - Moving a File

I could have also renamed the file as I moved it. If I had entered this command:

mv mytest2.txt biology\newfile.txt

The file would have been moved to the biology directory and been renamed to newfile.txt.

Rename

Linux does not have a rename command. Instead, mv a file into the same directory but call it something new. I renamed mytest.txt like this:

[selfg@localhost cis140]$ ls
biology chemistry mytest.txt physics vi.txt
[selfg@localhost cis140]$ mv mytest.txt newfile.txt
[selfg@localhost cis140]$ ls
biology chemistry newfile.txt physics vi.txt

[selfg@localhost cis140]$

Figure 15 - Renaming A File

Append

In Linux, use the cat command (stands for concatenate) to append files.

For this example, I made two copies of the file newfile.txt and called them new2.txt and new3.txt. Then I copied all three into a file called bigfile.txt. Here’s what happened:

[selfg@localhost cis140]$ ls
biology chemistry newfile.txt physics vi.txt
[selfg@localhost cis140]$ cp newfile.txt new2.txt
[selfg@localhost cis140]$ cp newfile.txt new3.txt
[selfg@localhost cis140]$ ls
biology chemistry new2.txt new3.txt newfile.txt physics vi.txt
[selfg@localhost cis140]$ cat newfile.txt new2.txt new3.txt > bigfile.txt
[selfg@localhost cis140]$ ls -l
total 36
-rw-rw-r-- 1 selfg selfg 438 Aug 10 16:26 bigfile.txt
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 biology
drwxrwxr-x 7 selfg selfg 4096 Aug 10 16:05 chemistry
-rw-rw-r-- 1 selfg selfg 146 Aug 10 16:25 new2.txt
-rw-rw-r-- 1 selfg selfg 146 Aug 10 16:25 new3.txt
-rw-rw-r-- 1 selfg selfg 146 Aug 10 16:25 newfile.txt
drwxrwxr-x 5 selfg selfg 4096 Aug 10 16:05 physics
-rw-rw-r-- 1 selfg selfg 2242 Aug 10 16:05 vi.txt
[selfg@localhost cis140]$

Figure 16 - Appending Files

You’ll notice that bigfile.txt is about three times the size of newfile.txt – but you would expect that since we appended that file three times. You’ll also notice that in the command line I used this symbol: >. That is what is called a redirect in Linux. What literally happened is that the cat command wanted to display the three files on the screen, but the display was redirected into bigfile.txt instead – in effect, appending the files onto the end of bigfile.txt.

Delete

Now, we get to delete all the files we’ve just created. The command for delete is rm (that stands for “remove”).

First, in cis140 enter these commands:

rm bigfile.txt
rm newfile.txt
rm newfile2.txt
rm newfile3.txt

Change to the biology directory and rm mytest2.txt

Find

Linux comes with a number of tools to help you find files - one of the best is locate. When I entered the command locate nervous:

[selfg@localhost cis140]$ locate nervous
/home/selfg/cis140/biology/human/systems/nervous
[selfg@localhost cis140]$

Figure 17 - Locating Files

While it doesn’t exactly fit here, you may be interested to know how to find a particular command in Linux. There is a command called apropos that will tell you all the commands that may be appropriate for a given task. For example, if I knew I could copy a file but forgot that the actual command was cp, I could enter apropos copy and this is what Linux would return (to save space, I've deleted some of the lines returned, but you can see that Linux found a lot of potential matches for "copy").

[selfg@localhost cis140]$ locate nervous
cp                   (1)  - copy files and directories
cpio (1) - copy files to and from archives
cpp (1) - The C Preprocessor
dhclient-script (8) - DHCP client network configuration script
dhcp-options (5) - Dynamic Host Configuration Protocol options
escputil (1) - maintain Epson Stylus inkjet printers
getrpcport (3) - get RPC port number
ifnames (1) - Extract CPP conditionals from a set of files
ip (8) - TCP/IP interface configuration and routing utility
macptopbm (1) - convert a MacPaint file into a portable bitmap
memccpy (3) - copy memory area
memccpy [bstring] (3) - byte string operations
perlmodinstall (1) - Installing CPAN Modules
rcp (1) - remote file copy
rmail (8) - handle remote mail received via uucp
scp (1) - secure copy (remote file copy program)
strcpy (3) - copy a string
tcpd (8) - access control facility for internet services
tcpdump (8) - dump traffic on a network
tiffcp (1) - copy (and possibly convert) a TIFF file
top (1) - display top CPU processes
[selfg@localhost cis140]$

Figure 18 - Finding Copy Commands With Apropos

You’ll notice that there are many commands in Linux for copying, but the first in this list (cp (1)) is the one we’re after. The description of this command is “copy files and directories.” By using apropos you can usually find any Linux command of interest.

Organization Of The CIS140 Directory

CIS 140        
  VI.TXT      
  physics      
    gravity    
      einstein  
      newton  
    mechanics    
      motion  
      tools  
      work  
    optics    
      color  
      lens  
      light  
  chemistry      
    acid-base    
      definition  
      neutralization  
      ph  
    organic    
      hydrocarbons  
      polymers  
    periodic-table    
      definition  
      groups  
      history  
      periods  
      noble-gas  
    radio    
      isotopes  
      radio-dating  
      radioactivity  
    structure    
      atoms  
      electrons  
      models  
      neutrons  
      protons  
      subatomic  
  biology      
    botany    
      flowering-plants  
      germination-table  
      herbs  
      photosynthesis  
    human    
      genetics  
        chromosomes
        dna
        engineering
      psychology  
        learning-theory
        mood-disorders
        neuroses
        phobia
        psychoses
      systems  
        circulatory
        digestive
        hormonal
        immune
        muscle
        nervous
        reproductive
        respiratory
        skeletal
    zoology    
      carnivores  
      herbivores  
      omnivores