There are a variety of ways to work with directories and their contents.
The command and an example are presented for each of the following directory tasks:
The mkdir command creates one or more new directories specified by the Directory parameter. Each new directory contains the standard entries . (dot) and .. (dot dot). You can specify the permissions for the new directories with the -m Mode flag.
When a new directory is created, it is created within the current, or working, directory unless you specify an absolute path name to another location in the file system.
For example, to create a new directory called Test in the current working directory with default permissions, enter:
mkdir Test
For example, to create a new directory called Test with rwxr-xr-x permissions in a previously created /home/demo/sub1 directory, enter:
mkdir -m 755 /home/demo/sub1/Test
For example, to create a new directory called Test with default permissions in the /home/demo/sub2 directory, enter:
mkdir -p /home/demo/sub2/Test
The -p flag creates the /home , /home/demo , and /home/demo/sub2 directories if they do not already exist.
See the mkdir command in the AIX Version 4.3 Commands Reference for the exact syntax.
The mvdir command moves directories or renames a directory.
For example, to move a directory, enter:
mvdir book manual
This moves the book directory under the directory named manual , if manual exists. Otherwise, the book directory is renamed to manual .
>For example, to move and rename a directory, enter:
mvdir book3 proj4/manual
This moves book3 to the directory named proj4 and renames it manual (if manual did not previously exist).
See the mvdir command in the AIX Version 4.3 Commands Reference for the exact syntax.
The pwd command writes to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a / (slash). The /(root) directory is represented by the first / (slash), and the last directory named is your current directory.
For example, to display your current directory, enter:
pwd
The full path name of your current directory is displayed similar to the following:
/home/thomas
See the pwd command in the AIX Version 4.3 Commands Reference for the exact syntax.
The cd command moves you from your present directory to another directory. You must have execute (search) permission in the specified directory.
If you do not specify a Directory parameter, the cd command moves you to your login directory ($HOME in the ksh and bsh environments, or $home in the csh environment). If the specified directory name is a full path name, it becomes the current directory. A full path name begins with a / (slash) indicating the /(root) directory, a . (dot) indicating current directory, or a .. (dot dot) indicating parent directory. If the directory name is not a full path name, the cd command searches for it relative to one of the paths specified by the $CDPATH shell variable (or $cdpath csh variable). This variable has the same syntax as, and similar semantics to, the $PATH shell variable (or $path csh variable).
For example, to change to your home directory, enter:
cd
For example, to change to the /usr/include directory, enter:
cd /usr/include
This changes the current directory to /usr/include .
For example, to go down one level of the directory tree to the sys directory, enter:
cd sys
If the current directory is /usr/include and it contains a subdirectory named sys , then /usr/include/sys becomes the current directory.
For example, to go up one level of the directory tree, enter:
cd ..
The special file name, .. (dot dot), refers to the directory immediately above the current directory, its parent directory.
See the cd command in the AIX Version 4.3 Commands Reference for the exact syntax.
The cp or copy command creates a copy of the contents of the file or directory specified by the SourceFile or SourceDirectory parameters into the file or directory specified by the TargetFile or TargetDirectory parameters. If the file specified as the TargetFile exists, the copy writes over the original contents of the file. If you are coping more than one SourceFile, the target must be a directory.
To place a copy of the SourceFile into a directory, specify a path to an existing directory for the TargetDirectory parameter. Files maintain their respective names when copied to a directory unless you specify a new file name at the end of the path. The cp command also copies entire directories into other directories if you specify the -r or -R flags.
For example, to copy all the files in a directory to a new directory, enter:
cp /home/janet/clients/* /home/nick/customers
This copies only the files in the clients directory to the customers directory.
For example, to copy a directory, including all its files and subdirectories, to another directory, enter:
cp -R /home/nick/clients /home/nick/customers
This copies the clients directory, including all its files, subdirectories, and the files in those subdirectories, under the customers directory.
See the cp command in the AIX Version 4.3 Commands Reference for the exact syntax.
You can display the contents of a directory by using either the li command or the ls command.
The li command lists information about each named File and the files in each named Directory. If File is an archived file and the -Rq flag is specified, the li command lists the files in the archive. If you do not specify a File or Directory, the li command displays the contents of the current directory.
When the li command displays the contents of a directory, it does not show entries for files whose names begin with a . (dot) unless you use the -a flag.
The li command lists file and directory names in alphabetical order. Control characters in file names are displayed in expanded form (for example, ^ D, \177 ).
For example, to list the files and directories in the current directory, enter:
li
For example, you can list the files and directories separated out by files, executable files, symbolic links, and directories. The executable files are surrounded by right and left angle brackets ( < > ), symbolic links are surrounded by at signs (@ ), and directories are surrounded by brackets ([ ] ). To see this listing, enter:
li -v
For example, to list all files and directories in the current directory, including those with names beginning with a . (dot), enter:
li -a
For example, to display detailed information, enter:
li -l chap1 .profile
This displays an extended listing with detailed information about chap1 and the .profile file.
For example, to display detailed information about a directory, enter:
li -d -l . manual manual/chap1
This displays a long listing for the . (dot) and manual directories, and for the manual/chap1 file.
For example, to list the contents of each directory in a tree, enter:
li -R manual
This lists the names in each subdirectory of the tree that starts with manual .
See the li command in the AIX Version 4.3 Commands Reference for the exact syntax.
The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags. If you do not specify a File or Directory, the ls command displays the contents of the current directory.
By default, the ls command displays all information in alphabetic order by file name. If the command is executed by a user with root authority, it uses the -A flag by default, listing all entries except . (dot) and .. (dot dot). To show all entries for files, including those that begin with a . (dot), use the ls -a command.
There are three main ways to format the output:
To determine the number of character positions in the output line, the ls command uses the $COLUMNS environment variable. If this variable is not set, the command reads the terminfo file. If the ls command cannot determine the number of character positions by either of these methods, it uses a default value of 80.
The information displayed with the -e and -l flags is interpreted as follows:
If the first character is:
d | Entry is a directory. |
b | Entry is a block special file. |
c | Entry is a character special file. |
l | Entry is a symbolic link. |
p | Entry is a first-in, first-out (FIFO) pipe special file. |
s | Entry is a local socket. |
- | Entry is an ordinary file. |
The next nine characters are divided into three sets of three characters each. The first three characters show the owner's permission. The next set of three characters shows the permission of the other users in the group. The last set of three characters shows the permission of anyone else with access to the file. The three characters in each set show read, write, and execute permission of the file. Execute permission of a directory lets you search a directory for a specified file.
Permissions are indicated as follows:
r | Read permission granted |
t | Only the directory owner or the file owner can delete or rename a file within that directory, even if others have write permission to the directory. |
w | Write (edit) permission granted |
x | Execute (search) permission granted |
- | Corresponding permission not granted. |
The information displayed with the -e flag is the same as with the -l flag, except for the addition of an 11th character interpreted as follows:
+ | Indicates a file has extended security information. For example, the file may have extended ACL, TCB, or TP attributes in the mode. |
- | Indicates a file does not have extended security information. |
When the size of the files in a directory are listed, the ls command displays a total count of blocks, including indirect blocks.
For example, to list all files in the current directory, enter:
ls -a
This lists all files, including
For example, to display detailed information, enter:
ls -l chap1 .profile
This displays a long listing with detailed information about chap1 and .profile .
For example, to display detailed information about a directory, enter:
ls -d -l . manual manual/chap1
This displays a long listing for the directories . and manual , and for the file manual/chap1 . Without the -d flag, this would list the files in the . and manual directories instead of the detailed information about the directories themselves.
See the ls command in the AIX Version 4.3 Commands Reference for the exact syntax.
The rmdir command removes the directory, specified by the Directory parameter, from the system. The directory must be empty (it can only contain . and ..) before you can remove it, and you must have write permission in its parent directory. Use the ls -a Directory command to check whether the directory is empty.
For example, to empty and remove a directory, enter:
rm mydir/* mydir/.* rmdir mydir
This removes the contents of mydir , then removes the empty directory. The rm command displays an error message about trying to remove the directories . (dot) and .. (dot dot), and then the rmdir command removes them and the directory itself.
Note that rm mydir/* mydir/.* first removes files with names that do not begin with a dot, and then removes those with names that do begin with a dot. You may not realize that the directory contains file names that begin with a dot because the ls command does not normally list them unless you use the -a flag.
For example, to remove the /tmp/jones/demo/mydir directory structure and all the directories beneath it, enter:
cd /tmp rmdir -p jones/demo/mydir
This removes the jones/demo/mydir directory from the /tmp directory. If a directory is not empty or you do not have write permission to it when it is to be removed, the command terminates with appropriate error messages.
See the rmdir command in the AIX Version 4.3 Commands Reference for the exact syntax.
The dircmp command compares the two directories specified by the Directory1 and Directory2 parameters and writes information about their contents to standard output. First, the dircmp command compares the file names in each directory. If the same file name appears in both, the dircmp command compares the contents of both files.
In the output, the dircmp command lists the files unique to each directory. It then lists the files with identical names in both directories, but with different contents. If no flag is specified, it also lists files that have identical contents as well as identical names in both directories.
For example, to summarize the differences between the files in the proj.ver1 and proj.ver2 directories, enter:
dircmp proj.ver1 proj.ver2
This displays a summary of the differences between the directories proj.ver1 and proj.ver2 . The summary lists separately the files found only in one directory or the other, and those found in both. If a file is found in both directories, the dircmp command notes whether the two copies are identical.
For example, to show the details of the differences between the files in the proj.ver1 and proj.ver2 directories, enter:
dircmp -d -s proj.ver1 proj.ver2
The -s flag suppresses information about identical files. The -d flag displays a diff listing for each of the differing files found in both directories.
See the dircmp command in the AIX Version 4.3 Commands Reference for the exact syntax.
Input and Output Redirection Overview
Backup Files and Storage Media