Cheatography
https://cheatography.com
Linux command reference detailing commands I require most often.
This is a draft cheat sheet. It is a work in progress and is not finished yet.
General
lsb_release -a |
Linux version |
alias |
Show aliases attached to shell |
Locations
/var/www |
Server www sites / pointers to |
/var/log |
System / auth / php etc. logs |
/var/log/nginx/ |
NGINX access / error logs |
~/.ssh |
SSH config |
/etc/php |
PHP version installed |
Files
echo "xyz" > /somewhere/file.log |
Write xyz to given file |
touch myfile.txt |
Create a file |
nano myfile.txt |
Edit myfile.txt with Nano |
rm -rf /node_modules |
Remove node_modules recursively |
grep -r 'string to search' directory/to/search |
Search for string in files |
File system
ls -al -S |
Directory list in file size order |
ls -alt |
directory list in time order |
lsblk |
Display volumes / partitions |
df -i |
inode usage |
df -hT |
File system memory usage |
find / -size +20M |
Find large files |
find / -type d -name 'httpdocs' |
Find folder |
find / -name ‘filename.html' |
Find file |
file -s /dev/xvd* |
File system / partition types |
growpart /dev/xvda 1 |
Grow partition to newly added space |
resize2fs /dev/xvda1 |
Resize partition to new allocated size |
Permissions
chown -R root:www /var/www
Change ownership of /var/www to root user:www group
|
Networking
ping -c 4 8.8.8.8 |
Ping (Google) 4 times |
ip addr |
Network interfaces enabled? |
sudo nano /etc/network/interfaces |
Network config |
route -n |
Show kernal IP routing table |
sudo ifdown --force eth0 |
Network interface off (force optional) |
sudo ifup --force eth0 |
Network interface on (force optional) |
PHP
php -m |
List installed modules / extensions |
php --version |
PHP version on CLI |
Weblish
CTRL A, Esc |
Enter scroll mode (Esc to exit) |
User
whoami |
Output current user context to CLI |
groups |
Show which groups user belongs to |
adduser ubuntu www-data |
Add user ubuntu to group www-data |
GIT
git remote --verbose |
Show remotes for currently checked out repo |
git branch |
List local branches |
|
|
Services
sudo service /etc/init.d/mysqld restart
Restart service (full path)
|
sudo service nginx restart
Restart service (short)
|
sudo service --status-all
Service status + running / - stopped / ? services without status command
|
Display port attachments
|
Kill everything on given port (i.e. release 80 for NGINX restart)
|
Process and jobs
jobs |
List of background jobs |
jobs -l |
List with PID |
fg |
Bring most recent to front |
fg %2 |
Switch to specific job in list |
If you ctrl-z out of a command line program, such as man, it may leave a running process in the background
[3]+ Stopped man
3 = Number of stopped jobs in background
man = program that was stopped
Find and kill it
Package management
sudo apt-get autoremove |
Delete unused packages |
sudo apt-get purge php7.* |
Remove package |
apt list —installed | grep your-package-name |
List installed packages |
apt-get install your-package-name |
Install package |
apt-get update |
Update packages info about package from repo |
apt-get upgrade |
Update all packages |
apt-get install --only-upgrade <packagename> <anotherpackagename> |
Update specific package |
add apt-repository name-of-your-repo-here |
Add apt repo |
apt-cache search package-name-here |
Search for packages |
apt-get = older version of apt
MYSQL
apt-get install mysql-server
Install mysql
|
mysql_secure_installation
Secure installation
|
mysql -u your-username -p
Connect on CLI
|
CREATE DATABASE database_name_cant_use_hyphens_use_underscores CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Create DB
|
Show collation of tables
|
ALTER TABLE <some_table> convert to CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Alter table collation
|
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'a_password_here';
Create user
|
GRANT ALL PRIVILEGES ON db_name_here . * TO 'newuser'@'localhost';
Grant priviledges
|
Reload priviledges
|
|