Cheatsheet_cmd

My cmd cheatsheet

File management

cd

Command Result
cd /path/to/dir Change to a directory
cd .. Go up one directory
cd %USERPROFILE% Go to the home directory
cd Print current directory

viewing Files and Directories

dir

Command Result
dir List files in the current directory
dir /A Show hidden files
dir /Q Show the owner of the files
dir /S List files and subfolders recursively

tree

Command Result
tree View directory tree
tree /F Show all files for all directories
tree /A Uses ASCII instead of extended characters

Creating Files and Directory

mkdir

Command Result
mkdir new_dir Create a new directory
mkdir dir1\subdir2\subdir3 Create a directory within a directory

echo. or type nul

Command Result
type nul > file.txt Create a new empty file
echo. > file.txt Create a new empty file

Copy files and Directories

copy

Command Result
copy file1.txt file2.txt Copy files only

xcopy

Command Result
xcopy file1.txt file2.txt Copy file and directory
xcopy /E dir1 dir2 Copy directory recursively
xcopy /C Ignore errors
xcopy /I Make the destination a directory
xcopy /Y No confirmation

robocopy

Command Result
robocopy C:\path\to\source C:\path\to\destination Robust File Copy
robocopy /S copy non-empty directory recursively
robocopy /E Copy all directory recursively
robocopy /R:3 Retry 3 times in case of failure
robocopy /W:5 Wait 5 seconds between each try
robocopy C:\path\to\source C:\path\to\destination /LOG:log.txt Copy the operations in a file

Moving & Renaming

move

Command Result
move file.txt c:\new\location Move file to location
move oldname.txt newname.txt Rename file
ren oldname.txt newname.txt Rename file
move /-y file.txt C:\new\location Prompt before overwrite
move /y file.txt C:\new\location No prompt before overwrite

Deleting Files and Directories

del

Command Result
del file.txt delete file only
del /P file.txt Prompt before deleting
del /F file.txt Force delete on read-only file
del /S file.txt Delete from all subfolders
del /Q file.txt No prompt before deleting

rmdir (rd)

Command Result
rmdir dir1 delete empty directory only
rmdir /S dir1 Delete directory recursively
rmdir /Q No prompt before deleting

Finding files

where

Command Result
where /R C:\ file.txt find file.txt in C:\
where /F /R C:\ file.txt show the result in double quote
where /T /R C:\ file.txt show date and size of file

File Permissions and Ownership

icacls

Command Result
Icacls file.txt /grant:r "Authenticated Users":F /T /C Allow all users full control
Icacls file.txt /deny:r "Authenticated Users":F /T /C Deny all users full control
Icacls file.txt /grant "Authenticated Users":R /T /C Allow all users Read-Only access
Icacls file.txt /deny "Authenticated Users":R /T /C Deny all users Read access
Icacls file.txt /grant "Authenticated Users":W /T /C Allow all users Write access
Icacls file.txt /deny "Authenticated Users":W /T /C Deny all users Write access
Icacls file.txt /grant "Authenticated Users": RX /T /C Allow all users Read and Execute access
Icacls file.txt /deny "Authenticated Users":RX /T /C Deny all users Read and Execute access
Icacls file.txt /grant user:R /T /C Allow a user Read access
Icacls file.txt /deny user:R /T /C Deny a user Read access
Icacls file.txt /grant user:W /T /C | Allow a user Write access | |Icacls file.txt /deny user:W /T /C| Deny a user Write access | |Icacls file.txt /grant user:RX /T /C| Allow a user Read and Execute access | |Icacls file.txt /deny user:RX /T /C| Deny a user Read and Execute access | |Icacls file.txt /grant group:R /T /C| Allow a group Read access | |Icacls file.txt /deny group:R /T /C| Deny a group Read access | |Icacls file.txt /grant group:W /T /C Allow a group Write access
Icacls file.txt /deny group:W /T /C Deny a group Write access
Icacls file.txt /grant group:RX /T /C Allow a group Read and Execute access
Icacls file.txt /deny group:RX /T /C Deny a group Read and Execute access
Icacls file.txt /inheritance:e Enable inheritance
Icacls file.txt /inheritance:d Disable the inheritance and copy the ACEs (access control entries)
Icacls file.txt /inheritance:r remove all inherited ACEs (access control entries)
Icacls file.txt /remove user Remove a user from permissions
Icacls file.txt /remove:g user Remove all granted rights to that user
Icacls file.txt /remove:d user Remove all denied rights to that user
Icacls file.txt /remove group Remove a group from permissions
Icacls file.txt /setowner user /T /C Change owner
/T Apply permissions changes to all subdirectories
/C Continue on file errors (access denied) Error messages are still displayed )
/L Perform the operation on a symbolic link only, not its target
/Q Quiet, supress success messages

Permission code

Letter(s) Meaning
D Delete access
F Full access
N No access
M Modify access (Create+Delete+Read+Write)
RX Read and eXecute acces
R Read-only access
W Write-only access