Windows Commands Flashcards
dir
List files and directories
dir [<path>] [/...]
/o:x - list files in a particular order where x
could be n
to list by name, s
to list by size, e
to list by extension, or d
to list by date.
/t:x - specifies which timestamp on the files and directories is displayed and used for sorting. x
can be c
for created on, a
for last access and w
for last modified.
/a:x - displays files with the attribute indicated by x
: r
for readonly, h
for hidden, s
for system and a
for archive.
/P - pause after each screen of information.
Examples:
Display Creation Time:
dir /TC
Display Last Access Time:
dir /TA
Display Last Write Time:
dir /TW
Sort by Creation Time (oldest first):
dir /TC /O:D
Sort by Last Access Time (newest first):
dir /TA /O:-D
List Files by Size, Displaying Creation Time:
dir C:\mydir /TC /O:S
Display all .log files with eight characters in the filename:
dir ????????.log
/A
- Displays files with specified attributes.
/B
- Uses bare format (no heading information or summary).
move
Move files.
move [/...] [<from>] [<to>]
/y
- Stops prompting for confirmation that you want to overwrite an existing destination file.
-y
- Starts prompting for confirmation that you want to overwrite an existing destination file
/?
- Display help in the command prompt
Examples:
move /y \data\*.xls \reports\
copy
Copies one or more files from one location to another. Cannot copy a directory.
/y
- Suppresses prompting to confirm that you want to overwrite an existing destination file.
/-y
- Prompts you to confirm that you want to overwrite an existing destination file.
copy [/...] [<from>] [<to>]
robocopy
Or “robust copy” - is another file copy utility. Microsoft now recommends using robocopy
rather than xcopy
since the former is designed to work better with long filenames and NTFS attributes.
robocopy <from> <to> [<file>] [/...]
/s
- Copy subdirectories. Exclude empty directories.
/e
- Copy subdirectories. Include empty directories.
/mov
- Move files and delete them from the source after they are copied.
/move
- Move files and directories, delete them from the source after they are copied.
/mir
- Mirror. Tells robocopy to copy everything from the source and make the destination mirror it. That means robocopy will delete anything in the destination that doesn’t match the source folders and files.
xcopy
A utility that allows you to copy the contents of more than one directory at a time and retain the directory structure
/s
- Copies directories and subdirectories unless they’re empty. If you omit /s, xcopy works within a single directory.
/e
- Copies all subdirectories, even if they are empty
/t
- Copies the subdirectory structure (the tree) only, not files. To copy empty directories, must be used with /e
/h
- Copies hidden and system files.
/k
- Copies files and retains read-only attribute to destination files if present. By default, xcopy
removes the read-only attribute.
/y
- Supresses prompting to confirm overwriting files.
/d [:MM-DD-YYYY]
- Copies files changed on or after the specified date (useful for backups)
xcopy <from> [<to>] [/...]
md (mkdir)
Creates a directory at a specified path
md <directory>
- Creates a new directory with the specified name.md <path\directory>
- Creates a new directory at a specified path.
rmdir
Deletes the specified directory if it’s empty.
Same as rd
/s
- Deletes the specified directory and all its subdirectories and files (use with caution as it performs a recursive delete).
/q
- Quiet mode; does not prompt for confirmation when used with /s.
For example:
rmdir OldFolder
deletes “OldFolder” if it’s empty.rmdir /s /q C:\Users\Example\OldFolder
diskpart
The command interface underlying the Disk Management tool.
There are too many options in diskpart to cover here, but the basic process of inspecting disks and partitions is as follows:
- Run the
diskpart
utility, and then enterselect disk 0
at the prompt (or the number of the disk you want to check). - Enter
detail disk
to display configuration information for the disk. The utility should report that the partitions (or volumes) are healthy. If diskpart reports that the hard disk has no partitions, the partition table may have become corrupted. - Enter either
select partition 0
orselect volume 0
at the prompt (or the number of the partition or volume you want to check). - Enter either
detail partition
ordetail volume
to view information about the object. You can now use commands such asassign
(change the drive letter),delete
(destroy the volume), orextend
. - Enter
exit
to quit diskpart.
format
Used to prepare a storage device (like a hard drive, USB drive, or other media) for use by erasing its contents and setting up a file system.
Key switches for the format command:
format <drive letter>:
- Formats the specified drive./fs:<file system>
- Specifies the file system to use (e.g., NTFS, FAT32, exFAT)./q
- Performs a quick format. Deletes the file table and the root directory of a previously formatted volume, but doesn’t perform a sector-by-sector scan for bad areas./v:<label>
- Specifies a volume label for the formatted drive./x
- Forces the volume to dismount before formatting (useful if the drive is in use).
For example:
format D: /fs:NTFS
formats the D: drive with the NTFS file system.format E: /q /v:DataDrive
performs a quick format on the E: drive and sets its label to “DataDrive.”
chkdsk
Scans the file system and/or disk sectors for faults and can attempt to repair any problems detected. A version of Check Disk (autochk) will also run automatically if the system detects file system errors at boot.
There are three ways to run the tool:
chkdsk X:
(where X is the drive letter but no switch is used) runs the tool in read-only mode. The scan will report whether errors need to be repaired.chkdsk X: /f
attempts to fix file system errors.chkdsk X: /r
fixes file system errors and attempts recovery of bad sectors. You are prompted to save any recoverable data, which is copied to the root directory as filennnn.chk files.
Check Disk cannot fix open files, so you may be prompted to schedule the scan for the next system restart.
shutdown
Safely halt the system or log out.
/s
- Shutdown. Close all open programs and services before powering off the computer. The user should save changes in any open files first but will be prompted to save any open files during shutdown.
/t nn
- Specify delay in seconds before shutdown starts; the default is 30 seconds.
/a
- Abort. Abort shutdown (if it is in progress)
/h
- Hibernate. Save the current session to disk before powering off the computer.
/l
- Close all open programs and services started under the user account, but leave the computer running.
/r
- Restart. Close all open programs and services before rebooting without powering down. This is also called a soft reset.
Shutdown now:
~~~
shutdown now
~~~
Restart now:
~~~
shutdown -r now
~~~
sfc
The Windows Resource Protection mechanism prevents damage to or malicious use of system files and registry keys and files. The System File Checker utility (sfc
) provides a manual interface for verifying system files and restoring them from cache if they are found to be corrupt or damaged.
The program can be used from an administrative command prompt in the following modes:
sfc /scannow
- runs a scan immediately.sfc /scanonce
- schedules a scan when the computer is next restarted.sfc /scanboot
- schedules a scan that runs each time the PC boots.
winver
Display Windows version information by opening a GUI. Its predecessor, ver
, prints the version to the command line.
net
net use
Manages shared network resources such as mapped drives or shared printers
net use <drive letter>: \\<server>\<share>
- Connect to a network resource
net use <drive letter>: \\<server>\<share> /user:<domain>\<username> <password>
- Connect with specific user credentials
net use
- Display active connections
net use <drive letter>: /delete
- Disconnect from a network resource
net use * /delete
- Disconnect all active connections
net view
can be used to list all Windows hosts on the network
DISM
Deployment Image Servicing and Management - (DISM)
DISM utility can be used to slipstream operating system (OS) updates into a Windows install image. When an administrator is creating and maintaining disk images, it is important to include any necessary device drivers and relevant OS updates. DISM can be used to interact with an online image, which is a running Windows installation, or an offline image, such as a .wim, .vhd, or .vhdx file. DISM is a command-line tool that can be used to interact with Windows system images. It is commonly used in conjunction with other command-line system repair utilities such as the System File Checker (sfc
) tool and the Check Disk (Chkdsk
) tool.
Image
- is used to specify an offline image, such as a .wim, .vhd, or .vhdx file.
/Online
- specifies that DISM should operate on the running Windows installation and not on an offline image.
/Cleanup-Image
- specifies that DISM should perform image maintenance and requires one of the following parameters: /CheckHealth, /ScanHealth, /RestoreHealth.
/CheckHealth
- checks to see whether the image has been flagged as corrupt.
/ScanHealth
- scans the image for corruption.
/RestoreHealth
- scans the image and performs the necessary repairs.
By default, the DISM tool uses the Windows Update service to repair an online image; however, the /LimitAccess
command-line switch can be used in conjunction with the /Source
command-line switch to specify an alternate repair source.