- you can keep this super handy by adding this alias:
alias cheatsheet="less ~path/to/cheatsheet.md
- get external ip:
curl http://ipecho.net/plain
- Or, this oneliner (put in an alias):
wget -q -O - http://zacanger.com/ip && echo " "
- Getting Help:
- View the manual for a command:
man command
- Get help without using
man
:command --help
(or, frequently,command -h
) - Can't remember the name of a command, but you know a relevant word?
apropos word
- Index of help pages:
info
- View the manual for a command:
- Basic file and directory operations:
pwd
shows your current directoryls
shows files in your current directoryls -a
shows all files (including hidden)ls -R
shows files recursivelyls -lt
shows files by modification time (most recent first)mv
moves a file or directory (also for renaming), egmv foo bar
ormv ~/bin ~/Dropbox/bin
rm
removes a file (this is permanent)rmdir
orrm -r
will remove a directory, recursivelynpm i -g trash-cli empty-trash-cli
gives you a really useful trash in the command line'alias rm='trash'
andalias erm='empty-trash'
are two aliases I use for safety
cp file
copies filecp -r directory
copies directory, recursively
mount /dev/device/name /media/device/name
mounts a filesystemunmount /media/device/name
unmounts it
dd
clones filesystems- It's probably best not to use
dd
until you really know it well
- It's probably best not to use
parted
,fdisk
,cfdisk
, andmkfs
are tools for working with filesystems and partitions- Again, probably best not to touch these until you're sure you know what's up
- Administration:
sudo foo
executesfoo
as a temporary administrator accountsu
orsudo su
orsudo -s
lets you become root (administrator)exit
exits that business
sudo !!
executes previous command withsudo
- Installing things from source:
- Unpack the archive (I highly recommend the utilities
atool
orunp
, becausetar
commands are ridiculous) cd
into the unpacked directoryless README
(orcat README
) -- always check for a README! (and an INSTALL file, if one exists!)- There may be a script to run that will generate some files you'll need,
./autogen.sh
./configure
checks for appropriate configs and generates a Makefile (if there's aconfigure
filemake
compilesmake install
will installalias makelist="make -rpn | sed -n -e '/^$/ { n ; /^[^ .#][^ ]*:/p ; }' | egrep --color '^[^ ]*:'"
is a useful alias for listing allmake
targetsmake clean
cleans up all the miscellaneous cruft from the configure and make processes
- Unpack the archive (I highly recommend the utilities
- Installing things using package managers:
- Debian (and its descendants):
sudo apt-get update
updates information on available packagessudo apt-get upgrade
upgrades out-of-date thingsapt-cache search word
searches for 'word' in available packagesapt-cache show packagename
shows details on 'packagename'sudo apt-get install packagename
installs packagenamesudo apt-get remove packagename
uninstalls packagenamedpkg --get-selections
shows currently installed packagessudo add-apt-repository
adds a PPA (Ubuntu)sudo dpkg -i file.deb
installsfile.deb
sudo dpkg -r programname
uninstallsprogramname
- Python:
- https://bootstrap.pypa.io/ Download these three, and run them with
python3 thing.py
pip install -U pip
installspip
(or updates)pip search pip
searches forpip
virtualenv dirname
creates a virtual environmentsource dirname/bin/activate
connects to that venvdeactivate
disconnectspip install pip==versionnumber -E dirname
installs pip at version number into venvpip freeze -E dirname > requirements.txt
exports venv info into shareable formatpip install -r requirements.txt
installs fromrequirements.txt
pip install -E dirname -r requirements.txt
imports venv fromrequirements.txt
- https://bootstrap.pypa.io/ Download these three, and run them with
- Node (NPM)
- Debian (and its descendants):
- Basic commands:
thing | less
views the output ofthing
in a paged formatless filename
views that filename in a paged formatG
jumps to the bottom of the viewg
jumps to the top/
starts a searchmore
andpg
are two earlier pagerspager
will start whichever one happens to be your defaultmost
is a very different alternative, without thevi
-like keybinds, which can also view binary files easily
cat file
will print the contents offile
to the terminallocate filename
will search (everywhere) for that filenamesudo updatedb
will update locate's database (this is usually set as a daily cronjob by default)
which programname
will show the location of an executable in yourPATH
grep query
will search everything belowcwd
for thatquery
grep query filename
will search only in the filefilename
command | grep query
will search the output ofcommand
forquery
ack
is a popular alternative togrep
grep
itself has a few aliases usually built in:egrep
,fgrep
, maybevgrep
ag
(AG, The Silver Searcher) is the grep to be using:- Less characters to type
- Better highlighting, colour options, and defaults
- MUCH faster than
grep
(orack
) - Plus the guy who wrote it is just a really swell person
- https://github.com/ggreer/the_silver_searcher
ps -e
lists all running processesps aux | sort -nk +4 | tail
lists the top ten processes by memory usageecho " "; ps -eo pcpu,pid,user,args | sort -rk1 | head -6 | column -t; echo " ";
lists the top five processes by CPU usage
top
is an interactive system monitorhtop
is a much nicer alternative:- colour
- settings
- much cleaner
- more friendly keys
- http://hisham.hm/htop/
npm i -g vtop
will install a (javascript) version- very much simplified
- nifty little graphs
pkill processname
kills processnamepkill -NUM name
kills name using the signalNUM
pkill -9 foo
kills foo withSIGKILL
(kill it dead, right now, do it!)pkill -15 foo
kills foo a little bit more gently, allowing time for cleanup, etc.
renice process
stops the processes from hogging all resources and making computer lagcommand &
startscommand
in the background (so you don't need to waste a terminal on it)nohup command &
startscommand
in the background and keeps it running after you've logged off
tar
is a mess. you could memorize all of its commands and flags, or...- you could use
unp
, which is in Python, and is as simple as typingunp archivename.extension
- you could use
atool
(which I recommend):aunpack foo.ext
unpacks the archivefoo.ext
als foo.ext
lists all its filesapack
to make an archive- http://www.nongnu.org/atool/
- you could use
gpg -o outputname.gpg -c targetfile
to encrypt a filegpg -o outputname -d target.gpg
to decrypt a file
- Shell things (mostly Bash, but Zsh is usually pretty compatible):
- Directories:
~/
means user's home./
meanscwd
(current working directory)../
is parent directory../../../../../
means the great-great-great-grandparent dierctory (Etc)*
means all files in current directory (use caution, always)
- Output redirects:
|
is the heart of UNIX.foo | bar
sends the output offoo
to the input ofbar
foo | bar | quux > baz
sends the output of foo into bar, out to quux, and then writes that output to baz
things > stuff
sends the output ofthings
to a file,stuff
(warning, this WILL overwrite the content ofstuff
)blah >> stuff
will append the output ofblah
tostuff
(so, it won't overwrite)
tee
works like|
, but it also writes its output to the terminal (it's aT
shaped output!)- so
cat foo.txt | sort | uniq tee bar.txt
willcat
all offoo.txt
, sort it (alphabetically), remove duplicate lines, and send the output to bothbar.txt
and the terminal
- so
;
:one ; two
will executeone
fully, then execute2
&
will execute simultaneously&&
will only execute if the previous command was completed successfully
||
only executes if the previous command completed unsuccessfully*
matches zero or more characters?
matches any one character[chars]
matches any characters inside brackets[a-z]
matches any characters inside that range
- Directories:
- Some more basic utilities:
ifconfig
andiwconfig
to configure network interfaces and wireless network interfaces (specifically)ssh username@ipaddress
to connect to a serverssh -X username@ipaddress
to forward X (the display server) from the target to your current machine
scp -r sourcefilename:user@ip targetfilename:targetuser@targetip
copies files/directories from one machine to another (recursively)rsync source target
copies changes between files/directories (very useful for syncing, can work remotely like ssh)ping address
checks ifaddress
(which can be an IP address or a domain) is available, and reports response timestraceroute ipaddress
views the full network route toipaddress
iptables -L
shows firewall rulesnmap localhost
shows open ports onlocalhost
wget http://zacanger.com/
downloadshttp://zacanger.com/
wget -c
completes a partial download-b
runs in the background-ftp-user=username --ftp-password=password ftp://example.com/directory/file
downloads over FTP--mirror
does a full-on mirroring download-i file
reads urls infile
as a list to download
netcat
listens for input from the network, and dumps to a filechown username file
changes the owner of a file (may need to be run as root, depending on the file)chown -R username directory
for directories, recursively
chmod
changes file permissionschmod +x
makes a file executablechmod -x
makes it not executable
users
shows current usersadduser
adds a userusermod
changes user privelegesdeluser
removes a user
groups
shows all user groupsgroupadd
creates a new groupgroupmod
changes privelegesdelgroup
removes group
lsof
shows what processes are using what filesdiff
shows the differences between two fileshead -n NUM file
shows the top NUM lines offile
tail -n NUM file
shows the last NUM lines offile
md5sum file
andmd5deep directory
checksum file/all in directorysha1sum
andsha1deep
are the same, but with sha1watch -d -n NUM command
callscommand
every NUM of seconds, shows difference in outputtime command
executescommand
and shows how long it tookdu -a directory | sort -n -r | less
shows files in directory from largest to smallestdate
shows date and timedmidecode
shows motherboard infoinxi
shows system info in a much more friendly format
echo $HOSTNAME
shows current hosnamelsb release -a
shows current (Linux) distro infocat /etc/issue
does similaruname -a
shows (Linux) system/kernel infolsmod
shows info about kernel modulesmodprobe
to configure kernel modules (caution!)printenv
shows environment variables- (so does
env
on most systems)
- (so does
lspci
shows PCI-connected hardwarelsusb
shows USB-connected hardware
dumpcap
dumps wireless card datadumpkeys
dumps keyboard driver data
- Git:
git init
creates new repo (project)git config user.name "username"
git config user.email "email"
git clone target
clones to localgit commit -m "message"
commits withmessage
git status
shows curernt statusgit log
shows full loggit pull
git push
git branch
createsgit checkout branchname
switches to branchnamegit merge branchname
merges branchnamepip install -U legit
will give you some fantastic shortcutslegit help
andlegit install
to get started
npm i -g gh
gives you some nifty Github specific commands (trygh
to get started)hub
is Github's official client- Adds some Github-specific things to Git, like:
- Pull Requests
- Issues
- Cloning from Github with the shorthand
hub clone user/repo
- https://github.com/github/hub/releases
- or,
brew install hub
(on a Mac)
- Adds some Github-specific things to Git, like:
- See my .gitignore_global
- See my .gitconfig
- Much, much more
- MySQL:
help
show database
shows databasesuse databasename
show tables
shows schemasDROP DATABASE databasename
CREATE DATABASE databasename
CREATE USER username@hostname IDENTIFIED BY 'password';
select * from mysql.user;
shows usersdelete from mysql.user WHERE User='username';
mysqldump databasename > dumpfilename.txt
exports text with commands to rebuild all tablesmysql -u username -p < dumpfilename.txt
restores from a dumpmysqldump -u username -p --opt databasename > dumpfilename.sql
dumps the entire databasemysql -u username -p --database=databasename < dumpfilename.sql
restores from the full dump
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.