Several commands may be entered at the command prompt that allow the manipulation of files, such as attrib, copy, and sort. Attrib permits the user to change file attributes; copy permits the user to combine files; and sort sorts data. The attrib and sort commands are discussed below; copy was discussed in the "File-Management Commands" section.
The assoc command displays and changes the file name extension that is associated with a file type or application. The syntax it uses is
assoc [.ext[=[filetype]]]
To view the associated extension of file type .doc
Type assoc .doc
The attrib command allows the user to either display or change a file's attributes—Archive, Hidden, Read-Only, Compressed, and System (Compressed is available only on NTFS file systems and cannot be altered using this command). The syntax is
attrib [attributes] filename [/s]
Neither the attributes parameter nor the /s switch is entered to display the attributes associated with a particular file. Instead, the syntax is attrib filename. The filename parameter is the name of the file with the drive designation and path included where necessary. The /s switch is used when setting or changing attributes and instructs the command to change not only the files in the current directory but also those in the subdirectories. As with most commands, the wildcard characters * and ? may be used to designate multiple files to change.
Table A.38 identifies the acceptable values for the attributes parameter. More than one attribute can be set within a single command, but if the system or hidden attribute is set, it must be removed before any other attribute can be modified.
To add the Archive attribute to all the files in the current directory, enter
attrib +a *.*
Attribute |
Description |
---|---|
+a |
Adds the Archive attribute. |
-a |
Removes the Archive attribute. |
+h |
Adds the Hidden attribute. |
-h |
Removes the Hidden attribute. |
+r |
Adds the Read-Only attribute. |
-r |
Removes the Read-Only attribute. |
+s |
Adds the System attribute. |
-s |
Removes the System attribute. |
The sort command sorts the input data and outputs the result to the screen, a file, or a device. It also accepts input from another command, from a file, or from data entered on the terminal screen. The syntax of sort can be one of the following:
sort options < infilename > outfilename command | sort options > outfilename
The infilename parameter is the name of the file that contains the data to be sorted. The drive designation and directory path may be entered as necessary. The outfilename parameter is the name of the file that contains the sorted data. Once again, the drive designation and directory path may be entered if needed. The command parameter is a command whose output will be sorted by sort. Two options are available as shown in Table A.39.
If the command or infilename parameters are omitted, the sort command will take input as the user enters it on the screen until a CTRL+Z+ENTER sequence is encountered. If the outfilename parameter is omitted, the sorted data will display on the screen.
Option |
Description |
---|---|
/+n |
Sorts the data based on the character in column n. The default sort is based on the character in column 1. |
/r |
Executes a reverse sort either in reverse alphabetical or reverse numerical order |
Top |