1) Command Line Flashcards
Windows: Dir
Displays contents of current working directory.
Switches:
/p = Pauses after screen full of info
/w = Displays only filenames
/a = Displays files with specified attributes (see below)
D = Directories | H = Hidden files | R = Read-only
S = System files
Windows: Cd
Changes to specified directory (change directory)
Syntax: cd \documents\testfolder
Change Drives: cd D (do not use colon, just drive letter)
.. = Move up a directory
\ = root directory
Windows: Md/Rd
Md = Make Directory
Syntax: md /documents/newfolder
Rd = Remove directory
Syntax: rd /documents/newfolder
Rd Switches
/S = Removes all directories & files in specified directory
/Q = Quiet mode, does not ask if okay to remove
Windows: Ipconfig
Displays IP configuration details
Switches /all = Displays all IP config info /release = releases current IP address from DHCP /renew = re-assigns an IP via DHCP /flushdns = clears DNS cache
Windows: Ping
Used to test if an domain/IP can be reached & how long it takes
Switches
- t = ping specified host until stopped (ctrl-c)
- a = resolve address to host names
- l = specify ping packet size (buffer size)
Windows: Tracert
Shows the route that a packet takes to get to its destination (via domain or IP address)
Switches
- d = do not resolve addresses to hostnames
- 4 = force using IPv4
- 6 = force using IPv6
Windows: Netstat
Shows all TCP/UDP connections on your computer
Switches
- a = displays all connections & listening ports
- q = displays all connections, listening ports, and bound non-listening TCP ports
- r = displays routing table
Dion recommends -ano switch to view details
Windows: Nslookup
Enables you to determine exactly what info the DNS server is giving you about a specific hostname.
Displays host’s IP address (4 & 6)
Takes you to its own terminal
Then type in the web address being queried
Windows: Shutdown
Enables you to shut down a local or remote computer
Switches /r = reboot (full shutdown/restart) /s = shutdown /l = log off /a = abort shutdown /m \\computer = specify target computer /f = force applications to close without warning
Windows: Sfc
System file checker
Looks at system store (backup copies of critical files)
Compares them with current working files
Can choose to repair or verify only
Switches
/scannow = scans integrity of all protected files & repairs if needed
/verifyonly = scans integrity of all protected files
no repairs
Windows: Dism
Deployment Image Servicing/Management Tool
Best to run sfc first, if sfc finds a problem, run dism
Syntax: dism /online /cleanup-image /restorehealth
dism /online /cleanup-image /checkhealth
Enumerates, installs, uninstalls, configures, & updates features/packages in Windows images.
Switches
/online = Targets running OS
/checkhealth = looks for corruptions inside image
/restorehealth = attempts to repair corrupted scanned files automatically
Windows: Chkdsk
Checks a HDD & displays a status report
Switches
/f = fixes errors on the disk
Volume = specify drive to check
Syntax: chkdsk volume:C:
/scan = runs online scan of volume /L:size = specify log file size in Kb
Windows: Diskpart
Type ? for help
Command line partitioning tool equipped with its own commands.
List disk (shows disks & disk numbers)
Select disk 1 (select disk number 1 or whichever)
Create partition primary
List partition
Select partition
Assign (assigns drive letter to selected drive/partition)
Clean (removes all partition/volume formatting)
Create (creates partition on a disk)
Format (formats drive)
Syntax: format fs=ntfs quick label=test
Quick formats to NTFS with name test
Windows: Tasklist/Taskkill
Tasklist
Displays current running programs with PIDs & mem usage
Taskkill
Kills process by PID or name
Switches
/f = force quit
/t = terminates the process & child processes
Windows: Gpupdate
Forces an update to new group policies (AD)
Switches
/force = reapplies policy settings
/target = specify user/computer to target update for
/logoff = logoff after GP updates
/boot = restart after applying GP updates
Windows: Gpresult
Gives a quick overview of all security policies applied to a user/computer
Switches
/s = specifies name/IP of a remote PC (default: local)
/u = uses credentials of specified user to run command
/p = specifies password of user provided by /u
/z = displays all info about GP
Windows: Format
Formats a disk to accept Windows files (admin)
Syntax: format e: /q /fs:exFAT
Switches /q = quick format /c = compress new volume (NTFS) /fs: = specify file system /v: = specify volume name
Windows: Copy/Move/Del
Copy = copy file
copy filename.txt \users\filepath
Move = moves file (same copy syntax)
Del = deletes file del \documents\file.txt Wild card = * del *.txt (deletes all text files) del *.* (deletes all files in directory)
Windows: Xcopy
Copies files & directories, including subdirectories
Switches /s = copy all subdirectories /h = copy hidden files /l = list files to be copied /r = copies read-only files
Windows: Robocopy
Basically the same as Xcopy except:
Checks destination directory & doesn’t waste time copying unchanged files
Switches
/s = copies subdirectories (excludes empty)
/e = copies subdirectories (includes empty)
/mov = files, delete from source after copied (cut)
/move = files/directories, delete from source after (cut)
Windows: Net use
Used for mapping network shares
Syntax Example: Map resource to x: drive
net use x: \server1\research
Windows: Net user
Create/delete/change user accounts (admin)
On its own, displays user list
Syntax: net user username password
net user JohnDoe password123 /add
net user JohnDoe /delete
/active:no/yes = enables/disables user account
Windows: /?
Shows help options for specified command.
Linux: Ls
Displays contents of present working directory.
/ = Root directory | .. = Parent directory
~ = Home directory
ls > output.txt (outputs result to file)
Flags
- l = long format info
- la = includes hidden files/directories
- lh = displays file size too
- s = shows folder/file size
- t = sort by last modified date/time (-tr to reverse)
- R = all files/directories with subdirectories
- S = sort by file size (Sr to reverse)
Linux: Pipe “|”
Lets you use 2+ commands such that the output of one command serves as the input to the next
Cat filename | less
Displays file contents with one scroll length at a time
Linux: Grep
Used to search for a string of characters in a specified file.
Syntax: grep “string” filename.txt
With pipeline
ifconfig | grep 192.168.4.15
Flags
- r = recursive search (all files/subdirectories)
- l = list files containing the match
- w = whole word matches
- n = line number
- i = removes case sensitivity
Linux: Cd
Changes directory
Syntax: cd Documents
or cd /home/user/Documents
Add quotes if there is a space in the folder name
Linux: Cat
Displays file contents
Syntax: cat flags filename
cat list1.txt
Flags
- A = show all
- n = adds line numbers
Linux: Shutdown
Shuts down computer
Flags -c = cancel shutdown \+20 = specifies number of minutes until shutdown 15:00 = specifies time to shut down Now = shutdown immediately
-r = reboot system (1 min)
or add “now” or specific time to schedule restart
Linux: Pwd
Shows present working directory.
Linux: Passwd
Change user password
Syntax: passwd username
Will have you enter current password and new password.
Flags
- e = set an account’s password to expire
- l = lock user account
- d = delete password
Linux: Mv
Move file to specified path
Syntax: mv flags source destination
mv file1.txt file2.txt = basically renames file
mv file1.txt dir1/ = moves file to dir1 directory
Flags
- i = will prompt if you are overwriting
- v = (verbose) displays what is happening
Linux: Cp
Copies file to specified path
Syntax: cp flags source destination
Source can be 1+ files
- i = will prompt if overwriting
- R = recursive copy (creates directory specified if it doesn’t exist)
Linux: Rm/Rmdir
Rmdir = remove directory
Syntax: rmdir flags directoryname
-p = removes all directories in filepath
-v = (verbose) displays what is happening
Rm = remove files & directories
- r = removes directory structure
- f = never prompt user (ignores nonexistent files)
- d = identical to rmdir
Linux: Mkdir
Make directory (creates directory) Syntax: mkdir directoryname mkdir directory/pictures = creates subdirectory
Create multiple directories
mkdir -p folder/{sub1,sub2,sub3}
-p = creates directory structure
Linux: Chmod
Changes file permissions for specified file
chmod u+x file.txt = adds x for owner
chmod u-x file.txt = removes x for owner
Numbering
4 = r | 2 = w | 1 = x
7 = rwx | 6 = rw | 5 = rx
chmod 754 file.txt
rwx for owner | rx for group | r for other
This is over-simplified for someone that doesn’t fully understand
Linux: Chown/Chgrp
Chown = change file owner
sudo chown devon file.txt
-R = apply to files within directories recursively
Chgrp = change group owner
Old, you can do this with chown
Linux: iwconfig/ifconfig
ifconfig = basically ipconfig for Linux/macOS
iwconfig = gives details about NIC(s)
Linux: Ps
Displays processes currently running (PID & name)
Flags
aux = list all details for all processes (all users)
a = all users
u = detailed process info
x = list processes without a controlling terminal
-r = all running processes
-x = processes owned by user
Linux: Kill
Kills specified process (PID or name)
Syntax: kill flags pid/processname
kill 3286 or kill process-name
Flags
- KILL = force quit
- 9 = sync kill, powerful force quit
Linux: su/sudo
Sudo
Runs command with super-user/admin permissions
-s = changes full terminal to root permissions
Su
Allows you to become another user
Syntax: su user
Linux: Apt/Apt-get
Use sudo before running Apt update = update package lists Apt upgrade = install updated packages Apt install program-name Apt remove program-name Apt show package-name (package details) Apt search userquery (search for packages with query)
Apt-get is basically the same thing, except outdated
Linux: Vi
Built-in text editor for all Linux distros
Syntax: vi filename.php
If no extension is specified, txt file
Two Modes Command Mode (use cursor to select/cut/copy/paste/delete)
Insert Mode (ESC key in command mode or press I) Insert & edit text
Linux: DD
Used to create an exact, bit-by-bit image of any form of block storage (any mass storage medium)
Syntax:
dd if= of=
Uses:
Copy a hard drive, backup a thumb drive, wipe a disk
Wiping a disk
dd if=/dev/urandom of=/dev/sdb