Basic Linux commands cheat sheet for common use (including basic VI commands)
These will get you through 80% of your day-to-day work.
Folders & Files Linux Commands Cheat Sheet
| Actions | Linux commands |
|---|---|
| View contents of a folder | ls -l |
| List files and folder sizes (only first level) | du -sh * |
| Find free, used, and total space used | df -h |
| Count files in a directory | ls -1 | wc -l |
| Zip a directory | zip -r myarchive.zip myfolder |
| Unzip a file | unzip file.zip |
| Create a new folder | mkdir foldername |
| Recursively delete a folder | rm -rf foldername |
| Create a new file | touch new-file.txt |
| Delete a file | rm new-file.txt |
| Move files from subfolder to parent | mv mysubfolder/* ./ |
| Copy a folder recursively | cp -R myfolder/ myfolder_backup/ |
| Copy a file | cp file.txt file-copy.txt |
| Rename a file | mv oldFileName newFileName |
| Display the current directory | pwd |
| Search in the current directory | find . -name pattern find . -name mynameprefix\* ("pattern" = file and folder name) |
| Find all file and folder names | find / -name pattern |
| Combine many text files into one | cat ./folder/* all.txt |
More resources for handling files and folders/directories in Linux.
- Working with files and directories in Linux
- Linux Commands for Managing Files & Directories
- Find Files and Folders in Linux

Basic VI Cheat Sheet
VI and VIM have many functions, but these are the top commands to open, save, close, edit and search a file. For more actions, check out a more complete VI cheat sheet or VIM cheat sheet.
| Action | Vi Commands |
|---|---|
| Edit file | vi filename |
| Save file | :w |
| Begin editing | i |
| Exit editing mode | ESC |
| Save the file and quit the editor | :wq |
| Quit file | :q |
| Quit file without saving | :q! |
| Display file numbers | :set nu |
| Delete an entire line | dd |
| Search for a string or pattern | /pattern |
Services Linux Commands Cheat Sheet
| Action | Linux commands |
|---|---|
| View the Linux version | uname -a |
| Find the PHP version | php -i |
| Search for PHP settings location | find / -name "php.ini" php -i | grep php.ini |
| Restart Apache | /etc/init.d/apache2 restart |
| Start MySQL | service mysqld start |
| Check if MySQL is running | ps afux | grep -i mysql |
| Stop MySQL | service mysqld stop |

MySQL At The Command Line
Although I prefer to use a MySQL GUI like Sequel Ace for managing SQL, sometimes it’s you have to get your hands dirty and access the data from the command line.
| Action | MySQL Code |
|---|---|
| MySQL login | mysql -u root -p ("root" is your username) |
| Find running threads | mysqladmin processlist; |
| List all databases | show databases; |
| Select a database | use dbname; |
| List tables in a database | show tables; |
| Show table structure | describe tablename; |
| View table contents | SELECT * FROM tablename; |
| Insert a table row | INSERT INTO tablename (col1, col2) VALUES(15, 22); |
| Update a table row | UPDATE user_posts SET status_id = 2 WHERE id = '109'; |
| Delete a table row | DELETE FROM table WHERE user = 'john'; |
| Export database | mysqldump -uroot -p1234 dbname > dump.sql (where "root" = username and "1234" = password) |
In-depth resources for MySQL.
- MySQL cheat sheet via Devhints
- MySQL Tutorial’s MySQL cheat sheet
- MySQL cheat sheet on Github.

Cleanup Space on Linux
From time to time, server space issues can pop up. Here are quick ways to free up space in Ubuntu.
| Action | Linux Commands |
|---|---|
| Access admin rights | sudo -i |
| Clean APT cache (check size, clean, check size) | du -sh /var/cache/apt/archives sudo apt-get clean du -sh /var/cache/apt/archives |
| Remove old kernels | sudo apt-get autoremove --purge |
| Uninstall unused apps | sudo apt-get remove package-name1 |
| Remove no longer required packages | sudo apt-get autoremove |
Further resources for freeing up space on a Linux Server.
- Ask Ubuntu: How do I free up disk space?
- 7 Simple Ways to Free Up Space on Ubuntu and Linux Mint
- How to Clean Up Disk Space in Linux
Bonus: Debug PHP Files
| Action | |
|---|---|
| Syntax check all php files in a directory | find . -type f -name ".php" -exec php -l {} \; | grep -v 'No syntax errors' |
More Linux Commands Cheat Sheets
- My basic Git commands cheat sheet
- Guru 99’s Linux Commands Cheat Sheet
- Linux Training Academy’s Linux Commands Cheat Sheet
- How to Use Linux Commands Cheat Sheet