Linux Commands Cheat Sheet

There are so many Linux commands that it can be difficult to remember them all, especially for beginners. That’s why I’ve created a handy Linux commands cheat sheet. Use this as a quick reference for when you just can’t remember the right command. It happens to me more often than I’d like to admit.

The Linux command set is extremely robust. Very frequently there are multiple Linux CLI commands to reach similar results. I have found these to be the most convenient for me. This isn’t meant to be an exhaustive list. It’s more of a beginners guide to Linux. I’m only providing common commands that are used frequently.

Notes

  • Some commands may need Sudo or SU prefixed before them for permissions reasons. This is especially true if you are not logged in as root. You would use “sudo command” or “su command” for example.
  • Append ” –help” to any command for options and syntax help.

Linux Commands Cheat Sheet

Display current directory (print working directory)
pwd

List files
ls

List files with details
ls -l

List files including hidden files
ls -a

List size of the contents of directories
du -sh *

Change directory
cd .. (return to parent directory)
cd exampledirectory (enter a subdirectory)
cd /rootdirectory/path/to/somewhere/ (jump to an absolute path from root)
cd / (go to file system root)

Make directory
mkdir newdirectory

Remove directory (directory must be empty)
rmdir directory

Remove a file
rm file.txt

Remove a directory with files
rm -r directory

Find a directory named example
find / -type d -name "example"

View file in text editor. There are many choices but I find nano to be the easiest to use.
nano

Copy a file
cp file.txt filecopy.txt

Rename a file
mv file.txt newfilename.txt

Move a file
mv file.txt anotherdirectory/file.txt

Change permissions of a file/directory (-R for recursively)
chmod -R 777 directoryorfile

Change owner of a file/directory (-R for recursively)
chown -R user:group fileordirectory

View partitions
fdisk -l or lsblk

Check disk space
df -h

Check modification/access date of file
stat filename

Read the last 10 lines of a log file and watch for new lines
tail -f example.log

Create an empty file
touch example.txt

Create a zip archive. The 5 signifies the level of compression. 0 is none and 9 is the most. This will recursively compress subdirectory into example.zip.
zip -5 -r example.zip subdirectory

Empty the contents of a file. This can be very useful for clearing log files without having to delete the file, recreate it, and adjust permissions.
cat /dev/null > logfile.log

Search for text within all files in this directory and recursively
grep -r exampletext

View resources and a list of processes ordered by top CPU usage. Tip: When top is running press shift-i to calculate percentages for multiple CPU cores.
top

Work with services. Some services will be under the service command instead of systemctl.
systemctl start SERVICE_NAME
systemctl stop SERVICE_NAME
systemctl restart SERVICE_NAME
systemctl status SERVICE_NAME

Start (enable) service at boot-up
sudo systemctl enable SERVICE_NAME

Download a file to this directory
wget https://someplace.com/somefile.txt

Show IP addresses
ip addr

Show IP Addresses
ip addr

Change a password
passwd username

Combining commands (Use “&&” per example)
cd .. && ls (go back a directory and list directory)

Restart the OS now
reboot now

Shutdown the OS now
shutdown now

Conclusion

This list should get you going if you are a beginner or help you remember easy Linux commands that you’ve forgotten. I hope this Linux commands cheat sheet has been useful to you.

Leave a Reply

Your email address will not be published. Required fields are marked *