Introduction: Mastering the Digital Terrain
In the vast and ever-evolving landscape of cybersecurity, a fundamental understanding of how to navigate and manipulate file systems is not just an advantage – it’s an absolute necessity. Whether you’re conducting a penetration test, performing incident response, or simply securing a system, interacting with files and directories is at the core of nearly every operation.
This cheatsheet serves as your concise guide to the most common file and directory management commands across four critical environments: Linux, the backbone of many servers and security tools; Windows Command Prompt (CMD), the classic interface for Windows systems; PowerShell, Microsoft’s powerful, object-oriented scripting shell; and Meterpreter, the advanced post-exploitation framework within Metasploit.
Why is this foundational knowledge crucial for aspiring cybersecurity professionals like you?
- Initial Reconnaissance: The first step in any assessment often involves understanding the target’s file structure, looking for configuration files, logs, or potentially sensitive data.
- Post-Exploitation: After gaining access, you’ll need to move, create, delete, or exfiltrate files. Knowing the right commands ensures you can efficiently achieve your objectives.
- Incident Response: When a breach occurs, quickly navigating directories to examine logs, quarantine malicious files, or gather forensic evidence is paramount.
- Cross-Platform Agility: Real-world environments are rarely homogenous. Fluency in commands across different operating systems allows you to adapt swiftly to diverse targets.
- Scripting Foundation: These basic commands are the building blocks for more complex scripts (Bash, Batch, PowerShell) that automate tasks and streamline operations.
- Efficiency and Precision: The command line offers unparalleled speed and precision compared to graphical interfaces, a critical factor when time is of the essence.
By internalizing these commands, you’re not just memorizing syntax; you’re learning the fundamental language of system interaction, a skill that will empower your cybersecurity journey.
Linux, CMD, PowerShell, & Meterpreter: File & Directory Cheatsheet
This cheatsheet provides a quick reference for common file and directory management commands across Linux, Windows Command Prompt (CMD), PowerShell, and Meterpreter. Use it to quickly find the equivalent commands you need, no matter your environment!
Description: List directory contents 📁
- 🐧 Linux:
ls- Example:
ls -l(lists contents in long format, showing permissions, owner, size, date, etc.) - Example:
ls -a(lists all files, including hidden ones)
- Example:
- 🖥️ CMD:
dir- Example:
dir /w(lists contents in wide format, multiple columns) - Example:
dir /s(lists contents of the current directory and all subdirectories)
- Example:
- 🚀 PowerShell:
Get-ChildItem(orgci)- Example:
Get-ChildItem -Path C:\Windows -Force(lists all items, including hidden/system files, in the specified path) - Example:
Get-ChildItem -Recurse -File *.txt(finds all .txt files recursively)
- Example:
- ☠️ Meterpreter:
ls- Example:
ls(lists current directory contents on the target system) - Example:
ls C:\\Users(lists contents of a specified directory)
- Example:
Description: Change directory 🚶♂️
- 🐧 Linux:
cd- Example:
cd /var/log(changes to the/var/logdirectory) - Example:
cd ..(moves up one directory level)
- Example:
- 🖥️ CMD:
cd- Example:
cd C:\Users\Public(changes to thePublicfolder on the C: drive) - Example:
cd ..(moves up one directory level)
- Example:
- 🚀 PowerShell:
Set-Location(orcd)- Example:
Set-Location C:\Program Files(changes to theProgram Filesdirectory) - Example:
Set-Location ..(moves up one directory level)
- Example:
- ☠️ Meterpreter:
cd- Example:
cd C:\\Users\\Admin\\Desktop(changes to the specified directory on the target) - Example:
cd ..(moves up one directory level on the target)
- Example:
Description: Print working directory 📍
- 🐧 Linux:
pwd- Example:
pwd(displays the full path of the current directory)
- Example:
- 🖥️ CMD:
cd(when typed without arguments)- Example:
cd(displays the current directory path)
- Example:
- 🚀 PowerShell:
Get-Location(orpwd)- Example:
Get-Location(displays the current directory path)
- Example:
- ☠️ Meterpreter:
pwd- Example:
pwd(displays the current working directory path on the target system)
- Example:
Description: Make a new directory ➕
- 🐧 Linux:
mkdir- Example:
mkdir my_new_folder(creates a directory namedmy_new_folderin the current location) - Example:
mkdir -p /path/to/new/nested/directory(creates nested directories if they don’t exist)
- Example:
- 🖥️ CMD:
mkdir(ormd)- Example:
mkdir project_alpha(creates a directory namedproject_alphain the current location) - Example:
mkdir C:\Reports\2025\Q1(creates directories and subdirectories if needed)
- Example:
- 🚀 PowerShell:
New-Item -ItemType Directory(ormkdir)- Example:
New-Item -ItemType Directory -Name "Reports"(creates a directory namedReports) - Example:
New-Item -ItemType Directory -Path "C:\Data" -Name "NewFolder"(createsNewFolderinsideC:\Data)
- Example:
- ☠️ Meterpreter:
mkdir- Example:
mkdir secret_stash(creates a directory namedsecret_stashon the target) - Example:
mkdir C:\\temp\\backups(creates a directory in a specified path on the target)
- Example:
Description: Remove a directory 🗑️
- 🐧 Linux:
rmdir(only for empty directories),rm -r(for non-empty)- Example:
rmdir empty_folder(removesempty_folderif it’s empty) - Example:
rm -r non_empty_folder(recursively removesnon_empty_folderand its contents)
- Example:
- 🖥️ CMD:
rmdir(orrd)- Example:
rmdir empty_dir(removesempty_dirif it’s empty) - Example:
rmdir /s /q non_empty_dir(removesnon_empty_dirand its contents silently, without confirmation)
- Example:
- 🚀 PowerShell:
Remove-Item -Recurse- Example:
Remove-Item -Path C:\OldData -Recurse -Force(removesOldDataand all its contents, forcing the removal)
- Example:
- ☠️ Meterpreter:
rmdir- Example:
rmdir C:\\temp\\old_logs(removes the specified directory on the target)
- Example:
Description: Remove files or directories ✖️
- 🐧 Linux:
rm- Example:
rm myfile.txt(removesmyfile.txt) - Example:
rm -r mydirectory(removesmydirectoryand its contents recursively) - Example:
rm -f force_remove.txt(forces removal without prompting)
- Example:
- 🖥️ CMD:
del(for files),rmdir /s /q(for directories)- Example:
del old_report.doc(deletesold_report.doc) - Example:
del *.bak(deletes all files with the.bakextension) - Example:
rmdir /s /q C:\Temp\OldProject(deletes theOldProjectdirectory and its contents silently)
- Example:
- 🚀 PowerShell:
Remove-Item- Example:
Remove-Item -Path "C:\Users\Public\downloaded.zip"(removes the specified file) - Example:
Remove-Item -Path "C:\Logs" -Recurse -Force(removes theLogsdirectory and all its contents)
- Example:
- ☠️ Meterpreter:
rm- Example:
rm C:\\Windows\\Temp\\malicious.exe(removes a file on the target) - Example:
rm -r C:\\Users\\Public\\Downloads(removes a directory and its contents on the target)
- Example:
Description: Copy files or directories 📋
- 🐧 Linux:
cp- Example:
cp file.txt /tmp/new_location/(copiesfile.txttonew_location) - Example:
cp -r myfolder /backup/(copiesmyfolderand its contents recursively tobackup)
- Example:
- 🖥️ CMD:
copy(for files),xcopyorrobocopy(for directories)- Example:
copy document.pdf C:\Archive\(copiesdocument.pdftoC:\Archive) - Example:
xcopy C:\SourceDir D:\DestDir /E /I(copiesSourceDirand its subdirectories/files toDestDir, creatingDestDirif it doesn’t exist)
- Example:
- 🚀 PowerShell:
Copy-Item- Example:
Copy-Item -Path C:\Source\file.log -Destination C:\Backup\(copies a file) - Example:
Copy-Item -Path C:\SourceFolder -Destination C:\Backup -Recurse(copies a folder and its contents)
- Example:
- ☠️ Meterpreter:
cp- Example:
cp C:\\Users\\victim\\data.txt C:\\Windows\\Temp\\(copies a file on the target system) - Example:
cp -r C:\\ProgramData\\Secrets C:\\temp\\(copies a directory and its contents recursively on the target)
- Example:
Description: Move or rename files or directories ↔️
- 🐧 Linux:
mv- Example:
mv old_name.txt new_name.txt(renamesold_name.txttonew_name.txt) - Example:
mv report.pdf /archive/completed/(movesreport.pdftoarchive/completed/)
- Example:
- 🖥️ CMD:
move(for files),ren(rename files/directories)- Example:
move oldfile.txt newlocation\(movesoldfile.txttonewlocation) - Example:
ren original_folder renamed_folder(renamesoriginal_folder)
- Example:
- 🚀 PowerShell:
Move-Item- Example:
Move-Item -Path C:\Temp\draft.docx -Destination C:\Documents\(moves a file) - Example:
Move-Item -Path C:\OldFolder -Destination C:\NewLocation\RenamedFolder(moves and renames a folder)
- Example:
- ☠️ Meterpreter:
mv- Example:
mv C:\\bad_file.dll C:\\Windows\\System32\\good_file.dll(moves and renames a file on the target) - Example:
mv C:\\Users\\public\\downloaded_tool.exe C:\\temp\\(moves a file to a new location on the target)
- Example:
Description: Create empty files 📄
- 🐧 Linux:
touch- Example:
touch new_log.txt(creates an empty file or updates timestamp if it exists)
- Example:
- 🖥️ CMD:
type nul > filename.txt- Example:
type nul > config.ini(creates an emptyconfig.inifile)
- Example:
- 🚀 PowerShell:
New-Item -ItemType File(ortouch)- Example:
New-Item -ItemType File -Name "empty_doc.txt"(creates an emptyempty_doc.txtfile) - Example:
touch scripts.ps1(aliases toNew-Item)
- Example:
- ☠️ Meterpreter: N/A (Can be achieved by
echo > fileordownloadand thenuploadan empty one)- Example:
shellthenecho > C:\temp\newfile.txt(execute Windows command) - Example:
upload empty_file.txt C:\\temp\\empty_file_on_target.txt(upload a locally empty file)
- Example:
Description: Search for file in a directory hierarchy 🔍
- 🐧 Linux:
find- Example:
find /home/user -name "*.jpg"(finds all JPG files in/home/userand its subdirectories) - Example:
find / -type f -size +1G(finds all files larger than 1GB starting from root)
- Example:
- 🖥️ CMD:
dir /s(basic search),where(finds executables)- Example:
dir C:\Users\ /s /b config.ini(findsconfig.inirecursively, bare format) - Example:
where explorer.exe(finds location ofexplorer.exein PATH)
- Example:
- 🚀 PowerShell:
Get-ChildItem -Recurse -Filter(orgci -recurse -filter)- Example:
Get-ChildItem -Path C:\ -Recurse -Filter "*.log"(finds all.logfiles recursively from C:) - Example:
Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue | Where-Object {$_.Length -gt 1MB}(finds files larger than 1MB)
- Example:
- ☠️ Meterpreter:
search- Example:
search -d C:\\Users -f *.doc(searches for .doc files inC:\Userson the target) - Example:
search -f calc.exe(searches forcalc.exeacross common system paths)
- Example:
Description: Find files by name 📛
- 🐧 Linux:
locate(uses a pre-built database, faster but might be outdated),find- Example:
locate mydocument.pdf(findsmydocument.pdfusing thelocatedatabase) - Example:
find . -name "report_2024.xlsx"(findsreport_2024.xlsxin current dir and subdirs)
- Example:
- 🖥️ CMD:
dir /s- Example:
dir C:\Windows\ /s /b calc.exe(findscalc.exein Windows dir and subdirs)
- Example:
- 🚀 PowerShell:
Get-ChildItem -Recurse -Name(orgci -recurse -name)- Example:
Get-ChildItem -Path C:\ -Recurse -Name "*.dll"(lists all.dllfiles by name recursively) - Example:
Get-ChildItem -Recurse -Include 'image.png'(includes only files named ‘image.png’)
- Example:
- ☠️ Meterpreter:
search- Example:
search -f password.txt(searches the target system for files namedpassword.txt)
- Example:
Description: Determine file type ❓
- 🐧 Linux:
file- Example:
file myphoto.jpg(outputs something likemyphoto.jpg: JPEG image data, JFIF standard 1.01)
- Example:
- 🖥️ CMD: N/A (Can infer from extension or use third-party tools)
- Example:
dir /x(shows short names which can sometimes help)
- Example:
- 🚀 PowerShell: N/A (Can infer from extension or use third-party tools,
Get-Itemshows extension)- Example:
(Get-Item myfile.txt).Extension(displays the file extension)
- Example:
- ☠️ Meterpreter: N/A (Can often be inferred from context or
downloadand inspect)- Example:
download C:\\payload.binthenfile payload.bin(download and inspect locally)
- Example:
Description: Concatenate and display file contents 📖
- 🐧 Linux:
cat- Example:
cat readme.txt(displays the content ofreadme.txt) - Example:
cat file1.txt file2.txt > combined.txt(concatenates two files into a new one)
- Example:
- 🖥️ CMD:
type- Example:
type settings.ini(displays the content ofsettings.ini)
- Example:
- 🚀 PowerShell:
Get-Content(orcat)- Example:
Get-Content C:\Logs\error.log(displays the content oferror.log) - Example:
Get-Content C:\file1.txt, C:\file2.txt | Set-Content C:\combined.txt(concatenates files)
- Example:
- ☠️ Meterpreter:
cat- Example:
cat C:\\Windows\\System32\\drivers\\etc\\hosts(displays the content of thehostsfile on the target)
- Example:
Description: View file content with navigation ↔️
- 🐧 Linux:
less- Example:
less large_log_file.log(openslarge_log_file.logfor interactive viewing with scrolling)
- Example:
- 🖥️ CMD:
more(basic pagination)- Example:
more big_text_file.txt(displays content page by page)
- Example:
- 🚀 PowerShell:
Get-Content(can be piped tomoreor a custom viewer)- Example:
Get-Content C:\very_big_report.txt | more(displays content page by page) - Example:
Get-Content C:\script.ps1 -ReadCount 10(reads 10 lines at a time)
- Example:
- ☠️ Meterpreter:
cat(for small files, ordownloadfor larger ones)- Example:
cat C:\\small_config.txt(displays content if the file is small) - Example:
download C:\\large_dump.log(downloads for local inspection with a proper viewer)
- Example:
Final Thoughts: Beyond the Basics – Practical Tips for Cybersecurity Pros
Congratulations! You’ve just equipped yourself with a powerful toolkit of file and directory commands across multiple critical platforms. While this cheatsheet covers the basics, remember that true mastery comes with continuous practice and a deeper understanding of their implications.
Here are some key takeaways and practical tips for aspiring cybersecurity folks:
- Practice, Practice, Practice: The best way to internalize these commands is through hands-on experience. Spin up a Linux VM, open CMD, fire up PowerShell, and experiment. Build that muscle memory!
- Understand the “Why”: Don’t just know what a command does, but why you’re using it in a specific context. For example, why would you use
findinstead oflocatein Linux, orRemove-Item -Forcein PowerShell? - Explore Flags and Parameters: Each command has a wealth of options (flags/switches). Use
man <command>(Linux),<command> /?(CMD), orGet-Help <command>(PowerShell) to discover more advanced functionalities like recursive operations, specific filters, or output formats. - Piping and Redirection: Learn how to chain commands together using pipes (
|) to send the output of one command as the input to another, or redirect output to files (>or>>). This is where the real power of the command line shines (e.g.,ls -l | grep "sensitive"orcat logs.txt > audit_data.txt). - Security Implications of Commands:
- Be Careful with Deletion: Commands like
rm -rf(Linux) orRemove-Item -Recurse -Force(PowerShell) are incredibly powerful and can irrevocably delete data. Always double-check your path before executing, especially with the-Forceorfflags. - Permissions are Key: Understand how to view and modify file permissions (
chmodon Linux,icaclson Windows) to secure sensitive data and prevent unauthorized access. - Identify Suspicious Activity: Knowing normal file behavior helps you spot anomalies. An unusual file creation, deletion, or modification could indicate compromise.
- Be Careful with Deletion: Commands like
- These are Building Blocks: The commands listed here are fundamental building blocks for more advanced techniques. They form the basis of shell scripting (Bash, Batch, PowerShell), which automates repetitive tasks and creates powerful offensive or defensive tools.
- Stay Curious, Keep Learning: The cybersecurity landscape is dynamic. While these core commands remain constant, new tools and techniques emerge. Your foundational knowledge will enable you to quickly adapt and learn new command-line utilities.
By truly internalizing these commands and understanding their practical application, you’re building a robust foundation for a successful and impactful career in cybersecurity. Keep practicing, keep exploring, and remember that the command line is your most versatile weapon and shield.




