276 The File System Moving Your Directories Historically, Unix provides no tools for maintaining recursive directories of files. This is rather surprising, considering that Unix (falsely) prides itself on having invented the hierarchical file system. For example, for more than a decade, Unix lacked a standard program for moving a direc- tory from one device (or partition) to another. Although some versions of Unix now have a mvdir command, for years, the standard way to move directories around was with the cp command. Indeed, many people still use cp for this purpose (even though the program doesn’t preserve modifica- tion dates, authors, or other file attributes). But cp can blow up in your face. Date: Mon, 14 Sep 92 23:46:03 EDT From: Alan Bawden Alan@lcs.mit.edu To: UNIX-HATERS Subject: what else? Ever want to copy an entire file hierarchy to a new location? I wanted to do this recently, and I found the following on the man page for the cp(1) command: NAME cp - copy files cp -rR [ -ip ] directory1 directory2 -r -R Recursive. If any of the source files are directories, copy the directory along with its files (including any subdirectories and their files) the destination must be a directory. Sounds like just what I wanted, right? (At this point half my audience should already be screaming in agony—“NO! DON’T OPEN THAT DOOR! THAT’S WHERE THE ALIEN IS HIDING!”) So I went ahead and typed the command. Hmm… Sure did seem to be taking a long time. And then I remembered this horror from fur- ther down in the cp(1) man page: BUGS cp(1) copies the contents of files pointed to by symbolic links. It does not copy the symbolic link itself. This can lead to
UFS: The Root of All Evil 277 inconsistencies when directory hierarchies are replicated. Filenames that were linked in the original hierarchy are no longer linked in the replica… This is actually rather an understatement of the true magnitude of the bug. The problem is not just one of “inconsistencies”—in point of fact the copy may be infinitely large if there is any circularity in the symbolic links in the source hierarchy. The solution, as any well-seasoned Unix veteran will tell you, is to use tar6 if you want to copy a hierarchy. No kidding. Simple and ele- gant, right? Disk Usage at 110%? The Unix file system slows down as the disk fills up. Push disk usage much past 90%, and you’ll grind your computer to a halt. The Unix solution takes a page from any good politician and fakes the numbers. Unix’s df command is rigged so that a disk that is 90% filled gets reported as “100%,” 80% gets reported as being “91%” full, and so forth. So you might have 100MB free on your 1000MB disk, but if you try to save a file, Unix will say that the file system is full. 100MB is a large amount of space for a PC-class computer. But for Unix, it’s just spare change. Imagine all of the wasted disk space on the millions of Unix systems throughout the world. Why think when you can just buy bigger disks? It is estimated that there are 100,000,000,000,000 bytes of wasted disk space in the world due to Unix. You could probably fit a copy of a better operating system into the wasted disk space of every Unix system. There is a twist if you happen to be the superuser—or a daemon running as root (which is usually the case anyway). In this case, Unix goes ahead and lets you write out files, even though it kills performance. So when you have that disk with 100MB free and the superuser tries to put out 50MB of new files on the disk, raising it to 950 MB, the disk will be at “105% capacity.” 6“tar” stands for tape archiver it is one of the “standard” Unix programs for making a tape backup of the information on a hard disk. Early versions wouldn’t write backups that were more than one tape long.
Previous Page Next Page