Manipulate Files & Directories
Navigate directories
pwd: Display path of current directory you’re in
ls: List all files and folders in the current directory
ls -la: List detailed list of files and folders, including hidden ones
Change to a specific directory
cd: Change to home directory
cd /user/Desktop: Change to a specific directory called Desktop
cd .. : Move back a directory
Create a directory/folder
mkdir <dir>: Create a new directory
mkdir /home/Desktop/dir: Create a directory in a specific location
Create and edit files
touch <file>: Create an empty file
nano <file>: Edit an existing file or create it if it doesn’t exist.
Alternatives to nano text editor: vim, emacs
Copy, move and rename files and directories
cp <file1> <file2>: Create a copy of a file
cp -r <dir1> <dir2>: Create a copy of a directory and everything in it
cp <file> /home/Desktop/file2: Create a copy of a file in a different directory and name it file2.
mv <file> /home/Desktop: Move a file to a specific directory (overwrites any existing file with the same name)
mv <dir> /home/Desktop: Move a directory to another location
mv <dir1> <dir2>: Rename a file OR directory (dir1 -> dir2)
Delete files
rm <file>: Delete a file
rm -f <file>: Force delete a file
Careful now..
rm -r <dir>: Delete a directory and its contents
rm -rf <dir>: Force delete a directory and its contents
Be careful when using this command, it will delete everything inside the directory
Network Utilities
ping <host>: Ping a host
whois <domain/IP>: Get whois information about a domain or IP
dig <domain/IP>: Get DNS information
nslookup: <NS>: Get nameserver information
ifconfig: Configure/display network interfaces
iwconfig: Configure/display wireless network interfaces
netstat -r: Display kernel IP routing tables
netstat -antp: Check for established and listening ports/connections
arp -a: Display ARP cache tables for all interfaces
Secure File Transfer - (SCP)
Transfer files FROM the local system TO a remote host (Local > Remote)
scp /path/to/file user@host:/path/to/dest
Transfer files FROM a remote host TO the local system (Remote > Local)
scp user@host:/path/to/file /path/to/dest
Transfer directories and everything within it
scp -r /path/to/dir user@host:/path/to/dest
Transfer all files that match a specific filetype
scp /path/to/*.txt user@host:/path/to/dest
Transfer local public SSH public key to remote host
cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> .ssh/authorized_keys'
Output and analyze files
cat <file>: Display/output the contents of a file
less <file>: Display the contents of a file with scroll (paginate) ability (press q to quit)
head <file>: Display the first ten lines in a file
head -20 <file>: Display the first 20 lines in a file
tail <file>: Display the last ten lines in a file
tail -20 <file>: Display the last 20 lines in a file
diff <file1> <file2>: Check the difference between two files (file1 and file2)
System & User Information
cal: Display monthly calendar
date: Check date and time
uptime: Check system uptime and currently logged in users
uname -a: Display system information.
dmesg: Display kernel ring buffer
poweroff: Shutdown system
reboot: Reboot system
View disk and memory usage
df -h: Display disk space usage
fdisk -l: List disk partition tables
free: Display memory usage
cat /proc/meminfo: Display memory information
cat /proc/cpuinfo: Display cpu information
View user information
whoami: Output your username
w: Check who’s online
history: View a list of your previously executed commands
View last logged in users and information
last: Display last login info of users
last <user>: Display last login info of a specific user
finger <user>: Display user information
Installing & Upgrading Packages
Search for packages
apt-cache pkgnames: List all available packages
apt search <name>: Search for a package and its description
apt show <name>: Check detailed description of a package
Install packages
apt-get install <name>: Install a package
apt-get install <name1> <name2>: Install multiple packages
Update upgrade & cleanup
apt-get update: Update list of available packages
apt-get upgrade: Install the newest version of available packages
apt-get dist-upgrade: Force upgrade packages.
apt-get autoremove: Remove installed packages that are no longer needed
apt-get clean: Free up disk space by removing archived packages
Delete package's
apt-get remove: Uninstall a package
apt-get remove --purge: Uninstall a package and remove its configuration files
Processes & Job Management
top: Display running processes & system usage in real-time.
ps: Display currently running processes
ps -u <user>: Display currently running processes of a user
kill <PID>: Kill a processes by PID #.
killall <processes>: Kill all processes with specified name.
Start stop & resume jobs
jobs: Display the status of current jobs
jobs -l: Display detailed info about each job
jobs -r: Display only running jobs
bg: View stopped background jobs or resume job in the background
fg: Resume recent job in the foreground
fg <job>: Bring specific job to the foreground.
Download a full website:
wget -r domain.com
Keyboard Shortcuts
CTRL + L Clear terminal screen CTRL + D Log out of current session CTRL + C Stop (halt) currently running command/processes CTRL + Z Suspend (pause) currently running command/processes CTRL + W Delete the last word/argument CTRL + E Jump (skip) to the very LAST line CTRL + A Jump (skip) to the very FIRST line CTRL + F Move cursor one letter forward CTRL + B Move cursor one letter backward | ||||
CTRL + U Cut (copy) everything BEFORE the cursor CTRL + K Cut (copy) everything AFTER the cursor CTRL + Y Paste previously copied text | ||||
clear Clear terminal screen reset Fix display errors exit Exit (log out) current session tab Auto-complete | ||||
!! Repeat last command sudo !! Repeat last command as sudo (admin/root) user | ||||
Comments
Post a Comment