The rd command on the command line. Removing directories

Why is there such chaos in the world? Yes, because the administrator of our system forgot to fulfill his duties. Or I just lost the list of cmd commands from our world. Although this is a somewhat original look at the existing order of things, it nevertheless reflects part of the truth we need: using the command line, you can easily bring order to your computer:

What is the command line

The command line is the simplest tool for managing your computer's operating system. Control occurs using a number of reserved commands and a set of text keyboard characters without the use of a mouse ( in the Windows operating system).

On UNIX-based systems, you can use the mouse when working with the command line.

Some commands came to us from MS-DOS. The command line is also called the console. It is used not only to administer the operating system, but also to manage common programs. Most often, the most rarely used commands are included in this set of commands.

The advantage of using cmd basic commands is that it consumes a minimal amount of system resources. And this is important in emergency situations when all the computer’s powers are, one way or another, involved.

cmd implements the ability to execute and create entire batch files, which represent a specific order of execution of a number of commands (scripts). Thanks to this, they can be used to automate certain tasks ( account management, data archiving and more).

The Windows command shell for manipulating and redirecting commands to certain operating system utilities and tools is the Cmd.exe interpreter. It loads the console and redirects commands in a format that the system understands.

Working with the command line in the Windows operating system

You can call the console in Windows in several ways:

Both methods involve running the console as the current user. That is, with all the rights and restrictions that are imposed on its role in the operating system. To run cmd with administrator rights, you need to select the program icon in the Start menu and select the appropriate item in the context menu:

After launching the utility, you can get help information about commands and the format for writing them in the console. To do this, enter the help statement and press “Enter”:

Basic commands for working with files and directories

The most frequently used commands are:

  • RENAME – renaming directories and files. Command syntax:

RENAME | REN [drive/path] original file/directory name | final filename
Example: RENAME C:UsershomeDesktoptost.txt test.txt

  • DEL (ERASE) – used to delete files only, not directories. Its syntax is:

DEL | ERASE [processing method] [filename]
Example: Del C:UsershomeDesktoptest.txt/P

By processing method we mean a special flag that allows you to implement a certain condition when deleting a file. In our example, the “P” flag enables the display of a permission dialog for deleting each file:

More information about the possible values ​​of the “processing method” parameter can be found in the technical documentation for the Windows operating system.

  • MD – allows you to create a folder at the specified path. Syntax:

MD [drive:] [path]
Example:
MD C:UsershomeDesktoptest1test2

The example will create a subfolder test2 within the test1 folder. If one of the path's root folders does not exist, it will be created too:

  • RD ( RMDIR) – deleting a specific folder or all directories at a specified path. Syntax:

RD | RMDIR [process_key] [drive/path]
Example:
rmdir /s C:UsershomeDesktoptest1test2

The example uses the s flag, which will cause the entire branch of directories specified in the path to be deleted. Therefore, you should not use the rmdir command unnecessarily with this processing key.

In the next section, we'll take a closer look at network cmd commands.

Commands for working with the network

The command line allows you to manage not only the PC file system, but also its network capabilities. The console's network commands include a large number of operators to monitor and test the network. The most relevant of them are:

  • ping – the command is used to monitor the network connection capabilities of a PC. A set number of packets are sent to the remote computer and then sent back to them. The transmission time of packets and the percentage of losses are taken into account. Syntax:

ping [-t] [-a] [-n counter] [-l size] [-f] [-i TTL] [-v type] [-r counter] [-s counter] [(-j host_list | - k node_list)] [-w interval] [target_PC_name]

Example command implementation:
ping example.microsoft.com
ping –w 10000 192.168.239.132

In the last example of the cmd ping command, the request is sent to the recipient with the specified IP address. The waiting interval between packets is 10,000 (10 seconds). By default this parameter is set to 4000:

  • tracert – used to determine the network path to a specified resource by sending a special echo message through the protocol
  • ICMP (Control Message Protocol). After running the command with parameters, a list of all routers through which the message passes is displayed. The first element in the list is the first router on the side of the requested resource.

Syntax of tracer cmd command:
tracert [-d] [-h maximum_hop_number] [-j node_list] [-w interval] [target_resource_name]
Example implementation:
tracert -d -h 10 microsoft.com

The example traces the route to a specified resource. This increases the speed of the operation due to the use of the d parameter, which prevents the command from attempting to obtain permission to read IP addresses. The number of transitions (jumps) is limited to 10 using the set value of the h parameter. By default, the number of jumps is 30:

