# Command Line cheatsheet
Cheat Sheets
Command |
meaning |
example |
pwd |
Print work directory |
|
ls |
list files in current directory |
|
ls -a |
List all files, including hidden files |
|
ls -l |
List files in current directory as a list |
|
ls -la |
List all files in current directory as a list |
|
cd / |
Change directory to root |
|
cd ~ |
Change directory to home |
|
cd - |
go back to the most recent dir you've been in |
|
history |
display past commands |
|
Command |
meaning |
example |
cp [origin] [destination] |
copy |
cp text.txt . |
mv [origin] [destination] |
move (and rename) |
cp text.txt . |
rm -rf folder_or_filename |
remove folder_filename forcefully recursively |
|
defaults write com.apple.finder AppleShowAllFiles TRUE |
Shows hidden files in Finder |
|
which python3 |
Shows you where the python command is located |
|
python -V or python --version |
Shows you the version of Python |
|
| touch scriptname.sh
| create shell script scriptname.sh | |
| echo "hello" > file.txt
| print "hello" to file.txt | |
| cat filename
| display contents of in terminal| |
| head filename
| print first x lines of filename | |
| tail filename
| print last x line of filename | |
| tail -f your.log
| Open a live version of the file your.log in the terminal
| history > file1.txt
| replace contents of file1.txt with history | |
| history >> file1.txt
| append contents of file1.txt with history | |
| history \ grep "git" > file1.txt
| Find the word "git" in my history and replace the content of file1.txt with the result| |
Command |
meaning |
example |
find . -name "file*" |
find files and folders with the characters "file" AS part of the name |
|
find / -name "postgresql.conf" |
find the file 'postgresql.conf' recursively from the root folder |
|
Command |
meaning |
example |
lsof -i tcp:8000 |
List open files on tcp port 8000 |
|
kill -9 pid |
kills the process with the pid |
|
lsof -t -i tcp:8000 | xargs kill -9 |
kill all processes on port 8000 |
|
killall Finder |
Restarts the Mac Finder program |
|
ps aux |
report a snapshot of the current processes. a = show processes for all users, u = display the process's user/owner, x = also show processes not attached to a terminal |
|
top |
Show all the running processes within your Linux environment |
|
Command |
meaning |
example |
chmod 124 filename.ext |
change permissions - owner, user, guest |
|
| echo $USER
| print the username to the console |
| whoami
| Shows your user |
| sudo su
| Change to root user |
Command |
Description |
sudo apt update |
Fetches the list of available updates |
sudo apt upgrade |
Installs some updates; does not remove packages |
sudo apt full-upgrade |
Installs updates; may also remove some packages, it needed |
sudo apt autoremove |
Removes any old packages that are no longer needed |
reboot |
Reboot computer |
Commmand |
Description |
python3 script.py & |
Run python script in the background |
nohup python3 script.py & |
Run python script in the background and detach from session |
Commmand |
Description |
sudo service postgresql stop |
Stop postgres database |
sudo service postgresql start |
Star postgres database |
Command |
Description |
curl ifconfig.me |
Get own ip number |
curl https://freegeoip.app/xml/143.204.247.98 |
Get the geolocation of an ip number using the freegeoip service |
curl https://freegeoip.app/xml/bitmex.com |
Get the geolocation of an ip number |
dig 143.204.247.98 |
DNS lookup utility |
dig bitmex.com |
DNS lookup utility |
traceroute 143.204.247.98 |
print the route packets take to network host |
traceroute bitmex.com |
print the route packets take to network host |
option |
Effect |
-r |
recursively |
-m |
message |
Change ~/.bash_profile
, .profile
or ~/.zscrc
to set custom command aliases
alias |
Resolves to |
Description |
zshcf |
vim ~/.zshrc |
Edit zsh profile settings |
drwxr
rwx = Read Write Execute
Directory |
Owner |
Group |
User |
- |
- - - |
- - - |
- - - |
d |
rwx |
rwx |
rwx |
1 |
421 |
421 |
421 |
chmod 777 = read(4), write(2) and execute(1) right for owner(4), group(2) and user(1)
chmod 777 = give owner, group and user read, write and execute rights
chmod 444 = give owner, group and user read access
chmod 400 = give owner read access and all others no rights
Everything is a file!
#!/bin/bash/
echo "starting script...
touch ~/Desktop/virus"
echo "creating virus"
echo "=============="
echo "adding to virus..."
find /Users/vkng/Dropbox/99_code/Python/CodingNomads -name "*week*" >> ~/Desktop/virus
open ~/Desktop/virus
#!/bin/bash/
is called the shbang