Merge pull request #30263 from robsean/patch-6

Translated
This commit is contained in:
Xingyu.Wang 2023-10-10 21:37:48 +08:00 committed by GitHub
commit 2278501b7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 556 additions and 556 deletions

View File

@ -1,556 +0,0 @@
[#]: subject: "ABCs of FreeDOS: 26 commands I use all the time"
[#]: via: "https://opensource.com/article/22/6/26-freedos-commands"
[#]: author: "Jim Hall https://opensource.com/users/jim-hall"
[#]: collector: "lkxed"
[#]: translator: "robsean"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
ABCs of FreeDOS: 26 commands I use all the time
======
On its 28th anniversary, I'm pleased to share my top 26 favorite FreeDOS commands.
![FreeDOS fish logo and command prompt on computer][1]
Image by: Jim Hall, CC BY-SA 4.0.
One of my family's first computers ran a command-line operating system called DOS, the "Disk Operating System." I grew up with DOS, and learned to leverage the command line to make my work easier. And so did a lot of other people. We loved DOS so much that in 1994, we created the FreeDOS Project. Today on June 29, we celebrate 28 years of FreeDOS.
If you're new to FreeDOS, you may be confused about how to use the different command line programs that come with it. Let's get started with 26 of my favorite FreeDOS commands. To learn more, add the /? option after most commands to get more information:
```
C:\>attrib /?
ATTRIB v2.1 - Displays or changes file attributes.
Copyright (c) 1998-2003, licensed under GPL2.
Syntax: ATTRIB { options | [path][file] | /@[list] }
Options:
  +H Sets the Hidden attribute.     -H  Clears the Hidden attribute.
  +S Sets the System attribute.     -S  Clears the System attribute.
  +R Sets the Read-only attribute.  -R  Clears the Read-only attribute.
  +A Sets the Archive attribute.    -A  Clears the Archive attribute.
  /S Process files in all directories in the specified path(es).
  /D Process directory names for arguments with wildcards.
  /@ Process files, listed in the specified file [or in stdin].
Examples:
  attrib file -rhs
  attrib +a -r dir1 dir2*.dat /s
  attrib -hs/sd /@list.txt *.*
```
### A is for ATTRIB
The `ATTRIB` program displays or changes a file's *attributes*. An attribute can be one of four values: Hidden (H), System (S), Read-only (R), and Archive (A).
Files marked as Hidden don't display in a directory listing. For example, suppose you want to "hide" a file called `SECRET.TXT` so no one would know it was there. First, you can show the attributes on that file to see its current settings:
```
C:\FILES>attrib secret.txt
[----A] SECRET.TXT
```
To hide this file, turn on the Hidden attribute by using the plus (`+` ) operator, like this:
```
C:\FILES>attrib +h secret.txt
[----A] -> [-H--A] SECRET.TXT
C:\FILES>dir
 Volume in drive C is FREEDOS2022
 Volume Serial Number is 333D-0B18
 Directory of C:\FILES
.                   <DIR>  05-27-2022  9:22p
..                  <DIR>  05-27-2022  9:22p
         0 file(s)              0 bytes
         2 dir(s)     279,560,192 bytes free
```
Another common way to use `ATTRIB` is by manipulating the Read-only attribute, so you don't accidentally overwrite an important file. Suppose you want to protect the `SECRET.TXT` file so you can't delete or change it. Turn on the Read-only attribute like this, with the `+R` modifier:
```
C:\FILES>attrib +r secret.txt
[----A] -> [---RA] SECRET.TXT
C:\FILES>del secret.txt
C:\FILES\SECRET.TXT: Permission denied
no file removed.
```
### B is for BEEP
If you need to add a little pizzazz to a batch file, you can use the `BEEP` command to get the user's attention. `BEEP` doesn't display anything to the screen, but simply generates a classic “beep” tone.
Note that `BEEP` uses the PC's built-in speaker to make the “beep” sound. If you boot FreeDOS using a virtual machine, check that your system is set up to correctly emulate the PC speaker. Otherwise, you will not hear anything.
### C is for CD
Like Linux, FreeDOS supports directories, which allow you to organize your files in a way that makes sense to you. For example, you might keep all of your files in a directory called `FILES`, and you might have other directories inside `FILES` for certain kinds of files, such as `DOCS` for word processor files, or `SPRDSHT` for spreadsheet files.
You can navigate into a directory using the `CD` or *change directory* command. The `CHDIR` command is the same as `CD`, if you prefer to use that syntax.
To change into a new directory, use the `CD` command with the destination directory:
```
C:\>cd files
C:\FILES>cd sprdsht
C:\FILES\SPRDSHT>dir
Volume in drive C is FREEDOS2022
Volume Serial Number is 333D-0B18
 
Directory of C:\FILES\SPRDSHT
 
. <DIR> 05-27-2022 9:59p
.. <DIR> 05-27-2022 9:59p
FIB WKS 2,093 05-27-2022 10:07p
LAB1 WKS 2,087 05-27-2022 10:10p
MIS100 WKS 2,232 05-27-2022 10:05p
3 file(s) 6,412 bytes
2 dir(s) 279,527,424 bytes free
```
You don't have to navigate one directory at a time. You can instead provide the full directory path you want to change to, with one `CD` command:
```
C:\>cd \files\sprdsht
C:\FILES\SPRDSHT>dir
Volume in drive C is FREEDOS2022
Volume Serial Number is 333D-0B18
 
Directory of C:\FILES\SPRDSHT
 
.  <DIR> 05-27-2022 9:59p
.. <DIR> 05-27-2022 9:59p
FIB WKS 2,093 05-27-2022 10:07p
LAB1 WKS 2,087 05-27-2022 10:10p
MIS100 WKS 2,232 05-27-2022 10:05p
3 file(s) 6,412 bytes
2 dir(s) 279,527,424 bytes free
```
### D is for DELTREE
If you need to delete a single file, you can use the `DEL` command. To remove an empty directory, you can use the `RMDIR` or `RD` commands. But what if you want to delete a directory that has lots of files and subdirectories inside it?
A directory with other directories inside it is called a *directory tree*. You can delete an entire directory tree with the `DELTREE` command. For example, to delete your `FILES` directory, including all the files and directories it contains, type this command:
```
C:\>deltree files
    [DEFAULT-BUILD v1.02g] of DELTREE.  The "ROOT-SAFETY-CHECK" is enabled.
Delete directory "C:\FILES"
and all its subdirectories?
[Y] [N] [Q], [ENTER] ?  Y
==> Deleting "C:\FILES" ...
```
You can easily and quickly wipe out a lot of work with a single `DELTREE` command, so the FreeDOS `DELTREE` prompts you to ask if this is really something you want to do. Use this command carefully.
### E is for EDIT
If you need to edit a text file on FreeDOS, the `EDIT` program lets you do that quickly and easily. For example, to start editing a file called `HELLO.TXT`, type `EDIT HELLO.TXT`. If the `HELLO.TXT` file already exists, `EDIT` opens the file for editing. If `HELLO.TXT` doesn't exist yet, then `EDIT` starts a new file for you.
![Image of edit][3]
FreeDOS `EDIT` uses a friendly interface that should be easy for most people to use. Use the menus to access the various features of EDIT, including saving a file, opening a new file, or exiting the editor. To access the menus, tap the Alt key on your keyboard, then use the arrow keys to get around and Enter to select an action.
![Image of save menu][4]
### F is for FIND
If you need to find text in a file, the `FIND` command does the job. Similar to `fgrep` on Linux, `FIND` prints lines that contain a string. For example, to check the "Menu Default" entry in the `FDCONFIG.SYS` file, use `FIND` like this:
```
C:\>find "MENUDEFAULT" fdconfig.sys
---------------- FDCONFIG.SYS
MENUDEFAULT=2,5
```
If you aren't sure if the string you want to find uses uppercase or lowercase letters, add the `/I` option to ignore the letter case:
```
C:\>find /i "menudefault" fdconfig.sys
---------------- FDCONFIG.SYS
MENUDEFAULT=2,5
```
### G is for GRAPHICS
If you want to capture a screen, you might use the **PrtScr** (Print Screen) key on your keyboard to print the text on your monitor directly to a printer. However, this only works for plain text. If you want to print graphic screens, you need to load the `GRAPHICS` program.
`GRAPHICS` supports different printer types, including HP PCL printers, Epson dot matrix printers, and PostScript-compatible printers. For example, if you have an HP laser printer connected to your computer, you can load support for that printer by typing this command:
```
C:\>graphics hpdefault
Running in MS GRAPHICS compatibility mode...
Using HPPCL type for type hpdefault
  If you think this is not correct, mail me (see help text).
Printing black as white and white as black
which internally uses /I of this GRAPHICS.
You can use the following command directly instead of
GRAPHICS [your options] in the future:
LH GRAPH-HP /I
Note that GRAPH-HP allows extra options:
  /E economy mode, /1 use LPT1, /2 use LPT2, /3 use LPT3,
  /R for random instead of ordered dither
  /C for 300dpi instead of 600dpi
Driver to make 'shift PrtScr' key work
even in CGA, EGA, VGA, MCGA graphics
modes loaded, in HP PCL mode.
```
### H is for HELP
If you're new to FreeDOS, you can get hints on how to use the different commands by typing `HELP`. This brings up the FreeDOS Help system, with documentation on all the commands:
![Image of FreeDos help system][6]
### I is for IF
You can add conditional statements to your command line or *batch file* using the `IF` statement. `IF` makes a simple test, then executes a single command. For example, to print the result "It's there" if a certain file exists, you can type:
```
C:\>if exist kernel.sys echo It's there
It's there
```
If you want to test the opposite, use the `NOT` keyword before the test. For example, to print "Not equal" if two strings are not the same value, type this:
```
C:\>if not "a"=="b" echo Not equal
Not equal
```
### J is for JOIN
Early DOS versions were fairly simple; the first version of DOS didn't even support directories. To provide backwards compatibility for those older programs, we have the `JOIN` program as a neat workaround. `JOIN` replaces a path with a drive letter, so you can put an old program in its own subdirectory, but access it using a single drive letter.
Let's say you had an old application called `VC` that doesn't understand directories. To keep working with `VC`, you can "join" its path to a drive letter. For example:
```
JOIN V: D:\VC
```
FreeDOS implements `JOIN` as `SWSUBST`, which also combines features from the similar `SUBST` command. To join the `D:\VC` path to a new drive letter called `V:`, type:
```
C:\>swsubst v: d:\vc
C:\>dir v:
Volume in drive V is DATA
Volume Serial Number is 212C-1DF8
Directory of V:\
. <DIR> 02-21-2022 10:35p
.. <DIR> 02-21-2022 10:35p
VC COM 27,520 07-14-2019 4:48p
1 file(s) 27,520 bytes
2 dir(s) 48,306,176 bytes free
```
### K is for KEYB
DOS assumes a US keyboard layout by default. If your keyboard is different, you can use the `KEYB` command to load a new keyboard language layout. For example, to load a German keyboard layout, type:
```
C:\>keyb gr
FreeDOS KEYB 2.01 - (c) Aitor Santamaría Merino - GNU GPL 2.0
Keyboard layout : C:\FREEDOS\BIN\KEYBOARD.SYS:GR [858] (3)
```
### L is for LABEL
FreeDOS names each floppy drive and hard drive with a *label*. These labels provide a handy way to identify what a disk might contain. The `LABEL` command was immensely useful when you needed store files across a number of different floppy disks, where you might label one floppy "Data" and another floppy as "Games."
To assign a new label to a drive, or to change the existing label on a drive, use LABEL like this:
```
D:\>label d: data
D:\>dir /w
Volume in drive D is DATA
Volume Serial Number is 212C-1DF8
Directory of D:\
[123] [ABILITY] [ASEASY] [GAMES2] [QUATTRO]
[SRC] [TEMP] [THE] [VC] [WORD]
[WS400] EDLIN16.EXE EDLIN32.EXE MYENV.BAT
3 file(s) 113,910 bytes
11 dir(s) 48,306,176 bytes free
```
### M is for MEM
Running programs and loading drivers takes memory. To see how much memory your system has, and how much memory is free for running DOS programs, use the `MEM` command:
```
C:\>mem
Memory Type Total Used Free
---------------- -------- -------- --------
Conventional 639K 11K 628K
Upper 104K 18K 86K
Reserved 281K 281K 0K
Extended (XMS) 15,224K 537K 14,687K
---------------- -------- -------- --------
Total memory 16,248K 847K 15,401K
 
Total under 1 MB 743K 29K 714K
 
Total Expanded (EMS) 8,576K (8,781,824 bytes)
Free Expanded (EMS) 8,192K (8,388,608 bytes)
 
Largest executable program size 628K (643,104 bytes)
Largest free upper memory block 84K ( 85,728 bytes)
FreeDOS is resident in the high memory area.
```
### N is for NANSI
If you want to add a little color to the FreeDOS command line, you can use ANSI escape sequences. These sequences are so named because each starts with code 33 (the `ESC` character) and a special sequence of characters, as defined by the American National Standards Institute, or ANSI.
FreeDOS supports ANSI escape sequences through the `NANSI.SYS` driver. With `NANSI` loaded, your FreeDOS console interprets the ANSI escape sequences, such as setting the text colors.
![Image of Nansi][8]
### O is for oZone
FreeDOS is a command line operating system, but some folks prefer to use a graphical user interface instead. That's why FreeDOS 1.3 includes several graphical desktops. One desktop I like is called oZone, which provides a sleek, modern-looking interface.
![Image of Ozone GUI][9]
Note that oZone has a few annoying bugs, and could use some love from a developer out there. If you're interested in making oZone even better, feel free to download the source code.
### P is for PROMPT
The standard FreeDOS command-line prompt tells you where you are in the filesystem. When you first boot FreeDOS, your prompt looks like `C:\>`, which means the "\" (root) directory on the "C:" drive. The ">" character indicates where you can type a command.
If you prefer different information on your prompt, use the `PROMPT` command to change it. You can represent different information with a special code preceded with `$`, such as `$D` for the date and `$T` for the time. For example, you can make your FreeDOS command line look like a Linux prompt with the `$$` instruction, to print a single dollar sign:
```
C:\>prompt $$
$
```
Type `PROMPT /?` to see a list of all special codes.
### Q is for QBASIC
FreeDOS doesn't actually have QBASIC. That was a proprietary BASIC programming environment for MS-DOS. Instead, we provide several open source compilers, including some for BASIC programming.
The FreeBASIC Compiler should compile most QBASIC programs out there. Here's a simple "guess the number" example:
```
dim number as integer
dim guess as integer
randomize timer
number = int( 10 * rnd() ) + 1
print "Guess the number from 1 to 10:"
do
input guess
if guess < number then print "Too low"
if guess > number then print "Too high"
loop while guess <> number
print "That's right!"
```
Use the `FBC` command to compile the program with FreeBASIC:
```
C:\DEVEL\FBC>fbc guess.bas
```
Here's a quick demonstration of that simple game:
```
C:\DEVEL\FBC>guess
Guess the number from 1 to 10:
? 5
Too high
? 3
Too low
? 4
That's right!
```
### R is for REM
Comments are great when writing programs; comments help us understand what the program is supposed to do. You can do the same in batch files using the `REM` command. Anything after the `REM` is ignored in a batch file.
```
REM this is a comment
```
### S is for SET
The FreeDOS command line uses a set of variables called *environment variables* that let you customize your system. You can set these variables with the `SET` command. For example, use the `DIRCMD` variable to control how `DIR` arranges directory listings. To set the `DIRCMD` variable, use the `SET` command:
```
SET DIRCMD=/O:GNE
```
This tells `DIR` to order (O) the output by grouping (G) directories first, then sorting the results by name (N) and extension (E).
### T is for TYPE
The `TYPE` command is one of the most-often used DOS commands. `TYPE` displays the contents of a file, similar to `cat` on Linux.
```
C:\DEVEL>type hello.c
#include
int
main()
{
puts("Hello world");
return 0;
}
```
### U is for UNZIP
On Linux, you may be familiar with the standard Unix archive command: `tar`. There's a version of tar on FreeDOS too (and a bunch of other popular archive programs), but the de facto standard archiver on DOS is `ZIP` and `UNZIP`. Both are installed in FreeDOS 1.3 by default.
Let's say I had a zip archive of some files. If I want to extract the entire Zip file, I could just use the `UNZIP` command and provide the Zip file as a command-line option. That extracts the archive starting at my current working directory. Unless I'm restoring a previous version of something, I usually don't want to overwrite my current files. In that case, I will want to extract the archive to a new directory. You can specify the destination path with the `-d` ("destination") command-line option:
```
D:\SRC>unzip monkeys.zip -d monkeys.new
Warning: TZ environment variable not found, cannot use UTC times!!
Archive: monkeys.zip
creating: monkeys.new/monkeys/
inflating: monkeys.new/monkeys/banana.c
inflating: monkeys.new/monkeys/banana.obj
inflating: monkeys.new/monkeys/banana.exe
creating: monkeys.new/monkeys/putimg/
inflating: monkeys.new/monkeys/putimg/putimg.c
inflating: monkeys.new/monkeys/putimg/putimg.obj
inflating: monkeys.new/monkeys/putimg/putimg.exe
```
To learn more about the `ZIP` and `UNZIP` commands, read [How to archive files on FreeDOS][11].
### V is for VER
In the old days of DOS, the `VER` command reported the DOS distribution you were running, such as "MS-DOS 5.0.D" With FreeDOS, the `VER` command gives you additional details, such as the version of the FreeDOS Shell:
```
C:\DEVEL>ver
FreeCom version 0.85a - WATCOMC - XMS_Swap [Jul 10 2021 19:28:06]
```
If you also want to see the FreeDOS kernel version and the DOS compatibility level, add the `/R` option:
```
C:\DEVEL>ver /r
FreeCom version 0.85a - WATCOMC - XMS_Swap [Jul 10 2021 19:28:06]
DOS version 7.10
FreeDOS kernel 2043 (build 2043 OEM:0xfd) [compiled May 14 2021]
```
### W is for WHICH
The FreeDOS command line can run programs from a list of different directories, identified in a `PATH` variable. You can use the `WHICH` command to identify exactly where a program is located. Just type `WHICH` plus the name of the program you want to locate:
```
C:\>which xcopy
xcopy C:\FREEDOS\BIN\XCOPY.EXE
```
### X is for XCOPY
The `COPY` command copies only files from one place to another. If you want to extend the copy to include any directories, use the `XCOPY` command instead. I usually add the `/E` option to include all subdirectories, including empty ones, so I can copy the entire directory tree. This makes an effective backup of any project I am working on:
```
D:\SRC>xcopy /e monkeys monkeys.bak
Does MONKEYS.BAK specify a file name
or directory name on the target (File/Directory)? d
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.C
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.OBJ
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.EXE
Copying D:\SRC\MONKEYS\BANANA.C
Copying D:\SRC\MONKEYS\BANANA.OBJ
Copying D:\SRC\MONKEYS\BANANA.EXE
6 file(s) copied
```
### Y is for Yellow
This isn't a command, but interesting trivia about how DOS displays colors. If you've looked carefully at FreeDOS, you've probably noticed that text only comes in a limited range of colors—sixteen text colors, and eight background colors.
The IBM 5153 color display presented color to the user by lighting up tiny red, green, and blue phosphor dots at different brightness levels to create a palette of 16 text colors and 8 background colors. Early PCs could only display the background color in the "normal intensity" level; only text colors could use bright colors.
If you look at the text colors, you have black, blue, green, cyan, red, magenta, orange, and white. The "bright" versions of these colors are bright black (a dull gray), bright blue, bright green, bright cyan, bright red, bright magenta, yellow, and bright white. The "bright" version of orange is actually yellow. There is no "bright orange."
If you want to learn more about text colors, read our article about [Why FreeDOS has 16 colors][12].
### Z is for ZIP
You can use `ZIP` at the DOS command line to create archives of files and directories. This is a handy way to make a backup copy of your work or to release a "package" to use in a future FreeDOS distribution. For example, let's say I wanted to make a backup of my project source code, which contains these source files:
```
D:\SRC>zip -9r monkeys.zip monkeys
zip warning: TZ environment variable not found, cannot use UTC times!!
adding: monkeys/ (stored 0%)
adding: monkeys/banana.c (deflated 66%)
adding: monkeys/banana.obj (deflated 26%)
adding: monkeys/banana.exe (deflated 34%)
adding: monkeys/putimg/ (stored 0%)
adding: monkeys/putimg/putimg.c (deflated 62%)
adding: monkeys/putimg/putimg.obj (deflated 29%)
adding: monkeys/putimg/putimg.exe (deflated 34%)
```
ZIP sports a ton of command-line options to do different things, but the command line options I use most are `-r` to process directories and subdirectories recursively, and `-9` to provide the maximum compression possible. `ZIP` and `UNZIP` use a Unix-like command line, so you can combine options behind the dash: `-9r` gives maximum compression and include subdirectories in the Zip file.
For more details about how to use the `ZIP` and `UNZIP` commands, read [How to archive files on FreeDOS][13].
### New FreeDOS guides
Ready for the next step in your FreeDOS journey? Check out our new eBooks and start experimenting with FreeDOS now!
**[A guide to using FreeDOS][14]**
**[An advanced guide to FreeDOS internals][15]**
Image by: (Jim Hall, CC BY-SA 40)
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/6/26-freedos-commands
作者:[Jim Hall][a]
选题:[lkxed][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jim-hall
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/freedos-fish-laptop-color.png
[2]: https://opensource.com/article/22/6/linux-attr-command
[3]: https://opensource.com/sites/default/files/2022-06/FREEDedit_0.png
[4]: https://opensource.com/sites/default/files/2022-06/Freededit-save.png
[5]: https://opensource.com/Linux%20find%20cheat%20sheet
[6]: https://opensource.com/sites/default/files/2022-06/Freedhelp.system.png
[7]: https://opensource.com/article/22/6/linux-cheat-command
[8]: https://opensource.com/sites/default/files/2022-06/FreeDnansi.png
[9]: https://opensource.com/sites/default/files/2022-06/FreeDozone.png
[10]: https://opensource.com/article/21/1/fortran
[11]: https://opensource.com/article/21/6/archive-files-freedos
[12]: https://opensource.com/article/21/6/freedos-sixteen-colors
[13]: https://opensource.com/article/21/6/archive-files-freedos
[14]: https://opensource.com/downloads/guide-using-freedos
[15]: https://opensource.com/downloads/advanced-freedos

View File

@ -0,0 +1,556 @@
[#]: subject: "ABCs of FreeDOS: 26 commands I use all the time"
[#]: via: "https://opensource.com/article/22/6/26-freedos-commands"
[#]: author: "Jim Hall https://opensource.com/users/jim-hall"
[#]: collector: "lkxed"
[#]: translator: "robsean"
[#]: reviewer: " "
[#]: publisher: " "
[#]: url: " "
FreeDOS 的基础知识: 我一直在使用的 26 个命令
======
在它的 28 岁生日之时,我很高兴分享我最喜欢的 26 个 FreeDOS 命令。
![FreeDOS fish logo and command prompt on computer][1]
图片: Jim Hall, CC BY-SA 4.0.
我家最早的一批计算机中有一台运行着一款名称为 DOS 的命令行操作系统,即 " <ruby>磁盘操作系统<rt>Disk Operating System</rt></ruby> "。我是在 DOS 系统环境中长大的,学会了利用命令行来使我的工作更轻松。很多其他的人也是如此。我们非常爱 DOS 所以在1994年我们创建了 FreeDOS 工程。在06月29日的今天我们庆祝 FreeDOS 的28岁生日。
如果你的 FreeDOS 的初学者,你可能会对如何使用其附带的不同的命令行程序感到困惑。让我们从我最喜欢的 26 个 FreeDOS 命令开始吧。要学习更多的信息,在大部分命令的后面添加 /? 选项来获取更多的信息:
```
C:\>attrib /?
ATTRIB v2.1 - 显示或更高文件属性。
版权所有 (c) 1998-2003遵循 GPL2 协议。
语法: ATTRIB { options | [path][file] | /@[list] }
选项:
  +H 设置隐藏属性。     -H  清除隐藏属性。
  +S 设置系统属性。     -S  清除系统属性。
  +R 设置只读属性。  -R  清除只读属性。
  +A 设置存档属性。    -A  清楚存档属性。
  /S 处理具体指定路径中的所有目录中的文件。
  /D 处理带有通配符的参数的目录名称。
  /@ 处理文件,在具体指定文件[或在stdin]中的文件。
示例:
  attrib file -rhs
  attrib +a -r dir1 dir2*.dat /s
  attrib -hs/sd /@list.txt *.*
```
### A 的意思是 ATTRIB
`ATTRIB` 程序显示或更改文件的 *属性* 。属性可以是以下四个值之一:隐藏 (H)、系统 (S)、只读 (R)、存档 (A)。
标记为隐藏的文件将不会在目录列表中显示。例如,假设你想隐藏一个名称为 `SECRET.TXT` 的文件,这样就不会有人它在那里。首先,你可以显示该文件的属性,以便查看它的当前设置:
```
C:\FILES>attrib secret.txt
[----A] SECRET.TXT
```
为隐藏这个文件,使用加号 (`+`) 操作符来开启用隐藏属性,像这样:
```
C:\FILES>attrib +h secret.txt
[----A] -> [-H--A] SECRET.TXT
C:\FILES>dir
 Volume in drive C is FREEDOS2022
 Volume Serial Number is 333D-0B18
 Directory of C:\FILES
.                   <DIR>  05-27-2022  9:22p
..                  <DIR>  05-27-2022  9:22p
         0 file(s)              0 bytes
         2 dir(s)     279,560,192 bytes free
```
`ATTRIB` 的另一种常见使用方法是操作只读属性,这样你就不会意外地覆盖重要的文件。假设你想要保护 `SECRET.TXT` 文件,这样你就不能删除或更改它。使用 `+R` 修饰符 ,打开只读属性,像这样:
```
C:\FILES>attrib +r secret.txt
[----A] -> [---RA] SECRET.TXT
C:\FILES>del secret.txt
C:\FILES\SECRET.TXT: Permission denied
no file removed.
```
### B 的意思是 <ruby>嘟嘟<rt>BEEP</rt></ruby>
如果你需要在一个批处理文件中添加一些激情活力,你可以使用 `BEEP` 命令来获取用户的注意力。`BEEP` 不会在屏幕上显示任何内容,但是会简单地生成一个 “嘟嘟” 声音信号。
注意:`BEEP` 使用个人计算机内置的扬声器来发出 “嘟嘟” 声音。如果你使用一台虚拟机器来引导启用 FreeDOS ,检查你的系统是否建立正确的模拟个人计算机扬声器。否则,你将不会听到任何声音。
### C 的意思是 CD
像 Linux 一样FreeDOS 支持目录,这会允许你以一种来你有帮助的方式来组织你的文件。例如,你可以在一个名称为 `FILES` 的命令中存放你的全部文件,对于某些类型的文件,你可能会有其它的目录,例如,针对字处理器文件的 `DOCS` ,或者针对表格文件的 `SPRDSHT`
你可以使用 `CD` 命令来导航到一个目录。 或通过 *更改目录* 的方式,`CHDIR` 命令类似于 `CD` 命令,如果你更喜欢使用这种语法。
为更改到一个新的目录,使用 `CD` 目录和目标目录:
```
C:\>cd files
C:\FILES>cd sprdsht
C:\FILES\SPRDSHT>dir
Volume in drive C is FREEDOS2022
Volume Serial Number is 333D-0B18
 
Directory of C:\FILES\SPRDSHT
 
. <DIR> 05-27-2022 9:59p
.. <DIR> 05-27-2022 9:59p
FIB WKS 2,093 05-27-2022 10:07p
LAB1 WKS 2,087 05-27-2022 10:10p
MIS100 WKS 2,232 05-27-2022 10:05p
3 file(s) 6,412 bytes
2 dir(s) 279,527,424 bytes free
```
你不必一次导航一层目录。相反,你可以使用一个 `CD` 命令和提供完整的你想要更改到的目录路径:
```
C:\>cd \files\sprdsht
C:\FILES\SPRDSHT>dir
Volume in drive C is FREEDOS2022
Volume Serial Number is 333D-0B18
 
Directory of C:\FILES\SPRDSHT
 
.  <DIR> 05-27-2022 9:59p
.. <DIR> 05-27-2022 9:59p
FIB WKS 2,093 05-27-2022 10:07p
LAB1 WKS 2,087 05-27-2022 10:10p
MIS100 WKS 2,232 05-27-2022 10:05p
3 file(s) 6,412 bytes
2 dir(s) 279,527,424 bytes free
```
### D 的意思是 DELTREE
如果需要删除一个单个文件,你可以使用 `DEL` 命令。为删除一个空的目录,你可以使用 `RMDIR``RD` 命令。但是,如果你想删除一个有很多文件和子目录的目录?
一个包含有其它目录的目录称为 *目录树* 。你可以使用 `DELTREE` 命令来删除整个目录树。例如,为删除你的 `FILES` 目录,包括其中包含的所有的文件和目录,输入这个命令:
```
C:\>deltree files
    [DEFAULT-BUILD v1.02g] of DELTREE.  The "ROOT-SAFETY-CHECK" is enabled.
Delete directory "C:\FILES"
and all its subdirectories?
[Y] [N] [Q], [ENTER] ?  Y
==> Deleting "C:\FILES" ...
```
你可以使用一个单一的 `DELTREE` 命令来轻松快捷地完成很多工作因此FreeDOS 的 `DELTREE` 提示会询问你是否真的想要这样做。谨慎地使用这个命令。
### E 的意思是 EDIT
如果你需要在 FreeDOS 上编辑一个文本文件,`EDIT` 程序会让你轻松快速地完成任务。例如,为开始编辑一个名称为 `HELLO.TXT` 的文件,输入 `EDIT HELLO.TXT` 。如果 `HELLO.TXT` 文件已经存在,`EDIT` 打开文件并开始编辑。如果 `HELLO.TXT` 尚未存在,那么 `EDIT` 为你开启一个新的文件。
![Image of edit][3]
FreeDOS 的 `EDIT` 使用了一种友好的界面,对大多数人来说应该很容易使用。使用菜单来访问 EDIT 的各种特色功能,包括保存文件、打开一个新的文件、或者退出编辑器。为访问菜单,在你的键盘上按下 Alt 按键,然后使用箭头按键来避开和进入选择的动作。
![Image of save menu][4]
### F 的意思是 FIND
如果你需要在一个文件中查找文本,`FIND` 命令可以完成这项工作。类似于在 Linux 上的 `fgrep` `FIND` 会打印一些包含一个字符串的行。例如,为检查 `FDCONFIG.SYS` 文件中的 "Menu Default" 条目项,像这样使用 `FIND` :
```
C:\>find "MENUDEFAULT" fdconfig.sys
---------------- FDCONFIG.SYS
MENUDEFAULT=2,5
```
如果你不确定你想要查找的字符串是使用的大写字母还是小写字母,添加 `/I` 选项来忽略字母的大小写情况:
```
C:\>find /i "menudefault" fdconfig.sys
---------------- FDCONFIG.SYS
MENUDEFAULT=2,5
```
### G 的意思是 GRAPHICS
如果你想要捕捉屏幕,你可以使用你键盘上的 **PrtScr** (<ruby>打印屏幕<rt>Print Screen</rt></ruby>) 按键来直接将你显示器上的文本打印到打印机上。不过,这只对纯文本来说有效。如果你新定义图形屏幕,你需要加载 `GRAPHICS` 程序。
`GRAPHICS` 支持不同的打印机类型,包括 HP 的 PCL 打印机、Epson 的点阵打印机和兼容PostScript的打印机。例如如果有一台连接到你的计算机的 HP 的激光打印机,你可以通过输入这条命令来为这台打印机加载支持:
```
C:\>graphics hpdefault
Running in MS GRAPHICS compatibility mode...
Using HPPCL type for type hpdefault
  If you think this is not correct, mail me (see help text).
Printing black as white and white as black
which internally uses /I of this GRAPHICS.
You can use the following command directly instead of
GRAPHICS [your options] in the future:
LH GRAPH-HP /I
Note that GRAPH-HP allows extra options:
  /E economy mode, /1 use LPT1, /2 use LPT2, /3 use LPT3,
  /R for random instead of ordered dither
  /C for 300dpi instead of 600dpi
Driver to make 'shift PrtScr' key work
even in CGA, EGA, VGA, MCGA graphics
modes loaded, in HP PCL mode.
```
### H 的意思是 HELP
如果你刚刚来到 FreeDOS 的世界,你可以通过输入 `HELP` 来获取如何使用不同命令的提示。这将带来 FreeDOS 的帮助系统,包含所有命令的文档:
![Image of FreeDos help system][6]
### I 的意思是 IF
你可以使用 `IF` 语句来将条件语句添加到你的命令行或*批处理文件* 。`IF` 进行一次简短的测试,然后执行一个单个命令。例如,如果存在某个文件,那么打印结果 "It's there" ,你可以输入:
```
C:\>if exist kernel.sys echo It's there
It's there
```
如果你想要测试相反的东西,在测试内容前,使用 `NOT` 关键字。例如,如果两个字符串的值不相同,那么打印结果 "Not equal" ,输入这条语句:
```
C:\>if not "a"=="b" echo Not equal
Not equal
```
### J 的意思是 JOIN
早期的 DOS 版本是相当简单的DOS 的第一个版本甚至不支持目录。为向这些较旧的程序提供向后兼容性,我们需要 `JOIN` 程序来作为一种巧妙的应变方法。`JOIN` 使用驱动器字母代替路径,这样,你可以将旧程序放入其自己的子目录中,但是,使用一个单个驱动器字母来访问它。
让我们假设你有一个名称为 `VC` 的旧应用程序,它不懂目录。为保持 `VC` 的工作,你可以 <ruby> 链接<rt>join</rt></ruby> 它的路径到一个驱动器字母。例如:
```
JOIN V: D:\VC
```
FreeDOS 将 `JOIN` 实施为 `SWSUBST`,它也兼备类似 `SUBST` 命令的特色功能。为将 `D:\VC` 路径链接到到一个名称为 `V:` 的驱动器字母,输入:
```
C:\>swsubst v: d:\vc
C:\>dir v:
Volume in drive V is DATA
Volume Serial Number is 212C-1DF8
Directory of V:\
. <DIR> 02-21-2022 10:35p
.. <DIR> 02-21-2022 10:35p
VC COM 27,520 07-14-2019 4:48p
1 file(s) 27,520 bytes
2 dir(s) 48,306,176 bytes free
```
### K 的意思是 KEYB
DOS 默认采用美式英语键盘布局。你的键盘是不同的,你可以使用 `KEYB` 命令来加载新的键盘语言布局。例如,为为加载一种德语键盘布局,输入:
```
C:\>keyb gr
FreeDOS KEYB 2.01 - (c) Aitor Santamaría Merino - GNU GPL 2.0
Keyboard layout : C:\FREEDOS\BIN\KEYBOARD.SYS:GR [858] (3)
```
### L 的意思是 LABEL
FreeDOS 使用<ruby>标签<rt>label</rt></ruby>来命名每个软盘驱动器和硬盘驱动器。这些标签提供了一种识别磁盘可能包含内容的方法。当你需要将文件存储到单个不同的软盘上时,`LABEL` 命令是非常有用的,你可以标签一个软盘 "Data",另一个软盘为 "Games" 。
为分配一个新的标签到一个驱动器。或者更改在一个驱动器上的现存标签。像这样使用标签:
```
D:\>label d: data
D:\>dir /w
Volume in drive D is DATA
Volume Serial Number is 212C-1DF8
Directory of D:\
[123] [ABILITY] [ASEASY] [GAMES2] [QUATTRO]
[SRC] [TEMP] [THE] [VC] [WORD]
[WS400] EDLIN16.EXE EDLIN32.EXE MYENV.BAT
3 file(s) 113,910 bytes
11 dir(s) 48,306,176 bytes free
```
### M 的意思是 MEM
运行程序和加载驱动程序会占用内存。可以查看你的系统有多少内存,以及有多少可用来运行 DOS 程序,使用 `MEM` 命令:
```
C:\>mem
Memory Type Total Used Free
---------------- -------- -------- --------
Conventional 639K 11K 628K
Upper 104K 18K 86K
Reserved 281K 281K 0K
Extended (XMS) 15,224K 537K 14,687K
---------------- -------- -------- --------
Total memory 16,248K 847K 15,401K
 
Total under 1 MB 743K 29K 714K
 
Total Expanded (EMS) 8,576K (8,781,824 bytes)
Free Expanded (EMS) 8,192K (8,388,608 bytes)
 
Largest executable program size 628K (643,104 bytes)
Largest free upper memory block 84K ( 85,728 bytes)
FreeDOS is resident in the high memory area.
```
### N 的意思是 NANSI
如果你想添加一点颜色到 FreeDOS 命令行,你可以使用 ANSI 转义序列。这些序列之所以这样命名,是因为每个序列都以代码 33 (`ESC` 字符) 和一个由美国国家标准化协会 (ANSI) 定义的特殊字符序列为开头。
FreeDOS 通过 `NANSI.SYS` 驱动程序来支持 ANSI 转义序列。随着 `NANSI` 的加载,你的 FreeDOS 控制台将解释 ANSI 转义序列,例如,设置文本颜色。
![Image of Nansi][8]
### O 的意思是 oZone
FreeDOS 是一款命令行操作系统,但是一些人们更喜欢使用可备选的图形化用户界面。这就是为什么 FreeDOS 的 1.3 发行版包含一些图形化桌面的原因。我喜欢的一款名称为 oZone 的图形化桌面,它提供一种时尚、现代化外观的界面。
![Image of Ozone GUI][9]
注意oZone 有一点烦人的错误,可能还需要一些来自外部开发者的关爱。如果你对将 oZone 变得更好感兴趣,自主下载源文件代码。
### P 的意思是 PROMPT
标准的 FreeDOS 命令行提示符会告诉你:你所在文件系统中的位置。当你第一次启动 FreeDOS 时,你的提示符看起来像 `C:\>`, 这意味着 "\" (根) 目录在 "C:" 驱动器。">" 字符表示着你可以在那里输入命令。
在你的提示符中,如果你更喜欢不同的信息,使用 `PROMPT` 目录来更改它。你可以使用一个带有 `$` 的开头的特殊代码来显示不同的信息,例如,`$D` 用于日期、`$T` 用于时间。例如,你可以使用 `$$` 指令来使你的 FreeDOS 命令行看起来像一个 Linux 提示符,来打印一个单个美元符号:
```
C:\>prompt $$
$
```
输入 `PROMPT /?` 来查看一份全部特殊代码的列表。
### Q 的意思是 QBASIC
FreeDOS 实际上没有 QBASIC 。它是针对 MS-DOS 的专有 BASIC 语言环境。作为备选方案,我们提供一些开放源文件的编译器,包括一些针对 BASIC 编程的编译器。
FreeBASIC 编译器可以编译外来的大多数 QBASIC 程序。这里有一个简单的 "猜数" 示例:
```
dim number as integer
dim guess as integer
randomize timer
number = int( 10 * rnd() ) + 1
print "Guess the number from 1 to 10:"
do
input guess
if guess < number then print "Too low"
if guess > number then print "Too high"
loop while guess <> number
print "That's right!"
```
使用 `FBC` 命令来编译 FreeBASIC 程序:
```
C:\DEVEL\FBC>fbc guess.bas
```
这里是这个简单游戏的快速演示:
```
C:\DEVEL\FBC>guess
Guess the number from 1 to 10:
? 5
Too high
? 3
Too low
? 4
That's right!
```
### R 的意思是 REM
在编写程序时,注释是极好的;注释帮助我们理解程序应该要做什么。可以在批处理文件中使用 `REM` 来做同样的事。在批处理文件中,在 `REM` 的后面的任何东西都将会被忽略。
```
REM this is a comment
```
### S 的意思是 SET
FreeDOS 命令行使用一系列称为 <ruby>环境变量<rt>environment variables</rt></ruby> 的变量,让你来自定义你的系统。你可以使用 `SET` 命令来设置这些变量。例如。使用 `DIRCMD` 变量来控制 `DIR` 如何排列目录列表。为设置 `DIRCMD` 变量,使用 `SET` 命令:
```
SET DIRCMD=/O:GNE
```
这告诉 `DIR` 先按照目录分组 (G)来排序 (O) 输出,然后再按照名称 (N) 和扩展名 (E) 来排序结果。
### T 的意思是 TYPE
`TYPE` 命令是最常使用的 DOS 命令之一。`TYPE` 显示一个文件的内容,类似于在 Linux 上的 `cat`
```
C:\DEVEL>type hello.c
#include
int
main()
{
puts("Hello world");
return 0;
}
```
### U 的意思是 UNZIP
在 Linux 上,你可能更熟悉标准的 Unix 存档命令: `tar`.。在 FreeDOS 上也有一个 tar 版本 (和其它大量的流行的存档程序),但是,在 DOS 上的事实上的标准的存档命令是 `ZIP``UNZIP` 。两者都默认安装在 FreeDOS 1.3 之中。
比如说,我有一些文件的一个 zip 存档。如果我想提取整个 Zip 文件,我可以只使用 `UNZIP` 命令,并将 Zip 文件作为命令行的选项来提供。这将在我当前工作目录中开始提取存档文件。除非我正在恢复一些东西的先前版本,我通常不希望覆盖我的当前文件。在这种情况下,我将提取存档到一个新的目录。你可以使用 `-d` ("<ruby>目标<rt>destination</rt></ruby>") 命令行选项来具体指定目标路径:
```
D:\SRC>unzip monkeys.zip -d monkeys.new
Warning: TZ environment variable not found, cannot use UTC times!!
Archive: monkeys.zip
creating: monkeys.new/monkeys/
inflating: monkeys.new/monkeys/banana.c
inflating: monkeys.new/monkeys/banana.obj
inflating: monkeys.new/monkeys/banana.exe
creating: monkeys.new/monkeys/putimg/
inflating: monkeys.new/monkeys/putimg/putimg.c
inflating: monkeys.new/monkeys/putimg/putimg.obj
inflating: monkeys.new/monkeys/putimg/putimg.exe
```
为学习更多关于 `ZIP``UNZIP` 命令的信息,阅读 [如何在 FreeDOS 上存档文件][11]。
### V 的意思是 VER
在 DOS 的古老岁月中,`VER` 命令会报告你正在运行的 DOS 发行版本,例如:带有 "MS-DOS 5.0.D" 的 FreeDOS`VER` 命令将给予你额外的详细信息,例如 FreeDOS Shell 的版本:
```
C:\DEVEL>ver
FreeCom version 0.85a - WATCOMC - XMS_Swap [Jul 10 2021 19:28:06]
```
如果你还想查看 FreeDOS 内核版本和 DOS 兼容性等级,添加 `/R` 选项:
```
C:\DEVEL>ver /r
FreeCom version 0.85a - WATCOMC - XMS_Swap [Jul 10 2021 19:28:06]
DOS version 7.10
FreeDOS kernel 2043 (build 2043 OEM:0xfd) [compiled May 14 2021]
```
### W 的意思是 WHICH
FreeDOS 命令行可以运行来自不同的目录列表中且在 `PATH` 变量中标识的程序。你可以使用 `WHICH` 命令来准确地识别出程序的位置。只需要输入 `WHICH` 加上你想要定位的程序名称:
```
C:\>which xcopy
xcopy C:\FREEDOS\BIN\XCOPY.EXE
```
### X 的意思是 XCOPY
`COPY` 命令只能将文件从一个位置复制到另一个位置。如果你想扩大复制的范围来包括一些目录,使用 `XCOPY` 命令。我通常添加 `/E` 选项来包含所有的子目录,包括空的子目录,这样,我可以复制整个目录树。这样就可以有效地备份我正在工作的任意工程:
```
D:\SRC>xcopy /e monkeys monkeys.bak
Does MONKEYS.BAK specify a file name
or directory name on the target (File/Directory)? d
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.C
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.OBJ
Copying D:\SRC\MONKEYS\PUTIMG\PUTIMG.EXE
Copying D:\SRC\MONKEYS\BANANA.C
Copying D:\SRC\MONKEYS\BANANA.OBJ
Copying D:\SRC\MONKEYS\BANANA.EXE
6 file(s) copied
```
### Y 的意思是 Yellow
这不是一个命令,而是关于 DOS 如何显示颜色的有趣的百科知识。如果你仔细留心过 FreeDOS你可能已经注意到文本只能获取有限的颜色范围---十六种文本颜色、八种背景颜色。
IBM 的 5153 彩色显示器,通过点亮不同亮度等级的微小的红、绿、蓝荧光点的方式来创建 16 种文本颜色和 8 中背景颜色的主色调,为用户显示颜色。早期的个人计算机只能以"标准强度"级别来显示背景颜色;只要文本颜色可以使用明亮颜色。
如果你查看文本颜色,你有黑色、蓝色、绿色、蓝绿色、红色、品红色、橙色和白色。这些颜色的"明亮"版本有亮黑色(暗灰色)、亮蓝色、亮绿色、亮蓝绿色、亮红色、亮品红色、黄色和亮白色。橙色的"明亮"版本有实际上是黄色。没有"亮橙色"。
如果你想要学习更多关于文本颜色的信息,阅读我们关于[FreeDOS 为什么有 16 种颜色][12] 的文章。
### Z 的意思是 ZIP
你可以在 DOS 命令行中使用 `ZIP` 来创建文件和目录的存档。这是一种很便利的方法:可以备份你的工作,或者发布一个 "软件包" 来在未来的 FreeDOS 发行版中使用。例如,比如说,我想备份我的工程源文件代码,其中包含这些源文件文件:
```
D:\SRC>zip -9r monkeys.zip monkeys
zip warning: TZ environment variable not found, cannot use UTC times!!
adding: monkeys/ (stored 0%)
adding: monkeys/banana.c (deflated 66%)
adding: monkeys/banana.obj (deflated 26%)
adding: monkeys/banana.exe (deflated 34%)
adding: monkeys/putimg/ (stored 0%)
adding: monkeys/putimg/putimg.c (deflated 62%)
adding: monkeys/putimg/putimg.obj (deflated 29%)
adding: monkeys/putimg/putimg.exe (deflated 34%)
```
ZIP 支持很多命令行选项来完成不同的工作,但是,我使用最多的命令行选项是: `-r` 用于递归处理目录和子目录、`-9`用于提供尽可能大的压缩比。`ZIP` 和 `UNZIP` 使用类 Unix 命令行,因此,你可以在短划线后面合并选项: `-9r` 将在 Zip 文件中给予最大压缩比和包括子目录。
关于如何使用 `ZIP``UNZIP` 命令的更多详细信息,阅读 [如何在 FreeDOS 上存档文件][13]。
### 新的 FreeDOS 指南
准备好你的 FreeDOS 旅程的下一步了吗?查看我们的新的电子书,现在开始尝试我们的 FreeDOS !
**[使用 FreeDOS 的指南][14]**
**[FreeDOS 内部高级指南][15]**
图片来源: (Jim Hall, CC BY-SA 40)
--------------------------------------------------------------------------------
via: https://opensource.com/article/22/6/26-freedos-commands
作者:[Jim Hall][a]
选题:[lkxed][b]
译者:[robsean](https://github.com/robsean)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/jim-hall
[b]: https://github.com/lkxed
[1]: https://opensource.com/sites/default/files/lead-images/freedos-fish-laptop-color.png
[2]: https://opensource.com/article/22/6/linux-attr-command
[3]: https://opensource.com/sites/default/files/2022-06/FREEDedit_0.png
[4]: https://opensource.com/sites/default/files/2022-06/Freededit-save.png
[5]: https://opensource.com/Linux%20find%20cheat%20sheet
[6]: https://opensource.com/sites/default/files/2022-06/Freedhelp.system.png
[7]: https://opensource.com/article/22/6/linux-cheat-command
[8]: https://opensource.com/sites/default/files/2022-06/FreeDnansi.png
[9]: https://opensource.com/sites/default/files/2022-06/FreeDozone.png
[10]: https://opensource.com/article/21/1/fortran
[11]: https://opensource.com/article/21/6/archive-files-freedos
[12]: https://opensource.com/article/21/6/freedos-sixteen-colors
[13]: https://opensource.com/article/21/6/archive-files-freedos
[14]: https://opensource.com/downloads/guide-using-freedos
[15]: https://opensource.com/downloads/advanced-freedos