shutdown [(-l|-s|-r|-a)] [-f] [-m [\PC_name]] [-t xx] [-c “messages”] [-d[u][p]: xx:yy]
Example:
shutdown /s /t 60 /f /l /m \191.162.1.53

The remote PC (m) with the specified IP address (191.162.1.53) will shut down (s) after 60 seconds (t). This will force you to log out of all applications (f) and the current user's session (l).

Recommendations will help you completely delete a folder via command line. In the article about, the DEL command was used, which is intended specifically for files. In the case of folders, the RD or RMDIR commands are applicable.

To achieve the goal, . Enter RD /? and quickly familiarize yourself with the features and parameters of the command. Here you will see only 2 parameters:

  1. /s - when using this prefix, the folder will be deleted, as well as all its nested elements. If your directory is not empty, and you have not specified this parameter, then nothing will work for you.
  2. /Q - used when deleting without confirmation.

In general, the design looks like this:

RD or RMDIR /s/q “full folder path”

Note: when applying the design, the directory and its contents will be completely deleted from the computer and you will not find it in the trash. To be safe, make a backup copy of the folder.

Deleting a folder with or without confirmation

I created a directory on my computer called “cmd” and copied several objects into it. Then I entered the following command into the command line:

RD /s “c:\cmd”

Then I pressed Enter and the Y key because cmd prompted me to confirm the deletion.

I checked the C drive and found no directory. Next, I created a folder named “delete” and also copied 5 files, but when entering the command, I removed the /s prefix. It turned out like this:

RMDIR “c:\delete”

After pressing Enter, the deletion did not occur, and a message was displayed on the command line that the folder was not empty. Conclusion, without the /s parameter, you can only delete an empty folder, therefore, using it without this prefix is ​​practically useless.

If you are too lazy to enter the confirmation letter (Y or N), then the following construction is for you. The /q prefix was mentioned above; it is what removes the annoying typing of letters (see the screenshot for proof).

DEL command

DEL attributes]] names

ERASE attributes]] names

Names The names of one or more files. Wildcards are used to delete multiple files at once.

If a directory is specified, all files in it will be deleted.

/P Prompts for confirmation before deleting each file.

/F Forces deletion of read-only files.

/S Removes the specified files from all subdirectories.

/Q Disables confirmation prompt when deleting files.

/A Selects files for deletion by attributes.

Attributes S System files R Read-only

H Hidden files A Files for archiving

The prefix "-" has the meaning NOT

Changes to DEL and ERASE commands when enhanced command processing is enabled:

The output results for the /S switch are reversed, that is, only the names of deleted files are displayed, and not files that could not be found.

Example: 1. Deleting all files with the extension .txt

A:Tasks>del *.txt

A:Tasks>

2. Removing files starting with the letter “T”

A:Tasks> del T*.txt

A:Tasks>

OPERATING SYSTEM MS DOS

Guidelines for laboratory work on the course

"Operating systems" for students of specialty 230401 "Information systems"

Balakovo

Goal of the work– acquisition of basic practical skills when working with the MS-DOS operating system.

Basic Concepts

Any operating system (OS) provides the user and application programs with a means of communication (interface) with numerous computer devices. It receives various commands from the user and executes them. Application programs, being launched by the user (again, not without the help of the OS), themselves actively use the services of the OS. For example, if you need to print a text document on a printer, then the text editor in the window of which this document is located will not directly interact with the printer itself, but will delegate this work to the operating system. That, in turn, will check whether the printer is turned on, whether it is working properly, and whether its tray is filled with paper. And only after this will it supply text for printing in certain portions, while constantly monitoring the state of the working printer. There is a wide variety of operating systems: MS-DOS, Windows 7, Windows 2003, Linux, Unix and many others. They differ from each other in capabilities, ease of use, performance and other characteristics.

MS-DOS is an abbreviation for MicroSoft Disk Operating System, i.e. disk operating system of the American company Microsoft. The term “disk-based” means that the OS is located on a disk: either on a hard drive or on

from a floppy disk (the size of MS-DOS allows this), or even on a CD.

The algorithm for selecting a particular device is set in the BIOS. For example, if in the “BIOS FEATURES SETUP” section, the “Boot Sequence” item lists drives A:, C:, this means the following: if a floppy disk is installed in the computer (drive A:), an attempt to load MS-DOS from it; if there is no floppy disk, then MS-DOS will load from the hard drive (drive C:).

