Table Of Contents
CMD
Basic System Commands
- cls
Clears the Command Prompt screen. - exit
Closes the Command Prompt window. - echo Hello World
Displays a message in the Command Prompt (outputs “Hello World”). - time
Displays or sets the system time. Example input:12:30:00
to set the time. - date
Displays or sets the system date. Example input:01-12-2024
to set the date. - hostname
Displays the name of the computer. - ver
Displays the version of Windows. - systeminfo
Displays detailed information about the system configuration. - tasklist
Lists all running processes. - taskkill /IM notepad.exe
Terminates the Notepad process.
File and Directory Management
- dir
Lists the files and directories in the current folder. - cd C:\Users\user1\Documents
Changes to the specified directory. - cd..
Moves up one directory level. - mkdir newFolder
Creates a new directory namednewFolder
. - rmdir newFolder
Deletes the empty directorynewFolder
. - del myfile.txt
Deletes the filemyfile.txt
. - copy C:\file1.txt D:\file2.txt
Copiesfile1.txt
fromC:
toD:
asfile2.txt
. - move C:\file1.txt D:\file2.txt
Movesfile1.txt
fromC:
toD:
. - rename oldfile.txt newfile.txt
Renamesoldfile.txt
tonewfile.txt
. - attrib +r myfile.txt
Sets themyfile.txt
file to read-only. - xcopy C:\Folder D:\Backup /s
Copies the entireFolder
fromC:
toD:\Backup
(including subdirectories). - robocopy C:\data D:\backup /e
Copies files fromC:\data
toD:\backup
, including all subdirectories and files.
Network Commands
- ping google.com
Sends a network ping togoogle.com
. - ipconfig
Displays the current IP configuration. - ipconfig /all
Displays detailed information about network interfaces. - tracert google.com
Traces the route packets take togoogle.com
. - netstat
Displays active network connections and listening ports. - nslookup google.com
Looks up DNS information forgoogle.com
. - net use X: \Server\SharedFolder
Maps network share\\Server\SharedFolder
to driveX:
.
System Configuration and Maintenance
- chkdsk C:
Checks and repairs errors on theC:
drive. - sfc /scannow
Scans and repairs system files. - diskpart
Opens the disk partition tool. - defrag C:
Defragments theC:
drive. - shutdown /s /f /t 60
Shuts down the computer in 60 seconds. - shutdown /r /f /t 60
Restarts the computer in 60 seconds. - powercfg /hibernate off
Disables hibernation on the system. - msconfig
Opens the System Configuration utility. - regedit
Opens the Registry Editor.
User Management
- net user
Lists all user accounts on the computer. - net user user1 password123 /add
Adds a new useruser1
with the passwordpassword123
. - net user user1 /delete
Deletes the user accountuser1
. - net localgroup administrators user1 /add
Addsuser1
to theadministrators
group. - net user user1 newpassword123
Changes the password foruser1
tonewpassword123
.
Drive and Disk Management
- diskpart
Opens the disk partition utility. - format D:
Formats theD:
drive (Warning: This deletes all data). - chkdsk C: /f
Fixes file system errors on theC:
drive.
Environment and System Variables
- set
Displays all environment variables. - set PATH=C:\NewPath
Sets thePATH
environment variable toC:\NewPath
. - echo %PATH%
Displays the current value of thePATH
environment variable.
Advanced Commands
- find “error” log.txt
Searches for the worderror
inlog.txt
. - findstr “error” log.txt
Searches for the worderror
inlog.txt
with more advanced options. - assoc .txt=txtfile
Associates the.txt
file extension with thetxtfile
type. - cipher /e C:\Data
Encrypts theC:\Data
folder. - tasklist
Lists all running processes on the system. - taskkill /f /im notepad.exe
Forcefully closesnotepad.exe
. - schtasks /create /sc daily /tn “Backup” /tr “C:\Backup\backup.bat” /st 02:00
Schedules a task to runbackup.bat
daily at 2:00 AM.
Help Commands
- help
Displays a list of available commands. - del /?
Displays help information for thedel
command.
PowerShell
Basic System Commands
- Clear-Host
Clears the PowerShell screen. - Exit
Closes the PowerShell window. - Write-Host “Hello World”
Displays a message in the PowerShell window (outputs “Hello World”). - Get-Date
Displays the current date and time. - Set-Date “12/01/2024 14:30”
Sets the system date and time to12/01/2024 14:30
. - Get-Command
Lists all available commands in PowerShell. - Get-Help Get-Command
Shows help information for theGet-Command
command. - Get-Process
Lists all running processes. - Stop-Process -Name notepad
Terminates thenotepad
process.
File and Directory Management
- Get-ChildItem
Lists the files and directories in the current directory. - Set-Location C:\Users\user1\Documents
Changes to the specified directory. - New-Item -Path C:\ -Name “newFolder” -ItemType Directory
Creates a new directory namednewFolder
inC:\
. - Remove-Item C:\newFolder
Deletes thenewFolder
directory. - Remove-Item C:\file1.txt
Deletes thefile1.txt
file. - Copy-Item C:\file1.txt -Destination D:\file2.txt
Copiesfile1.txt
fromC:
toD:\file2.txt
. - Move-Item C:\file1.txt -Destination D:\file2.txt
Movesfile1.txt
fromC:
toD:\file2.txt
. - Rename-Item C:\file1.txt -NewName file2.txt
Renamesfile1.txt
tofile2.txt
. - Get-Content C:\file1.txt
Displays the contents offile1.txt
. - Set-Content C:\file1.txt “New content”
Replaces the contents offile1.txt
with “New content”. - Add-Content C:\file1.txt “Additional content”
Appends “Additional content” tofile1.txt
. - Test-Path C:\file1.txt
Checks iffile1.txt
exists inC:
(returnsTrue
orFalse
).
Network Commands
- Test-Connection google.com
Sends a network ping togoogle.com
. - Get-NetIPAddress
Displays IP address configuration information. - Get-NetRoute
Displays routing table information. - Get-NetAdapter
Lists all network adapters on the system. - Set-NetIPAddress -InterfaceAlias “Ethernet” -IPAddress 192.168.1.100 -PrefixLength 24
Sets a static IP address for the “Ethernet” interface. - Get-DnsClientServerAddress
Displays DNS server information for the system.
System Configuration and Maintenance
- Get-EventLog -LogName System
Displays system event logs. - Get-EventLog -LogName Application | Where-Object {$_.EntryType -eq “Error”}
Displays error events from the Application log. - Get-Service
Lists all services running on the system. - Start-Service -Name wuauserv
Starts the Windows Update service. - Stop-Service -Name wuauserv
Stops the Windows Update service. - Get-Command -Module Microsoft.PowerShell.Management
Lists all commands available in theMicrosoft.PowerShell.Management
module. - Get-Help Get-Command -Full
Displays detailed help information for theGet-Command
cmdlet. - chkdsk C:
Runs a disk check on theC:
drive (run with admin privileges). - sfc /scannow
Scans and repairs system files (run with admin privileges).
User Management
- Get-LocalUser
Lists all local user accounts. - New-LocalUser -Name user1 -Password (ConvertTo-SecureString “password123” -AsPlainText -Force)
Creates a new useruser1
with the passwordpassword123
. - Remove-LocalUser -Name user1
Deletes the user accountuser1
. - Add-LocalGroupMember -Group “Administrators” -Member user1
Addsuser1
to theAdministrators
group. - Set-LocalUser -Name user1 -Password (ConvertTo-SecureString “newpassword123” -AsPlainText -Force)
Changes the password foruser1
tonewpassword123
.
Drive and Disk Management
- Get-PSDrive
Lists all available drives. - Get-Volume
Lists all volumes on the system. - Format-Volume -DriveLetter D -FileSystem NTFS -NewFileSystemLabel “NewVolume”
Formats theD:
drive with NTFS and labels it as “NewVolume”. - Set-Partition -DriveLetter C -NewDriveLetter Z
Changes the drive letter ofC:
toZ:
. - Resize-Partition -DriveLetter D -Size 100GB
Resizes theD:
partition to 100GB.
Environment and System Variables
- Get-EnvironmentVariable -Name PATH
Displays the value of thePATH
environment variable. - Set-EnvironmentVariable -Name PATH -Value “C:\NewPath”
Sets thePATH
environment variable toC:\NewPath
. - [Environment]::SetEnvironmentVariable(“MyVar”, “MyValue”, “User”)
Sets a user-level environment variableMyVar
with valueMyValue
. - [Environment]::GetEnvironmentVariable(“MyVar”, “User”)
Retrieves the value of the user-level environment variableMyVar
.
Advanced Commands
- Select-String “error” C:\log.txt
Searches for the string “error” in thelog.txt
file. - Get-Content C:\log.txt | Select-String “error”
Filters the content oflog.txt
to display only lines containing “error”. - Get-Command -Module Microsoft.PowerShell.Management | Export-Csv “commands.csv”
Exports all available commands in theMicrosoft.PowerShell.Management
module to a CSV file. - Start-Process notepad
Launches Notepad. - Stop-Process -Name notepad
Stops the Notepad process. - New-ScheduledTask -Action (New-ScheduledTaskAction -Execute “C:\Backup\backup.bat”) -Trigger (New-ScheduledTaskTrigger -At 2am -Daily) | Register-ScheduledTask -TaskName “BackupTask”
Creates and schedules a daily backup task at 2 AM.
Help Commands
Get-Help
Lists all available help topics.
Get-Help Get-Command
Displays help information for the Get-Command
cmdlet.
Get-Help -Name Get-Command -Full
Displays detailed help information for the Get-Command
cmdlet.
Bash
Basic System Commands
- clear
Clears the terminal screen. - exit
Closes the terminal window. - echo “Hello World”
Displays the message “Hello World” in the terminal. - date
Displays the current date and time. - date “+%Y-%m-%d %H:%M:%S”
Displays the current date and time in a custom format (e.g.,2024-12-01 14:30:00
). - hostname
Displays the name of the current machine. - uname -a
Displays system information like kernel version and OS. - uptime
Displays how long the system has been running. - whoami
Displays the current logged-in user.
File and Directory Management
- ls
Lists the files and directories in the current directory. - ls -l
Lists files in the current directory in long format (permissions, ownership, size). - cd /home/user1/Documents
Changes the current directory to/home/user1/Documents
. - cd ..
Moves up one directory level. - mkdir newfolder
Creates a new directory namednewfolder
. - rmdir newfolder
Deletes the empty directorynewfolder
. - rm file.txt
Deletes the filefile.txt
. - rm -r directory
Recursively deletes a directory and its contents. - cp file1.txt file2.txt
Copiesfile1.txt
tofile2.txt
. - mv file1.txt /home/user1/Documents/
Movesfile1.txt
to/home/user1/Documents/
. - rename file1.txt newfile.txt
Renamesfile1.txt
tonewfile.txt
. - touch newfile.txt
Creates an empty file namednewfile.txt
. - cat file.txt
Displays the contents offile.txt
. - more file.txt
Displays the contents offile.txt
one page at a time. - head -n 10 file.txt
Displays the first 10 lines offile.txt
. - tail -n 10 file.txt
Displays the last 10 lines offile.txt
. - find /home/user1 -name “*.txt”
Finds all.txt
files in the/home/user1
directory. - chmod 755 file.txt
Changes the permissions offile.txt
torwxr-xr-x
. - chown user1:user1 file.txt
Changes the owner and group offile.txt
touser1
. - ln -s /path/to/original /path/to/symlink
Creates a symbolic link.
Network Commands
- ping google.com
Sends a network ping togoogle.com
. - ifconfig
Displays network interface configuration (older systems, useip
instead). - ip a
Displays network interface configuration. - ip link show
Displays network interfaces and their states. - netstat -tuln
Lists all listening ports and their associated services. - wget http://example.com/file.txt
Downloadsfile.txt
fromexample.com
. - curl -O http://example.com/file.txt
Downloadsfile.txt
fromexample.com
usingcurl
. - ssh user1@hostname
Connects to a remote server via SSH asuser1
. - scp file.txt user1@hostname:/path/to/destination/
Copiesfile.txt
to a remote server using SCP. - ftp ftp.example.com
Connects to an FTP server.
Process Management
- ps aux
Displays a list of all running processes. - top
Displays a dynamic, real-time view of system processes. - kill 1234
Terminates the process with PID1234
. - killall firefox
Terminates all processes namedfirefox
. - bg
Resumes a suspended job in the background. - fg
Brings a job from the background to the foreground. - jobs
Lists all jobs running in the background or suspended. - nice -n 10 command
Runscommand
with a lower priority (nice value of 10). - renice 10 -p 1234
Changes the priority of the process with PID1234
to 10.
User Management
- whoami
Displays the current user. - id user1
Displays information about the useruser1
. - adduser user1
Adds a new useruser1
. - userdel user1
Deletes the useruser1
. - usermod -aG sudo user1
Addsuser1
to thesudo
group. - passwd user1
Changes the password foruser1
. - su user1
Switches to theuser1
account. - sudo command
Runs a command with elevated privileges (as superuser).
System Management
- df -h
Displays disk space usage in a human-readable format. - du -sh directory
Displays the total size of a directory (human-readable). - free -h
Displays memory usage (in human-readable format). - top
Displays a dynamic view of system processes. - shutdown -h now
Immediately shuts down the system. - reboot
Reboots the system. - systemctl status apache2
Checks the status of theapache2
service (or any other service). - systemctl start apache2
Starts theapache2
service. - systemctl stop apache2
Stops theapache2
service. - systemctl enable apache2
Enables theapache2
service to start at boot. - systemctl disable apache2
Disables theapache2
service from starting at boot.
Environment and System Variables
- echo $PATH
Displays the current value of thePATH
environment variable. - export PATH=$PATH:/new/path
Adds/new/path
to thePATH
environment variable. - printenv
Displays all environment variables. - unset VAR_NAME
Unsets (removes) the environment variableVAR_NAME
.
File Permissions and Ownership
- chmod 755 file.txt
Changes the permissions offile.txt
torwxr-xr-x
. - chown user1:user1 file.txt
Changes the owner and group offile.txt
touser1
. - chgrp group1 file.txt
Changes the group ownership offile.txt
togroup1
.
Search and Filtering
- grep “pattern” file.txt
Searches for the string “pattern” infile.txt
. - grep -r “pattern” /home/user1/
Recursively searches for the string “pattern” in the/home/user1
directory. - find /home/user1 -name “*.txt”
Finds all.txt
files in/home/user1
. - sort file.txt
Sorts the contents offile.txt
alphabetically. - cut -d ‘,’ -f 1 file.csv
Extracts the first column of data fromfile.csv
, assuming comma as delimiter. - wc -l file.txt
Counts the number of lines infile.txt
.
Help Commands
command –help
Displays help information for a specific command (e.g., ls --help
).
man command
Displays the manual for the specified command (e.g., man ls
).