![]() | CONTENTS | ![]() |
A variety of topics related to UNIX file system structure, navigation, and daily use are covered in this chapter, including:
Permissions
Absolute and relative path names
File name expansion and wild cards
Several commands including: pwd, cd, chmod, cp, mv, mkdir, rm, rmdir
Examples of using many commands
The best place to begin discussing permissions is by issuing the ls command, which lists the contents of directories. Permissions are the means by which files and directories are made secure on your UNIX system. Because UNIX is multi-user, potentially thousands of users could be accessing the files on a system. Permissions controls who has access to what files.
Here is an example ls -l command and output:
$ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort
Issuing this command has produced a lot of information relating to a file called sort. Let's begin to understand what this listing has produced by analyzing the first set of characters (-rwxr-x--x). This set of characters is made up of four distinct fields, as shown in Figure 3-1.
The first character in this group is related to the file type. I covered some file types earlier, but the ls -l command does not analyze files to the same level of detail. Among the types of files ls -l will list are shown in Figure 3-2:
Keep in mind the file types can vary slightly from one UNIX variant to another. The file types listed in Figure 3-2 are common to most UNIX variants. For every file on the system, UNIX supports three classes of access:
User access (u). Access granted to the owner of the file.
Group access (g). Access granted to members of the same group as the owner of the file.
Other access (o). Access granted to everyone else.
These access rights are defined by the position of read (r), write (w), and execute (x) when the long listing command is issued. For the long listing (ls -l) issued earlier, you see the permissions in Table 3-1.
Access | User Access | Group Access | Other |
---|---|---|---|
Read | r | r | - |
Write | w | - | |
Execute | x | x | x |
Permissions are not granted where a "-" (hyphen) appears. In addition, there are other permissions such as s, S, t, and T, which I don't cover at this time.
You can see that access rights are arranged in groups of three: three groups of permissions with three access levels each. The owner, in this case marty, has read, write, and execute permissions on the file. Anyone in the group users is permitted read and execute access to the file. other is permitted only execute access of the file.
The definitions of read, write, and execute differ somewhat for files and directories. Here is what you can do if you have read, write, and execute permissions for files:
read You have permission to read the file.
write You have permission to change and to write to the file.
execute You can run, or execute, the program.
Here is what you can do if you have read, write, and execute permissions for directories:
read You can list the contents of the directory.
write You can create files in the directory, delete files in the directory, and create subdirectories in the directory.
execute You can change to this directory using the cd command, which we'll cover shortly.
We will cover permissions again when the chmod command is described.
We have already covered two topics that can serve as the basis for a discussion of absolute and relative path names: some important directories on the system and user login. If you take a look at the user denise and the way some of her files can be organized, we can get to the bottom of relative and absolute path names quickly.
The UNIX file system covered in Chapter 2 showed a hierarchy. In this hierarchy, there was the root (/) directory at the top, and files and directories were below root. The two means by which you can traverse this hierarchy to get to a "lower" point are with absolute path names and relative path names. Let's take a closer look at the files and directories that denise may have in her user area.
First of all, we'll assume that denise has many files. This activity is one of the things users do - create files. In addition, your system administrator has provided several default files for purposes such as defining your user environment after login (we'll get into this in a lot more detail in upcoming chapters). denise probably has many files under her user area, and subdirectories as well. Her user area may look something like that shown in Figure 3-3:
Most users will have their home directory under /home (and who said UNIX doesn't make any sense?). If you want to get to a subdirectory of denise using an absolute path name, you traverse the hierarchy using the complete path. To get to the directory.netscape-cache under denise, you could view the absolute path as shown in Figure 3-4:
You are progressing from root (/), to home, todenise, and finally to the directory.netscape-cache. The change directory (cd) command which you issue looks like the following:
$ cd /home/denise/.netscape-cache
This is an absolute path because it starts at root and progresses through the hierarchy. No matter what directory you are currently working in, even if it is.netscape-cache, you could use the absolute path name. In many cases, however, you may not need to issue an absolute path name. You may be so close to the file or directory you wish to access that the absolute path would be a waste of time for you. If, for instance, you are already in /home/denise, then you could change to.netscape-cache using a relative path name easily:
$ cd .netscape-cache
The relative path name is shorter because you don't begin with a slash (/) that brings you back up to the top of the hierarchy to work your way down. Instead, you are starting at some point in the file system hierarchy, such as /home/denise, and entering a path relative to that directory, such as.netscape-cache.
Before we cover additional file system related commands, it is worth taking a look at file name expansion. An overview of file name expansion is useful to ensure that you're comfortable with this topic before we cover additional commands.
Table 3-2 lists some common file name expansion and pattern matching.
Character(s) | Example | Description |
---|---|---|
* | 1) ls *.c | Match zero or more characters |
? | 2) ls conf.? | Match any single character |
[list] | 3) ls conf.[co] | Match any character in list |
[lower-upper] | 4) ls libdd.9873[5-6].sl | Match any character in range |
str{str1,str2,str3,...} | 5) ls ux*.{700,300} | Expand str with contents of {} |
~ | 6) ls -a ~ | Home directory |
~username | 7) ls -a ~gene | Home directory of username |
The following descriptions of the examples shown in Table 3-2 are more detailed:
To list all files in a directory that end in ".c", you could do the following:
$ ls *.c conf. SAM.c conf.c
To find all the files in a directory named "conf" with an extension of one character, you could do the following:
$ ls conf.? conf.c conf.o conf.1
To list all the files in a directory named "conf" with only the extension "c" or "o," you could do the following:
$ ls conf.{co} conf.c conf.o
To list files with similar names but a field that covers a range, you could do the following:
$ ls libdd9873[5-6].sl libdd98735.sl libdd98736.sl
To list files that start with "ux" and have the extension "300" or "700," you could do the following:
$ ls ux*.{700,300} uxbootlf.700 uxinstfs.300
To list the files in your home directory, you could use ~ (tilde:
$ ls -a ~ . .cshrc.org .login .shrc.org .. .exrc .login.org .cshrc .history .profile
To list the files in the home directory of a user, you could do the following:
$ ls -a ~gene . .history splinedat under.des .. .login trail.txt xtra.part .chsrc .login.org ESP-File .cshrc.org .profile Mail .exrc .shrc.org opt
When we covered absolute and relative path names, we used the cd command to change directory. You can be at any point in the file system hierarchy and use cd to change to the desired directory, provided that you have the necessary permissions to change to that directory.
We can change directory using an absolute path name as shown in the following example:
$ cd /home/denise/.netscape-cache
Regardless of your current location in the file system hierarchy, this changes you to the directory /home/denise/.netscape-cache. If, however, your current location in the file system hierarchy is /home/ denise, then you could use a relative path name to change to.netscape-cache, as shown in the following example:
$ cd .netscape-cache
In order to change directory to a place in the file system relative to your current location, you need a way to determine your current location. The pwd command, for present working directory, can do this for you. Going back to the previous example in which we changed directories using the relative path, we could have first issued the pwd command to see that our location was /home/denise, as shown in the following example
$ pwd /home/denise $ cd .netscape-cache $ pwd $ /home/denise/.netscape-cache $
pwd takes some of the mystery out of determining your current directory.
Let's now take a look at moving up a level in the directory tree using two dots:
$ pwd /home/denise/.netscape-cache $ cd .. $ pwd /home/denise $
The two-dot notation moves you to the parent directory of your current directory.
To return to your home directory, you could issue the cd command with no arguments as shown in the following example:
$ pwd /tmp $ cd $ pwd /home/denise $
This shows that no matter what your current location in the file system hierarchy, you can always get back quickly to your home directory. I don't get into shell parameters for some time, but there is a shell parameter which defines your home location, as shown in the following example:
$ pwd /tmp $ cd $HOME $ pwd /home/denise $
Using the pwd and cd commands, you can always obtain your current directory and change to any directory.
cd - Change to a new current directory.
|
Examples
$ pwd /home/denise/.netscape-cache $ cd ..
$ pwd /home/denise $
The chmod command is used to change the permissions on a file. Let's start our discussion of chmod with the listing of the file sort shown earlier:
$ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort
Figure 3-5 shows a breakdown of the permissions on sort.
You have very little control over the type of file defined. You do, however, have a great deal of control over the permissions of this file if it belongs to you. The chmod command is used to change the permissions on a file or directory. If you are the owner of the file, you can have a field day changing the permissions on the file.
There are two means by which you can change the permissions: symbolic or numeric. I focus first on the numeric mode, because the numbers involved are easy to manage and I sometimes find that new UNIX users get hung up on the meaning of some of the symbols. I'll then cover the symbols and include the symbol meanings in the chmod summary. I decided to use the symbols in the summary because the numeric mode, which I much prefer, is becoming obsolete. In some UNIX variants, the chmod manual page is strewn with references to "obsolescent form" whenever the numeric mode is covered.
First of all, what do I mean by numbers? Looking at the numbers for sort, we see permissions of 751: 7 for owner (hundreds position), 5 forgroup (tens position), and 1 for other (ones position). Figure 3-6 helps with the meanings of the positions:
Selecting the desired permissions for owner, group, andother, you use the chmod command to assign those permissions to a file or directory. Some of these permission possibilities are infrequently used, such as execute only, because you usually need to have read access to a file in order to execute it; however, I included all possibilities in Figure 3-6 for completeness. In addition to the permission mode bits shown in Figure 3-6, some miscellaneous mode bits also exist that you don't need to be concerned with at this time.
If you decide that you would like to add write permission of the file sort for group and remove all permissions for other, you would simply execute the chmod command with the appropriate numeric value. The following set of commands first lists the existing permissions for sort, then it changes the permissions on sort, and finally it lists the new permissions on sort:
$ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort $ chmod 770 sort $ ls -l sort -rwxrwx--- 1 marty users 120 Jul 26 10:20 sort
The same set of commands to change the permissions using the symbolic mode would be:
$ ls -l sort -rwxr-x--x 1 marty users 120 Jul 26 10:20 sort $ chmod g+w,o-x sort $ ls -l sort -rwxrwx--- 1 marty users 120 Jul 26 10:20 sort
In symbolic mode, you issue the chmod command and specify who will be affected by the change [user (u), group (g), other (o), or all (a)], the operation you wish to perform [add (+), delete (-), or replace (=)] on permissions, and the permission you wish to specify [read (r), write (w), or execute (x)]. In the previous example using symbolic mode, write (w) permission is being added (+) for group (g), and execute (x) permission is being removed (-) for other (o).
The following is a summary of some of the more commonly used symbols of chmod:
chmod - Change permissions of specified files using the following symbolic mode list.
|
The cp command is used to copy a file from one location to another location. You do not alter the original file when you perform a copy. Provided that you have access to the destination directory to which you wish to copy a file, you can place as many copies of a file in that destination as you wish.
The following bullet list describes some of the types of copies you can perform with cp. Because there are many file types in UNIX (as covered in Chapter 2) and you have many ways to specify path names for the source and destination files being copied, this list might help you understand the many ways cp can be used:
Copy a source file to a new file name.
Copy several source files to a different directory.
Copy several source files to the same directory.
Copy an entire directory to a different directory.
Copy several directories to different directories.
The following is an example of copying a file to a new file name within the same directory:
$ cp krsort krsort.sav
What if the file krsort.sav already exists? The answer is that it is replaced by the new krsort.sav being copied. To prevent such mishaps (officially called an overwrite) from occurring, you use the -i option to cp. -i asks you whether you wish to overwrite the file before the copy takes place. If your response is affirmative, then the old file is overwritten with the new file.
The following example first shows a listing of the contents of a directory. Using cp with the -i option, we copy the file krsort.c to krsortorig.c, a file that already exists. By responding n when asked whether we want to overwrite krsortorig.c, the file is not overwritten and no copy takes place:
$ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 31 11:27 krsort -rwxr-xr-x 1 denise users 3234 Oct 31 11:27 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 31 11:27 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 31 11:27 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 31 11:27 krsortorig.c $ cp -i krsort.c krsortorig.c overwrite krsortorig.c? (y/n) n $
cp - Copy files and directories.
|
The mv command is used to move a file or directory from one location to another location. You can also move multiple files.
The following example shows a listing of a directory, the move of file krsort.c to krsort.test.c within this directory, and a listing of the directory showing that the file has been moved:
$ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 31 15:17 krsort -rwxr-xr-x 1 denise users 3234 Oct 31 15:17 krsort.c -rwxr-xr-x 1 denise users 2756 Oct 31 15:17 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 31 15:17 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 31 15:17 krsortorig.c $ mv krsort.c krsort.test.c $ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 31 15:17 krsort -rwxr-xr-x 1 denise users 32756 Oct 31 15:17 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 31 15:17 krsort.q -rwxr-xr-x 1 denise users 3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x 1 denise users 3085 Oct 31 15:17 krsortorig.c $
What if the destination file already exists? You guessed it, UNIX is more than happy to write over the destination file. Using the -i option, mv asks you to confirm overwriting a file before it does so. The following example shows an attempt to move krsort.test.c to krsortorig.c. The user is alerted to the fact that krsortorig.c already exists and chooses not to let the move take place:
$ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 31 15:17 krsort -rwxr-xr-x 1 denise users 32756 Oct 31 15:17 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 31 15:17 krsort.q -rwxr-xr-x 1 denise users 3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x 1 denise users 3085 Oct 31 15:17 krsortorig.c $ mv -i krsort.test.c krsortorig.c remove krsortorig.c? (y/n) n $ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 31 15:17 krsort -rwxr-xr-x 1 denise users 32756 Oct 31 15:17 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 31 15:17 krsort.q -rwxr-xr-x 1 denise users 3234 Oct 31 15:17 krsort.test.c -rwxr-xr-x 1 denise users 3085 Oct 31 15:17 krsortorig.c $
Because the response was not in the affirmative, the move does not take place, and the original krsortorig.c remains intact.
mv - Move files and directories.
|
How nice it would be to have a commandtomake a directoryany time you wish. You could then use this command to create directories and thereby organize your files in multiple directories in a way similar to organizing files in a filing cabinet. The mkdir command allows you to do just that - make a directory.
This is an incredibly simple command. You specify the name of the directory to create. In the following example, we'll look at the contents of a directory with the ls command, use mkdir to make the directory named default.permissions, and then perform another ls to see the new directory:
$ ls -l total 2 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old $ mkdir default.permissions $ ls -l total 4 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old drwxr-xr-x 2 denise users 24 Oct 31 11:32 default.permissions $
The new directory has been produced with default permissions for the user denise. group and other have both read and execute permissions for this directory.
What if you wanted to create a directory with specific permissions on it instead of default permissions? You could use the -m option to mkdir and specify the mode or permissions you wanted. To give all users read permission on the krsort.dir.new directory, you issue the following:
$ mkdir -m "a=r" read.permissions $ ls -l total 6 drwxr-xr-x 2 denise users 1024 Oct 31 11:27 krsort.dir.old drwxr-xr-x 2 denise users 24 Oct 31 11:32 default.permissions dr--r--r-- 2 denise users 24 Oct 31 11:33 read.permissions $
Remember the symbolic versus numeric mode of permissions? This mkdir command shows the symbolic mode, which, although I do not like it as much as the numeric mode, should be used because the numeric mode is becoming obsolete.
You don't have to stop at creating a directory with only one level of depth. With the -p option, you can create a new directory with any number of subdirectories in it. Intermediate directories are created with the -p option. Let's now create a directory named level1, with the directory level2 beneath it, and the directory level3 below level2 in the following example. The ls command with the -R option recursively lists the directories below level1:
$ mkdir -p level1/level2/level3 $ ls -R level1 level2 level1/level2: level3 level1/level2/level3: $
After creating the directory level1 and issuing thels command, we can see that level2 is indeed beneath level1, andlevel3 is beneath level2.
mkdir - Create specified directories.
|
The rm command removes one or more files from a directory and can also be used to remove the directory itself. Going back to our earlier discussion on permissions, you must have both write and execute permissions on a directory in order to remove a file from it. If you own the directory from which you are going to remove files, then you can probably remove files from it. If, however, you don't have the appropriate permissions on a directory, then the rm fails.
As with some of the other commands we have covered, you can use the -i option, which asks you to confirm each file as it is removed. This means that if you are asked whether you really wish to remove a file and you respond n, then the file is not removed. If you respond y, the file is removed.
You can also use the -r (or -R) option to recursively delete the contents of directories and then delete the directories. This means you can recursively delete the files and directories specified. If there is any question in your mind about whether or not you wish to recursively delete files and directories, then use the -i option along with -r.
You can use the -f option to remove files and directories, which performs removes without asking you to confirm them.
The following example performs a long listing of the directory krsort.dir.new, interactively prompts the user to see whether he or she wants to delete the files in this directory, and then lists the contents of this directory again, showing that all files have not been deleted because the user responded n:
$ ls -l krsort.dir.new total 168 -rwxr-xr-x 1 denise users 34592 Oct 27 18:44 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:46 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:46 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 18:46 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:46 krsortorig.c $ rm -i krsort.dir.new/* ../krsort.dir.new/krsort: ? (y/n) n ../krsort.dir.new/krsort.c: ? (y/n) n ../krsort.dir.new/krsort.dos: ? (y/n) n ../krsort.dir.new/krsort.q: ? (y/n) n ../krsort.dir.new/krsortorig.c: ? (y/n) n $ ls -l krsort.dir.new total 168 -rwxr-xr-x 1 denise users 34592 Oct 27 18:44 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:46 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:46 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 18:46 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:46 krsortorig.c $
Note that the response to being asked whether the file should be deleted was n in all cases. This means that none of the files have been removed. A y response to any question results in that file being removed from the directory. To interactively delete a directory, you combine the options -i and -r of the rm command. If, however, you do not delete every file in a directory, then the directory is not removed if the -i option is used. The first part of the following example shows all but the file krsort being removed from the directory krsort.dir.new. The directory is not deleted because this file still exists. When the file is removed in the second part of this example, the directory itself is then deleted:
$ rm -ir krsort.dir.new directory krsort.dir.new: ? (y/n) y krsort.dir.new/krsort: ? (y/n) n krsort.dir.new/krsort.c: ? (y/n) y krsort.dir.new/krsort.dos: ? (y/n) y krsort.dir.new/krsort.q: ? (y/n) y krsort.dir.new/krsortorig.c: ? (y/n) y krsort.dir.new: ? (y/n) y rm: directory krsort.dir.new not removed. Directory not empty $ rm -ir krsort.dir.new directory krsort.dir.new: ? (y/n) y krsort.dir.new/krsort: ? (y/n) y krsort.dir.new: ? (y/n) y $
rm - Remove files and directories.
|
The rmdir command removes one or more directories. The directory must be empty in order to be removed or you must use the -f option. You can also specify more than one directory to be removed. Going back to our earlier discussion on permissions, you must have both write and execute permissions on the parent of a directory to be removed in order to remove it.
As with some of the other commands we have covered, you can use the -i option, which asks you to confirm each directory as it is removed. This means that if you are asked whether you really wish to remove a directory and you respond n, then it is not removed. If you respond y, it is removed.
The order in which you specify directories are to be removed is significant. If you want to remove both a directory and its subdirectory, you must specify the subdirectory to be removed first. If you specify the parent directory rather than its subdirectory to be removed first, the removal of the parent directory fails because it is not empty.
You can use the -f option to force the removal of directories, an action that performs removal without asking you to confirm them.
The following example performs a long listing of the directory krsort.dir.new, showing that this directory has in it a file called.dotfile. When we attempt to remove this directory with rmdir, a message is displayed informing us that this directory is not empty. The file .dotfile in this directory prevents the rmdir command from removing krsort.dir.new. After removing.dotfile, we are able to remove the directory with rmdir:
$ ls -al ../krsort.dir.new total 4 drwxr-xr-x 2 denise users 1024 Oct 27 18:57 . drwxrwxr-x 4 denise users 1024 Oct 27 18:40 .. -rw-r--r-- 1 denise users 0 Oct 27 18:56 .dotfile $ rmdir -i ../krsort.dir.new ../krsort.dir.new: ? (y/n) y rmdir: ../krsort.dir.new: Directory not empty $ rm ../krsort.dir.new/.dotfile $ rmdir -i ../krsort.dir.new ../krsort.dir.new: ? (y/n) y $
rmdir has now successfully removed krsort.dir.new because.dotfile is gone:
rmdir - Remove directories.
|
Now that we have covered some of these commands in an "isolated" fashion, let's put some of the commands together.
Let's start by viewing the hierarchy of a directory under denise's home directory, called krsort.dir.old, as shown in Figure 3-7:
$ cd /home/denise/krsort.dir.old $ pwd /home/denise/krsort.dir.old $ ls -l total 168 -rwxr-xr-x 1 denise users 34592 Oct 27 18:20 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 17:30 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 17:30 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 17:30 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 17:30 krsortorig.c $
We can then make a new directory called krsort.dir.new and copy a file to it, as shown in Figure 3-8:
$ mkdir ../krsort.dir.new $ cp krsort ../krsort.dir.new $ ls -l ../krsort.dir.new total 68 -rwxr-xr-x 1 denise users 34592 Oct 27 18:27 krsort $
Now let's try the -i option to cp. If we attempt to copy a file to an existing file name, we'll be asked if we wish to overwrite the destination file. We are alerted to the fact that the destination file already exists and we can then select a new name for the file we wish to copy, as shown in Figure 3-9:
$ pwd /users/denise/krsort.dir.old $ cp -i krsort ../krsort.dir.new overwrite ../krsort.dir.new/krsort? (y/n) n $ cp krsort ../krsort.dir.new/krsort.new.name $ ls -l ../krsort.dir.new total 136 -rwxr-xr-x 1 denise users 34592 Oct 27 18:27 krsort -rwxr-xr-x 1 denise users 34592 Oct 27 18:29 krsort.new.name $
We can also use a wild card with cp to copy all files in krsort.dir.old to krsort.dir.new, as shown in Figure 3-10:
$ cp * ../krsort.dir.new $ ls -l ../krsort.dir.new total 236 -rwxr-xr-x 1 denise users 34592 Oct 27 18:30 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:30 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:30 krsort.dos -rwxr-xr-x 1 denise users 34592 Oct 27 18:29 krsort.new.name -rw-r--r-- 1 denise users 9922 Oct 27 18:30 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:30 krsortorig.c $
Let's start over at the point where the krsort.dir.new directory is empty, as shown in Figure 3-11:
We can now move the file krsort to the krsort.dir.new directory, as shown in Figure 3-12:
$ mv krsort ../krsort.dir.new $ ls -l ../krsort.dir.new total 68 -rwxr-xr-x 1 denise users 34592 Oct 27 18:20 krsort $
If we now attempt to move krsort to the krsort.dir.new directory with the -i option and write over the file krsort, we getthe following:
$ mv -i krsort ../krsort.dir.new/krsort remove ../krsort.dir.new/krsort? (y/n) n $
Because we used the -i option to mv, we areasked whetherwe wish to allow a file to be overwritten with the move. Because we responded n to the question, the file is not overwritten.
We can also use a wild card with the mv command to copy all files from the krsort.dir.old directory to the krsort.dir.new directory. Without the -i option, any files in the krsort.dir.new directory are overwritten by files that have the same name, as shown in Figure 3-13:
$ mv * ../krsort.dir.new $ ls -l ../krsort.dir.new total 168 -rwxr-xr-x 1 denise users 34592 Oct 27 18:44 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:46 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:46 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 18:46 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:46 krsortorig.c $
The most feared command in the UNIX world, with good reason I might add, is the rm command. rm removes whatever you want whenever you want, with no questions asked unless you use the -i option.
Want to blow away your system instantly? rm would be more than happy to help you. As an average user, and not the system administrator, you probably do not have the permissions to do so. It is, however, unnerving to know that this is a possibility. In addition, it is likely that you have permissions remove all of your own files and directories. All of this can be easily avoided by simply using the -i option to rm.
Let's assume that krsort.dir.new and krsort.dir.old are identical directories, as shown in Figure 3-14:
To interactively remove files from krsort.dir.new, you do the following:
$ rm -i ../krsort.dir.new/* ../krsort.dir.new/krsort: ? (y/n) n ../krsort.dir.new/krsort.c: ? (y/n) n ../krsort.dir.new/krsort.dos: ? (y/n) n ../krsort.dir.new/krsort.q: ? (y/n) n ../krsort.dir.new/krsortorig.c: ? (y/n) n $ ls -l ../krsort.dir.new total 168 -rwxr-xr-x 1 denise users 34592 Oct 27 18:44 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:46 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:46 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 18:46 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:46 krsortorig.c $
This obviously resulted in nothing being removed from krsort.dir.new because we responded n when asked whether we wanted to delete files.
Let's now go ahead and add a file beginning with a "." (period) to krsort.dir.new. The touch command does just that, it touches a file to create it with no contents, as shown in Figure 3-15 (touch can also be used to update the time stamp of an existing file):
$ touch ../krsort.dir.new/.dotfile $ ls -al ../krsort.dir.new total 172 drwxr-xr-x 2 denise users 1024 Oct 27 18:54 . drwxrwxr-x 4 denise users 1024 Oct 27 18:40 .. -rw-r--r-- 1 denise users 0 Oct 27 18:56 .dotfile -rwxr-xr-x 1 denise users 34592 Oct 27 18:44 krsort -rwxr-xr-x 1 denise users 3234 Oct 27 18:46 krsort.c -rwxr-xr-x 1 denise users 32756 Oct 27 18:46 krsort.dos -rw-r--r-- 1 denise users 9922 Oct 27 18:46 krsort.q -rwxr-xr-x 1 denise users 3085 Oct 27 18:46 krsortorig.c $
If we now attempt to remove files using the same rm command earlier issued, we'll see the following, as shown in Figure 3-16:
$ rm -i ../krsort.dir.new/* ../krsort.dir.new/krsort: ? (y/n) y ../krsort.dir.new/krsort.c: ? (y/n) y ../krsort.dir.new/krsort.dos: ? (y/n) y ../krsort.dir.new/krsort.q: ? (y/n) y ../krsort.dir.new/krsortorig.c: ? (y/n) y $ ls -al ../krsort.dir.new total 4 drwxr-xr-x 2 denise users 1024 Oct 27 18:57 . drwxrwxr-x 4 denise users 1024 Oct 27 18:40 .. -rw-r--r-- 1 denise users 0 Oct 27 18:56 .dotfile
The "*" used as a wild card with the rm command does not remove the file.dotfile. The file.dotfile in this directory prevents the rmdir command from removing krsort.dir.new. This file must first be removed before the rmdir command can successfully delete krsort.dir.new.
$ rmdir -i ../krsort.dir.new ../krsort.dir.new: ? (y/n) y rmdir: ../krsort.dir.new: Directory not empty $ rm ../krsort.dir.new/.dotfile $ rmdir -i ../krsort.dir.new ../krsort.dir.new: ? (y/n) y $
rmdir has now successfully removed krsort.dir.new because.dotfile is gone, as shown in Figure 3-17:
The following are the HP-UX manual pages for many of the commands used in the chapter. Commands often differ among UNIX variants, so you may find differences in the options or other areas for some commands; however, the following manual pages serve as an excellent reference.
cd - Change working directory.
cd(1) cd(1) NAME cd - change working directory SYNOPSIS cd [directory] DESCRIPTION If directory is not specified, the value of shell parameter HOME is used as the new working directory. If directory specifies a complete path starting with /, ., .., directory becomes the new working directory. If neither case applies, cd tries to find the designated directory relative to one of the paths specified by the CDPATH shell variable. CDPATH has the same syntax as, and similar semantics to, the PATH shell variable. cd must have execute (search) permission in directory. cd exists only as a shell built-in command because a new process is created whenever a command is executed, making cd useless if written and processed as a normal system command. Moreover, different shells provide different implementations of cd as a built-in utility. Features of cd as described here may not be supported by all the shells. Refer to individual shell manual entries for differences. If cd is called in a subshell or a separate utility execution environment such as: find . -type d -exec cd {}; -exec foo {}; (which invokes foo on accessible directories) cd does not affect the current directory of the caller's environment. Another usage of cd as a stand-alone command is to obtain the exit status of the command. EXTERNAL INFLUENCES International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES Change the current working directory to the HOME directory from any location in the file system: cd Change to new current working directory foo residing in the current directory: cd foo or cd ./foo Change to directory foobar residing in the current directory's parent directory: cd ../foobar Change to the directory whose absolute pathname is /usr/local/lib/work.files: cd /usr/local/lib/work.files Change to the directory proj1/schedule/staffing/proposals relative to home directory: cd $HOME/proj1/schedule/staffing/proposals VARIABLES The following environment variables affect the execution of cd: HOME The name of the home directory, used when no directory operand is specified. CDPATH A colon-separated list of pathnames that refer to directories. If the directory operand does not begin with a slash (/) character, and the first component is not dot or dot-dot, cd searches for directory relative to each directory named in the CDPATH variable, in the order listed. The new working directory is set to the first matching directory found. An empty string in place of a directory pathname represents the current directory. If CDPATH is not set, it is treated as if it was an empty string. RETURN VALUE Upon completion, cd exits with one of the following values: 0 The directory was successfully changed. >0 An error occurred. The working directory remains unchanged. SEE ALSO csh(1), pwd(1), ksh(1), sh-posix(1), sh(1), chdir(2). STANDARDS CONFORMANCE cd: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
chmod - Change permissions.
chmod(1) chmod(1) NAME chmod - change file mode access permissions SYNOPSIS /usr/bin/chmod [-A] [-R] symbolic_mode_list file ... Obsolescent form: /usr/bin/chmod [-A] [-R] numeric_mode file ... DESCRIPTION The chmod command changes the permissions of one or more files according to the value of symbolic_mode_list or numeric_mode. You can display the current permissions for a file with the ls -l command (see ls(1)). Symbolic Mode List A symbolic_mode_list is a comma-separated list of operations in the following form. Whitespace is not permitted. [who]op[permission][,...] The variable fields can have the following values: who One or more of the following letters: u Modify permissions for user (owner). g Modify permissions for group. o Modify permissions for others. a Modify permissions for all users (a is equivalent to ugo). op Required; one of the following symbols: + Add permission to the existing file mode bits of who. - Delete permission from the existing file mode bits of who. = Replace the existing mode bits of who with permission. permission One or more of the following letters: r Add or delete the read permission for who. w Add or delete the write permission for who. x Add or delete the execute file (search directory) permission for who. s Add or delete the set-owner-id or set- group-id on file execution permission for who. Useful only if u or g is expressed or implied in who. t Add or delete the save-text-image on file execution (sticky bit) permission. Useful only if u is expressed or implied in who. See chmod(2). x Conditionally add or delete the execute/search permission as follows: - If file is a directory, add or delete the search permission to the existing file mode for who. (Same as x.) - If file is not a directory, and the current file permissions include the execute permission (ls -l displays an x or an s) for at least one of user, group, or other, then add or delete the execute file permission for who. - If file is not a directory, and no execute permissions are set in the current file mode, then do not change any execute permission. Or one only of the following letters: u Copy the current user permissions to who. g Copy the current group permissions to who. o Copy the current other permissions to who. The operations are performed in the order specified, and can override preceding operations specified in the same command line. If who is omitted, the r, w, x, and X permissions are changed for all users if the changes are permitted by the current file mode creation mask (see umask(1)). The s and t permissions are changed as if a was specified in who. Omitting permission is useful only when used with = to delete all permissions. Numeric Mode (Obsolescent) Absolute permissions can be set by specifying a numeric_mode, an octal number constructed from the logical OR (sum) of the following mode bits: Miscellaneous mode bits: 4000 (= u=s) Set-user-id on file execution (file only) 2000 (= g=s) Set-group-id on file execution 1000 (= u=t) Set sticky bit; see chmod(2) Permission mode bits: 0400 (= u=r) Read by owner 0200 (= u=w) Write by owner 0100 (= u=x) Execute (search in directory) by owner 0040 (= g=r) Read by group 0020 (= g=w) Write by group 0010 (= g=x) Execute/search by group 0004 (= o=r) Read by others 0002 (= o=w) Write by others 0001 (= o=x) Execute/search by others Options -A Preserve any optional access control list (ACL) entries associated with the file. By default, in conformance with the IEEE Standard POSIX 1003.1-1988, optional ACL entries are deleted. For information about access control lists, see acl(5). -R Recursively change the file mode bits. For each file operand that names a directory, chmod alters the file mode bits of the named directory and all files and subdirectories in the file hierarchy below it. Only the owner of a file, or a user with appropriate privileges, can change its mode. Only a user having appropriate privileges can set (or retain, if previously set) the sticky bit of a regular file. In order to set the set-group-id on execution bit, the group of the file must correspond to your current group ID. If chmod is used on a symbolic link, the mode of the file referred to by the link is changed. EXTERNAL INFLUENCES Environment Variables LC_MESSAGES determines the language in which messages are displayed. If LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, chmod behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. RETURN VALUE Upon completion, chmod returns one of the following values: 0 Successful completion. >0 An error condition occurred. EXAMPLES Deny write permission to others: chmod o-w file Make a file executable by everybody: chmod a+x file Assign read and execute permission to everybody, and set the set- user-id bit: chmod a=rx,u+s file Assign read and write permission to the file owner, and read permission to everybody else: chmod u=rw,go=r file or chmod 644 file (obsolescent form) Traverse a directory subtree making all regular files readable by user and group only, and all executables and directories executable (searchable) by everyone: chmod -R ug+r,o-r,a+X pathname If the current value of umask is 020 (umask -S displays u=rwx,g=rx,o=rwx; do not change write permission for group) and the current permissions for file mytest are 444 (a=r), displayed by ls -l as -r--r--r--, then the command chmod +w mytest sets the permissions to 646 (uo=rw,g=r), displayed by ls -l as -rw-r- -rw-. If the current value of umask is 020 (umask -S displays u=rwx,g=rx,o=rwx; do not change write permission for group) and the current permissions for file mytest are 666 (a=rw), displayed by ls -l as -rw-rw-rw-, then the command chmod -w mytest sets the permissions to 464 (uo=r,g=rw), displayed by ls -l as -r-- rw-r--. DEPENDENCIES The -A option causes chmod to fail on file systems that do not support ACLs. AUTHOR chmod was developed by AT&T and HP. SEE ALSO chacl(1), ls(1), umask(1), chmod(2), acl(5). STANDARDS CONFORMANCE chmod: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
cp - Copy files and directories.
cp(1) cp(1) NAME cp - copy files and directory subtrees SYNOPSIS cp [-f|-i] [-p] [-e extarg ] file1 new_file cp [-f|-i] [-p] [-e extarg ] file1 [file2 ...] dest_directory cp [-f|-i] [-p] [-R|-r] [-e extarg ] directory1 [directory2 ...] dest_directory DESCRIPTION cp copies: - file1 to new or existing new_file, - file1 to existing dest_directory, - file1, file2, ... to existing dest_directory, - directory subtree directory1, to new or existing dest_directory. or - multiple directory subtrees directory1, directory2, ... to new or existing dest_directory. cp fails if file1 and new_file are the same (be cautious when using shell metacharacters). When destination is a directory, one or more files are copied into that directory. If two or more files are copied, the destination must be a directory. When copying a single file to a new file, if new_file exists, its contents are destroyed. If the access permissions of the destination dest_directory or existing destination file new_file forbid writing, cp aborts and produces an error message ``cannot create file''. To copy one or more directory subtrees to another directory, the -r option is required. The -r option is ignored if used when copying a file to another file or files to a directory. If new_file is a link to an existing file with other links, cp overwrites the existing file and retains all links. If copying a file to an existing file, cp does not change existing file access permission bits, owner, or group. When copying files to a directory or to a new file that does not already exist, cp creates a new file with the same file permission bits as file1, modified by the file creation mask of the user if the -p option was not specified, and then bitwise inclusively ORed with S_IRWXU. The owner and group of the new file or files are those of the user. The last modification time of new_file (and last access time, if new_file did not exist) and the last access time of the source file1 are set to the time the copy was made. Options -i (interactive copy) Cause cp to write a prompt to standard error and wait for a response before copying a file that would overwrite an existing file. If the response from the standard input is affirmative, the file is copied if permissions allow the copy. If the -i (interactive) and -f (forced-copy) options are both specified, the -i option is ignored. -f Force existing destination pathnames to be removed before copying, without prompting for confirmation. This option has the effect of destroying and replacing any existing file whose name and directory location conflicts with the name and location of the new file created by the copy operation. -p (preserve permissions) Causes cp to preserve in the copy as many of the modification time, access time, file mode, user ID, and group ID as allowed by permissions. -r (recursive subtree copy) Cause cp to copy the subtree rooted at each source directory to dest_directory. If dest_directory exists, it must be a directory, in which case cp creates a directory within dest_directory with the same name as file1 and copies the subtree rooted at file1 to dest_directory/file1. An error occurs if dest_directory/file1 already exists. If dest_directory does not exist, cp creates it and copies the subtree rooted at file1 to dest_directory. Note that cp -r cannot merge subtrees. Usually normal files and directories are copied. Character special devices, block special devices, network special files, named pipes, symbolic links, and sockets are copied, if the user has access to the file; otherwise, a warning is printed stating that the file cannot be created, and the file is skipped. dest_directory should not reside within directory1, nor should directory1 have a cyclic directory structure, since in both cases cp attempts to copy an infinite amount of data. -R (recursive subtree copy) The -R option is identical to the -r option with the exception that directories copied by the -R option are created with read, write, and search permission for the owner. User and group permissions remain unchanged. With the -R and -r options, in addition to regular files and directories, cp also copies FIFOs, character and block device files and symbolic links. Only superusers can copy device files. All other users get an error. Symbolic links are copied so the target points to the same location that the source did. Warning: While copying a directory tree that has device special files, use the -r option; otherwise, an infinite amount of data is read from the device special file and is duplicated as a special file in the destination directory occupying large file system space. -e extarg Specifies the handling of any extent attributes of the file[s] to be copied. extarg takes one of the following values. warn Issues a warning message if extent attributes cannot be copied, but copies the file anyway. ignore Does not copy the extent attributes. force Fails to copy the file if the extent attribute can not be copied. Extent attributes can not be copied if the files are being copied to a file system which does not support extent attributes or if that file system has a different block size than the original. If -e is not specified, the default value for extarg is warn. Access Control Lists (ACLs) If new_file is a new file, or if a new file is created in dest_directory, it inherits the access control list of the original file1, file2, etc., altered to reflect any difference in ownership between the two files (see acl(5)). EXTERNAL INFLUENCES Environment Variables LC_CTYPE determines the interpretation of text as single and/or multi-byte characters. LANG and LC_CTYPE determine the local language equivalent of y (for yes/no queries). LANG determines the language in which messages are displayed. If LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, cp behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. EXAMPLES The following command moves the directory sourcedir and its contents to a new location (targetdir) in the file system. Since cp creates the new directory, the destination directory targetdir should not already exist. cp -r sourcedir targetdir && rm -rf sourcedir The -r option copies the subtree (files and subdirectories) in directory sourcedir to directory targetdir. The double ampersand (&&) causes a conditional action. If the operation on the left side of the && is successful, the right side is executed (and removes the old directory). If the operation on the left of the && is not successful, the old directory is not removed. This example is equivalent to: mv sourcedir targetdir To copy all files and directory subtrees in the current directory to an existing targetdir, use: cp -r * targetdir To copy all files and directory subtrees in sourcedir to targetdir, use: cp -r sourcedir/* targetdir Note that directory pathnames can precede both sourcedir and targetdir. To create a zero-length file, use any of the following: cat /dev/null >file cp /dev/null file touch file DEPENDENCIES NFS Access control lists of networked files are summarized (as returned in st_mode by stat()), but not copied to the new file. When using mv or ln on such files, a + is not printed after the mode value when asking for permission to overwrite a file. AUTHOR cp was developed by AT&T, the University of California, Berkeley, and HP. SEE ALSO cpio(1), ln(1), mv(1), rm(1), link(1M), lstat(2), readlink(2), stat(2), symlink(2), symlink(4), acl(5). STANDARDS CONFORMANCE cp: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
mkdir - Make a directory.
mkdir(1) mkdir(1) NAME mkdir - make a directory SYNOPSIS mkdir [-p] [-m mode] dirname ... DESCRIPTION mkdir creates specified directories in mode 0777 (possibly altered by umask unless specified otherwise by a -m mode option (see umask(1)). Standard entries, . (for the directory itself) and .. (for its parent) are created automatically. If dirname already exists, mkdir exits with a diagnostic message, and the directory is not changed. Options mkdir recognizes the following command-line options: -m mode After creating the directory as specified, the file permissions are set to mode, which is a symbolic mode string as defined for chmod (see chmod(1)). The umask(1) has precedence over -m. -p Intermediate directories are created as necessary. Otherwise, the full path prefix of dirname must already exist. mkdir requires write permission in the parent directory. For each directory name in the pathname prefix of the dirname argument that is not the name of an existing directory, the specified directory is created using the current umask setting, except that the equivalent of chmod u+wx is done on each component to ensure that mkdir can create lower directories regardless of the setting of umask. Each directory name in the pathname prefix of the dirname argument that matches an existing directory is ignored without error. If an intermediate path component exists, but has permissions set to prevent writing or searching, mkdir fails with an error message. If the dirname argument (including pathname prefix) names an existing directory, mkdir fails with an error message. If the -m option is used, the directory specified by dirname (excluding directories in the pathname prefix) is created with the permissions specified by mode. Only LINK_MAX subdirectories can be created (see limits(5)). EXTERNAL INFLUENCES Environment Variables LANG provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, mkdir will behave as if all internationalization variables are set to "C". See environ(5). LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE determines the interpretation of text as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. LC_MESSAGES determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH determines the location of message catalogues for the processing of LC_MESSAGES. International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS mkdir returns exit code 0 if all directories were successfully made. Otherwise, it prints a diagnostic and returns non-zero. EXAMPLES Create directory gem beneath existing directory raw in the current directory: mkdir raw/gem Create directory path raw/gem/diamond underneath the current directory and set permissions on directory diamond to read-only for all users (a=r): mkdir -p -m "a=r" raw/gem/diamond which is equivalent to (see chmod(1)): mkdir -p -m 444 raw/gem/diamond If directories raw or raw and gem already exist, only the missing directories in the specified path are created. SEE ALSO rm(1), sh(1), umask(1). STANDARDS CONFORMANCE mkdir: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
mv - Move or rename files and directories.
mv(1) mv(1) NAME mv - move or rename files and directories SYNOPSIS mv [-f|-i] [-e extarg] file1 new-file mv [-f|-i] [-e extarg] file1 [file2 ...] dest-directory mv [-f|-i] [-e extarg] directory1 [directory2 ...] dest-directory DESCRIPTION The mv command moves: - One file (file1) to a new or existing file (new-file). - One or more files (file1, [file2, ...]) to an existing directory (dest-directory). - One or more directory subtrees (directory1, [directory2, ...]) to a new or existing directory (dest-directory). Moving file1 to new-file is used to rename a file within a directory or to relocate a file within a file system or across different file systems. When the destination is a directory, one or more files are moved into that directory. If two or more files are moved, the destination must be a directory. When moving a single file to a new file, if new-file exists, its contents are destroyed. If the access permissions of the destination dest-directory or existing destination file new-file forbid writing, mv asks permission to overwrite the file. This is done by printing the mode (see chmod(2) and Access Control Lists below), followed by the first letters of the words yes and no in the language of the current locale, prompting for a response, and reading one line from the standard input. If the response is affirmative and the action is permissible, the operation occurs; if not, the command proceeds to the next source file, if any. If file1 is a file and new-file is a link to another file with other links, the other links remain and new-file becomes a new file. If file1 is a file with links or a link to a file, the existing file or link remains intact, but the name is changed to new-file which may or may not be in the directory where file1 resided, depending on directory path names used in the mv command. The last access and modification times of the file or files being moved remain unchanged. Options mv recognizes the following options: -f Perform mv commands without prompting for permission. This option is assumed when the standard input is not a terminal. -i Causes mv to write a prompt to standard output before moving a file that would overwrite an existing file. If the response from the standard input is affirmative, the file is moved if permissions allow the move. -e extarg Specifies the handling of any extent attributes of the files(s) to be moved. extarg can be one of the following values: warn Issue a warning message if extent attributes cannot be preserved, but move the file anyway. ignore Do not preserve extent attributes. force Do not move the file if the extent attributes cannot be preserved. If multiple source files are specified with a single target directory, mv will move the files that either do not have extent attributes or that have extent attributes that can be preserved. mv will not move the files if it cannot preserve their extent attributes. Extent attributes cannot be preserved if the files are being moved to a file system that does not support extent attributes or if that file system has a different block size than the original. If -e is not specified, the default value for extarg is warn. Access Control Lists (ACLs) If optional ACL entries are associated with new-file, mv displays a plus sign (+) after the access mode when asking permission to overwrite the file. If new-file is a new file, it inherits the access control list of file1, altered to reflect any difference in ownership between the two files (see acl(5)). EXTERNAL INFLUENCES Environment Variables LC_CTYPE determines the interpretation of text as single byte and/or multibyte characters. LANG and LC_CTYPE determine the local language equivalent of y (for yes/no queries). LANG determines the language in which messages are displayed. If LC_CTYPE is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of C (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, mv behaves as if all internationalization variables are set to C. See environ(5). International Code Set Support Single character and multibyte character code sets are supported. EXAMPLES Rename a file in the current directory: mv old-filename new-filename Rename a directory in the current directory: mv old-dirname new-dirname Rename a file in the current directory whose name starts with a nonprinting control character or a character that is special to the shell, such as - and * (extra care may be required depending on the situation): mv ./bad-filename new-filename mv ./?bad-filename new-filename mv ./*bad-filename new-filename Move directory sourcedir and its contents to a new location (targetdir) in the file system (upon completion, a subdirectory named sourcedir resides in directory targetdir): mv sourcedir targetdir Move all files and directories (including links) in the current directory to a new location underneath targetdir: mv * targetdir Move all files and directories (including links) in sourcedir to a new location underneath targetdir (sourcedir and targetdir are in separate directory paths): mv sourcedir/* targetdir WARNINGS If file1 and new-file exist on different file systems, mv copies the file and deletes the original. In this case the mover becomes the owner and any linking relationship with other files is lost. mv cannot carry hard links across file systems. If file1 is a directory, mv copies the entire directory structure onto the destination file system and deletes the original. mv cannot be used to perform the following operations: - Rename either the current working directory or its parent directory using the . or .. notation. - Rename a directory to a new name identical to the name of a file contained in the same parent directory. DEPENDENCIES NFS Access control lists of networked files are summarized (as returned in st_mode by stat(2)), but not copied to the new file. When using mv on such files,a +isnotprinted after the mode value when asking for permission to overwrite a file. AUTHOR mv was developed by AT&T, the University of California, Berkeley and HP. SEE ALSO cp(1), cpio(1), ln(1), rm(1), link(1M), lstat(2), readlink(2), stat(2), symlink(2), symlink(4), acl(5). STANDARDS CONFORMANCE mv: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
pwd - Present working directory name.
pwd(1) pwd(1) NAME pwd - working directory name SYNOPSIS pwd DESCRIPTION pwd prints the path name of the working (current) directory. EXTERNAL INFLUENCES Environment Variables LC_MESSAGES determines the language in which messages are displayed. If LC_MESSAGES is not specified in the environment or is set to the empty string, the value of LANG is used as a default for each unspecified or empty variable. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, pwd behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS Cannot open .. Read error in .. Possible file system trouble; contact system administrator. pwd: cannot access parent directories Current directory has been removed (usually by a different process). Use cd command to move to a valid directory (see cd(1)). EXAMPLES This command lists the path of the current working directory. If your home directory were /mnt/staff and the command cd camp/nevada were executed from the home directory, typing pwd would produce the following: /mnt/staff/camp/nevada AUTHOR pwd was developed by AT&T and HP. SEE ALSO cd(1). STANDARDS CONFORMANCE pwd: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
rm - Remove files or directories.
rm(1) rm(1) NAME rm - remove files or directories SYNOPSIS rm [-f|-i] [-Rr] file ... DESCRIPTION The rm command removes the entries for one or more files from a directory. If an entry was the last link to the file, the file is destroyed. Removal of a file requires write and search (execute) permission in its directory, but no permissions on the file itself. However, if the sticky bit is set on the directory containing the file, only the owner of the file, the owner of the directory, or a user having appropriate privileges can remove the file. If a user does not have write permission for a file to be removed and standard input is a terminal, a prompt containing the file name and its permissions is printed requesting that the removal of the file be confirmed (see Access Control Lists below). A line is then read from standard input. If that line begins with y the file is deleted; otherwise, the file remains. No questions are asked when the -f option is given or if standard input is not a terminal. If file is of type directory, and the -f option is not specified, and either the permissions of file do not permit writing and standard input is a terminal or the -i option is specified, rm writes a prompt to standard error and reads a line from standard input. If the response does not begin with y, it does nothing more with the current file and goes on to any remaining files. Options rm recognizes the following options: -f Force each file or directory to be removed without prompting for confirmation, regardless of the permissions of the entry. This option also suppresses diagnostic messages regarding nonexistent operands. This option does not suppress any diagnostic messages other than those regarding nonexistent operands. To suppress all error message and interactive prompts, the -f option should be used while redirecting standard error output to /dev/null. This option ignores any previous occurrence of the -i option. -i Write a prompt to standard error requesting confirmation before removing each entry. This option ignores any previous occurrence of the -f option. -R For each argument that is a directory, this option causes rm to recursively delete the entire contents of that directory before removing the directory itself. When used in conjunction with the -i option, rm asks whether to examine each directory before interactively removing files in that directory and again afterward to confirm removing the directory itself. The -R option will descend to arbitrary depths in a file hierarchy and will not fail due to path length limitations unless the length of file name, file specified by the user exceeds system limitations. -r Equivalent to -R. Access Control Lists If a file has optional ACL entries, rm displays a plus sign (+) after the file's permissions. The permissions shown summarize the file's st_mode value returned by stat() (see stat(2)). See also acl(5). EXTERNAL INFLUENCES Environment Variables LANG provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, rm will behave as if all internationalization variables are set to "C". See environ(5). LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE determines the interpretation of file names as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. LC_MESSAGES determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH determines the location of message catalogues for the processing of LC_MESSAGES. International Code Set Support Single- and multibyte character code sets are supported. DIAGNOSTICS Generally self-explanatory. Note that the -f option does not suppress all diagnostic messages. It is forbidden to remove the file .., in order to avoid the consequences of using a command such as: rm -r .* If a designated file is a directory, an error comment is printed unless the -R or -r option is used. EXAMPLES Remove files with a prompt for verification: rm -i file1 file2 Remove all the files in a directory: rm -i mydirectory/* Note that the previous command removes files only, and does not remove any directories in mydirectory. Remove a file in the current directory whose name starts with - or * or some other character that is special to the shell: rm ./-filename rm \*filename etc. Remove a file in the current directory whose name starts with some strange (usually nonprinting, invisible) character or perhaps has spaces at the beginning or end of the filename, prompting for confirmation: rm -i *filename* If *filename* is not unique in the directory, enter n when each of the other files is prompted. A powerful and dangerous command to remove a directory is: rm -fR directoryname or rm -Rf directoryname which removes all files and directories from directoryname without any prompting for verification to remove the files or the directories. This command should only be used when you are absolutely certain that all the files and directories in directoryname as well as directoryname itself are to be removed. DEPENDENCIES NFS rm does not display a plus sign (+) to indicate the existence of optional access control list entries when asking for confirmation before removing a networked file. SEE ALSO rmdir(1), unlink(2), acl(5). STANDARDS CONFORMANCE rm: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
rmdir - Remove directories.
rmdir(1) rmdir(1) NAME rmdir - remove directories SYNOPSIS rmdir [-f|-i] [-p] dir ... DESCRIPTION rmdir removes the directory entry for each dir operand that refers to an empty directory. Directories are removed in the order specified. Consequently, if a directory and a subdirectory of that directory are both specified as arguments, the subdirectory must be specified before the parent directory so that the parent directory will be empty when rmdir tries to remove it. Removal of a directory requires write and search (execute) permission in its parent directory, but no permissions on the directory itself; but if the sticky bit is set on the parent directory, only the owner of the directory, the owner of the parent directory, or a user having appropriate privileges can remove the directory. Options rmdir recognizes the following options: -f Force each directory to be removed without prompting for confirmation, regardless of the presence of the -i option. This option also suppresses diagnostic messages regarding non-existent operands. This option does not suppress any diagnostic messages other than those regarding non-existent operands. To suppress all error message and interactive prompts, the -f option should be used while redirecting the standard error output to /dev/null. This option ignores any previous occurrence of the -i option. -i Write a prompt to the standard error output requesting confirmation before removing each directory. This option ignores any previous occurrence of the -f option. -p Path removal. If, after removing a directory with more than one pathname component, the parent directory of that directory is now empty, rmdir removes the empty parent directory. This continues until rmdir encounters a non empty parent directory, or until all components of the original pathname have been removed. When used in conjunction with the -i option, rmdir asks whether to remove each directory component of a path. EXTERNAL INFLUENCES Environment Variables LANG provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the default value of "C" (see lang(5)) is used. If any of the internationalization variables contains an invalid setting, rmdir will behave as if all internationalization variables are set to "C". See environ(5). LC_ALL If set to a non-empty string value, overrides the values of all the other internationalization variables. LC_CTYPE determines the interpretation of dir names as single and/or multi-byte characters, the classification of characters as printable, and the characters matched by character class expressions in regular expressions. LC_MESSAGES determines the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output. NLSPATH determines the location of message catalogues for the processing of LC_MESSAGES. International Code Set Support Single- and multi-byte character code sets are supported. DIAGNOSTICS Generally self-explanatory. Note that the -f option does not suppress all diagnostic messages. EXAMPLES To remove directories with a prompt for verification: rmdir -i directories To remove as much as possible of a path, type: rmdir -p component1/component2/dir SEE ALSO rm(1), rmdir(2), stat(2). STANDARDS CONFORMANCE rmdir: SVID2, XPG2, XPG3, XPG4
![]() | CONTENTS | ![]() |