The MS-DOS operating system consists of the following parts:

1) BIOS (Basic Input-Output System). This part of the OS is hardwired into ROM or ROM (Read Only Memory). The BIOS contains tests for checking computer components (automatically run when the computer is turned on), as well as the Boot Loader - a small program for calling the more complex MS-DOS Loader (a fragment of the io.sys file). In addition, the BIOS performs low-level I/O operations (at the register level) with the monitor, keyboard, disks, and printer.

2) Disk files io.sys and msdos. sys. The io.sys file (located in the initial sector of the system disk) contains, as mentioned, the MS-DOS Loader program. In addition, io.sys supplements the BIOS with other low-level I/O operations. The msdos.sys file provides basic high-level MS-DOS services.

3) File command.com – Command processor or MS-DOS command interpreter. Contains basic MS-DOS commands: CLS, DIR, COPY and others, called internal. In addition, it works with external MS-DOS commands, such as FORMAT, DELTREE and others, which are usually located in the DOS directory and are files with the extension .com or .exe. The command processor command.com organizes the execution of any user commands entered from the keyboard or using batch files (files with the .bat extension). The MS-DOS components listed above constitute the minimum composition of this operating system. In addition to it, you can specify such MS-DOS elements as:

4) external MS-DOS commands. They are, as mentioned, files with the extension .com or .exe and located, as a rule, in the DOS directory.

5) Drivers. These are special programs (files with extensions .com, .exe or .sys) that provide maintenance for new or non-standard use of existing external devices. Activation of the necessary drivers is carried out using the config.sys and autoexec.bat files.

6) File config.sys. It is a regular text file containing special commands for activating various drivers. In addition, it can be used to change operating modes or the configuration of MS-DOS.

7) File autoexec.bat. This is a batch file that is automatically launched by the operating system for execution when the computer is turned on or restarted.

The user's dialogue with DOS takes place in the form of commands entered in response to the so-called operating system prompt. It is displayed on the display screen and usually looks like this:

current drive name:\current directory name>_,

where > is the system symbol;

For example, C:\lab>_,

where C is the name of the current disk;

lab – current directory name

If the current directory is the root directory, then the name of the current directory is omitted because it is the same as the name of the current drive. The prompt in this case looks like this:

C:\>_

Entering commands. DOS includes several dozen commands. They are typed on the command line after the DOS prompt. The syntax or general format of the command is as follows:

command name[arguments] ,

where arguments are the objects on which the command acts;

parameters – identifiers of command execution modes (they are separated by a slash "/ ").

To display the command's arguments and options, run help command name

To execute any command, press the Enter key (there will be no further indication of pressing the Enter key).

Basic DOS commands are divided into four groups.

1. General purpose commands.

2. Commands for working with disks.

3. Commands for working with directories.

4. Commands for working with files.

This lab does not use disk management commands, so they are not discussed further.

MS-DOS has standard file type designations that allow you to visually determine the nature of files.

COM – batch file;

EXE – executive file;

BAT – batch file;

SYS – system file;

TXT – text file

General purpose commands.

The most commonly used commands in this group are:

1) cls (Clear Screen) – clears the screen;

2) ver – displays the version of the operating system installed on the computer;

3) date – display and set the current date;

4) time – display and set the current time;

5) help – output of help data on DOS commands;

To call previously entered commands to the command line and manage the list of commands, you can use the following keys:

– call the previous command;

↓ – call the next command;

F7 – displays a list of previously entered commands;

F9 – copying one of the commands from the displayed list (F7) to the command line by selecting its number;

Alt+F7 – clear the list of commands.

Commands for working with directories

Team DIR– directory – directory (directories) – serves to display a list of files and subdirectories located in the specified directory.

For example, C:\>dir – view the root directory of drive C.

C:\>dir lab – view the contents of the lab directory.

If the specified directory contains a large number of subdirectories and files, then you can organize their paged output using the /P switch. In this case, after displaying one page of the list, DOS will wait for any key to be pressed to continue displaying subsequent pages. For example, dir c:\windows /p

!! Browse the contents of the root directory of the C: drive using page-by-page browsing mode.

Team TREE– displaying the directory tree on the screen.

Command Format: TREE[drive] [path] [name] [|more]

where drive is the name of the drive on which the directory system is located;

path – path to the directory whose tree you want to view;

name – the name of this directory;

/f – mode for displaying a tree of directories with the files they contain;

|more is a command for pipeline processing of output in chunks of 23 lines.

For example, C:/>tree C: /f|more

!! Display the directory tree of drive C: in portions of 23 lines without files.

Team M.D.- Make Directory – creating directories and subdirectories.

Command Format: M.D. [drive] [path] name

where drive is the name of the drive on which the directory is created;

path – path to the created directory from the root or current directory;

name – the name of the directory to be created.

For example, С:/>md lab

!! Create a directory X on drive C:.

Team CD- Change Directory – change the current directory.

Command Format: CD [path] name

where path is the path to a subdirectory in the hierarchical file structure;

name – the name of the subdirectory that needs to be declared current.

For example, cd C:\Windows

To return to the root directory from the current subdirectory at any level, you must enter the command cd \

If you need to move up one level, you must enter the command cd..

Here (..) means the parent directory.

!! Change to directory X. Notice the changes to the DOS prompt.

!! Create two subdirectories Y and Z in the current directory.

Change the current disk. To change the current disk, you need to type the name of the drive that should become the current one. After running this command, a DOS prompt will appear with the current drive.

Copying directories. To copy one directory to another, use the command XCOPY. This command allows you to copy a directory while changing its name.

Command Format:

Where
where
XCOPY [drive] [path] old_name [drive] [path] old (new) name

where /s – mode for copying non-empty directories (together with files and subdirectories);

/e – mode for copying empty directories.

For example, we copy directory 1 to directory 2 as 3

xcopy d:\x\1 d\x\2\3 /s/e (do not type - this is an example)

!! Copy directory Z to directory Y under the name Q. Check the result with the TREE command.

Directory transfer. To move directories use the command MOVE.

Command Format:

MOVE [drive][path] old_name[drive] [path] [new_name]

When transferring a directory to the current directory, it is necessary to specify either the new (old) name of the transferred directory or the full path to the current directory in the addressable part “where”.

For example, see the command similar to the example above

!! Go to the root directory, then move the Q directory to the X directory. Check the result by displaying the X directory tree.

Renaming directories. The directory name is changed using the command REN.

Command Format: REN [drive] [path] name1 name2

where name1 is the old directory name;

name2 – new directory name.

!! Rename directory X to W. Test the execution of the command.

Removing directories. Directories are removed using the RD command.

Command Format: R.D.[drive] [path] name

where drive is the name of the drive on which the directory to be deleted is located;

path – path to the directory to be deleted;

name – the name of the directory to be deleted.

You can only delete a directory while outside the directory. The root directory cannot be deleted. After pressing Enter, the operating system will prompt you: Delete the directory “[drive] [path] name” along with all subdirectories? . To delete, press Y (yes) and Enter; to cancel, press N (no) and Enter.

!! Delete directory Y. Test the delete command using the TREE command.

File commands

Removes a directory.

Syntax

rmdir[disk: ]path [/s] [/q]

rd[disk: ]path [/s] [/q]

Options

[disk: ]path Specifies the drive and directory location to delete. /s Deletes the specified directory and all subdirectories along with files. Parameter /s used to delete a directory tree. /q Launches rmdir in hidden mode. The command removes directories without asking for confirmation. /? Displays help on the command line.

Notes

  • Using the command rmdir in the recovery console

    Team rmdir with other parameters is available in the recovery console.

  • Removing directories with hidden and system files

    Deleting directories with hidden and system files is not possible. When you try to uninstall, the following message appears:

    The directory is not empty.

    To get a list of hidden and system files, use the command dir, and to view and change attributes - the command attrib. For more information, click the "" link.

  • Using backslash

    If a backslash (\) is inserted before the first directory name, that directory will be treated as a subdirectory of the root directory regardless of the current directory name. If there is no backslash, the directory will be treated as a subdirectory of the current directory.

  • Removing the current directory

    Team rmdir cannot be used to delete the current directory. First you need to change to another directory (which is not a subdirectory of the current one) and then use the command rmdir. When you try to delete the current directory, you receive the following message:

    The file cannot be accessed because it is in use by another process.

Examples

To delete the \User\Smith directory, you must first make sure that it does not contain any files. To do this, type on the command line:

dir \user\smith /a

Only the characters “.” should be displayed on the screen. And "..".

Then, from any directory other than \User\Smith, run the following command:

rmdir\user\smith

To remove the \User directory, all files, and all subdirectories, use the following command.