Help get yourself started with the Linux operating system with this handy Linux Command sheet.
We mostly refer to commands that a beginner will find handy, however it doesn’t include highly detailed information regarding each command to help keep things brief.
This cheat sheet should prove useful to more than just Raspberry Pi users and is pretty important for anyone who wants to learn what they’re actually plugging into their Linux based terminal.
I hope that the information below is detailed enough for you to understand the basics of what the commands do. With almost every command there is a lot more advanced options that you’re able to use to help achieve the task you’re trying to do.
If you need more information simply check out the link associated with some of the more complex commands alternatively you can check out the manual page within Linux itself.
If you want to learn more about the Raspberry Pi and all the cool things you can do with it then be sure to check out my many cool Pi projects, guides and much more. I’m constantly adding more so be sure drop a follow over at any of the major social networks.
This section is for general Linux commands that don’t fit into a specific category but are useful to know.
These general commands can be helpful for your general day to day usage of Linux.
For example, you can utilize the
man command to bring up useful information on almost any command.
man command is short for manual and is used to retrieve the manual page for a specified command.
man command is useful when you want to find out what a specific command does while also exposing any additional options it might provide.
Using the man command is a helpful tool for learning how the huge variety of Linux commands work and can be useful when you are stuck.
You can even use the command
man man to view the manual pages of the man command itself.
Example of using the man command:
man man man ls
One thing to note is that not every command in Linux has a manual page, this is more of a problem with third-party party packages then tools provided by Linux.
A pipe in Linux is a form of redirection that can be used to send the output of one command to another.
[COMMAND1] | [COMMAND2]
The pipe is an incredibly useful tool when you want to get the result from a command then use that result in some form.
The pipe is represented by a vertical bar
| and is used in-between two commands. The output of the first command is then redirect into the second.
For example, to only show the first 10 entries of the
ls command, we can pipe its results through the
Example of using pipes in Linux:
ls | head
There are a variety of other use cases for pipes in Linux. Pipes are a tool that can really simplify managing a Linux based operating system.
File System Commands
This section touches on Linux commands that help with managing the file system on a Linux based operating system.
These Linux commands deal with tasks such as copying, moving, deleting, editing, unzipping and renaming files. The commands touch on tasks such as file permissions.
Traversing Directories in Linux
In Linux, there are a couple of different commands that make it easier for you to traverse and deal with directories.
By placing a dot in front of the slash (
/) like this
./ will mean that you are referring to the current directory you are in
Adding two dots in front of the slash like this
../ will mean that you are referring to the parent directory of the current directory.
The tilde symbol
~ refers to the home directory. This symbol is handy whenever you need to quickly refer to a file in the home directory or navigate to a file from the home directory.
Example of traversing directories:
./ ../ ~
ls command in Linux will list the contents of the current directory or the one that you have specified:
ls [OPTIONS] [FILE/DIRECTORY]
You can utilize the
-l flag to display more information about the file or directory.
This flag provides an abundance of extra information such as the permissions, owner, group, size, date, and the time-stamp of the last edit.
You can refer to our graphic below to see the extra data that is returned by using the
-l flag with the
ls command returns its data in a list format, with each file/directory being listed on a new line.
Find out more by following our guide on using the ls command in Linux.
Example of using the ls command:
ls /home/pi ls -l /home/pi
In Linux the
tree command is used to recursively display the contents of a directory.
tree command returns a depth-based indented list of all the files in both the current directory and all subdirectories.
This command is incredibly helpful when you want to work out the folder structure of a directory.
tree command is used without a directory, it will recursively list the contents of the current directory.
If you have specified a directory, the
tree command will search through that directory instead.
Example of using the tree command:
tree tree /home/pimylifeup
Example result from the tree command
Below you can see the result of using the
tree command within the home directory of a user on our Raspberry Pi.
pi@raspberrypi:~ $ tree . ├── Downloads │ ├── SampleFile.zip │ └── TestFolder │ ├── Hello.txt │ └── PiMyLifeUp.com ├── hellofile.txt ├── MagPi │ └── MagPi85.pdf └── SampleFile
cd command is a straightforward yet essential command for dealing with Linux systems.
The reason this command is so important is that it allows you to change from one directory to another.
To use the
cd command, all you need to do is type in
cd followed by the path that you want to change to.
You can refer to our Traversing Directories in Linux section for tips on how to deal with directories quicker using some simple shortcuts.
Example of using the cd command:
cd /directory cd ..
You can always learn more about traversing Linux using the cd command with our guide.
pwd command is a straightforward command that outputs the path of the current directory starting from the root directory (
pwd stands for Print Working Directory.
This command can be useful when you want to know the path of the current working directory.
Example of using the pwd command:
mkdir command will create a new directory in the location that you specify.
mkdir [OPTIONS] [DIRECTORY]
If you run
mkdir command with just a name then it will create that directory in the current working directory. For example
Otherwise if you run the command with a path specified that it will create a directory in that location. For example
By default the
mkdir command will only create a new directory in that path if all of its parents exists.
mkdir /home/parent/old/young wont work if “parent” or “old” directories do not exist.
To make all the non-existing parent directories you can utilize the
-p flag. This flag will recursively create any missing directories.
Example of using the mkdir command:
mkdir pimylifeup mkdir /home/pimylifeup mkdir -p /home/pimylifeup/create/new/directories
rmdir command is useful for removing empty directories.
rmdir [OPTIONS] [DIRECTORY]
There is two ways to use the
rmdir command, the first is to remove a single empty directory by just specifying its path.
The second way of using the
rmdir command is to use the
-p flag which will remove all parent directories as long as they are empty as well.
You are unable to force the
rmdir command to remove directories if they are not empty, to do that you will need to make use of the
Example of using the rmdir command:
rmdir emptydir rmdir /emptydir1/emptydir2/emptydir3/
rm command will remove the specified file or directory. You will rely on this command a lot during the day to day usage of Linux.
rm [OPTIONS] [FILE/DIRECTORY]
There are a couple of different ways you can utilize the
rm command in Linux.
The first way is for removing a single file. You can remove a single file by utilizing the
rm command, followed by the path to a file.
To remove directories, you will need to make use of the
-r flag. This flag will also remove any files or directories contained within that directory.
rm -r /home/pimylifeup/
rm command doesn’t truly delete your files but instead un-links them from the file system and marks it as available space.
To ensure a file has been thoroughly deleted, you should utilize the
Be careful though the
rm command will still make restoring a file extremely hard.
Example of using the rm command:
rm /path/to/file rm -r /home/pimylifeup
cp command will create a copy of a file in the specified location.
cp [OPTIONS] [FILETOCOPY] [NEWFILENAME]
You can use the
-r flag with the
cp command to recursively copy the entire contents of a directory.
Example of using the cp command:
cp file newfilename cp -r /path/to/copy/ /newpath/to/copy/to
mv command moves a file and places it at the specified location.
mv [OPTIONS] [FILETOMOVE] [WHERETOMOVETO]
If you want to move the contents of a directory using the
mv command, then you need to utilize the
This command is similar to
cp, but instead of copying the file, it moves it.
You can also use the
mv command in Linux to rename a file by referencing the file you want to rename, followed by the new name.
Example of using the mv command:
mv file.txt ./newdirectory mv file.txt newname.txt mv -r /directorytomove /newdirectory
touch command will either update the last modified timestamp of the specified file(s) or creates the files if they don’t already exist.
Files created using the
touch command will be empty.
This command is useful for those who want to create a file but have no data to store at its time of creation.
Example of using the touch command:
touch file.txt touch file1.txt file2.txt file3.txt
cat command is short for “concatenate” and has a variety of different functions.
cat [OPTION] [FILENAME]...
To start with, the
cat command can be used to view the contents of a file by using
cat followed by the filename.
cat filename.txt, will display the contents of the file called filename.txt.
You can also use the
cat command to create a file by making use of the greater than
cat > newfile.txt will create a file called newfile.txt.
You can also use the
cat command to output the contents of multiple files.
cat *.txt will list the contents of all of the
.txt files in the current directory.
cat file.txt cat file.txt file.txt cat *.txt cat > newfile.txt
There is plenty more to the
cat command, but we will cover that in a future tutorial.
Example of using the cat command:
head command will display the beginning of a file.
It is the opposite of the
head [OPTIONS] [FILENAME]
You can utilize the
–n flag with the
head command to specify the number of lines to show.
By default the amount of lines shown by the
head command is 10.
Example of using the head command:
head file.txt head file.txt -n 20
tail command will display the end of a file. It is useful for retrieving the latest lines in a log file for example.
It is the opposite of the
tail [OPTIONS] [FILENAME]
To specify the number of lines you want to be displayed, you can make use of the
By default, the
tail command will display the last 10 lines in a file.
Example of using the tail command:
tail file.txt tail file.txt -n 20
chmod command is used to alter the permissions of a file or files.
The chmod offers both symbolic or numerical notation depending on what you prefer.
For example, the symbols used for the symbolic notation are u (user), g (group), o (other users), r (read), w (write), and x (execute).
An example of this is
chmod u+x samplefile. This command will add the execute permission to the owner of a file called samplefile.
If you are using the numerical notation, then refer to the table below to see which number represents the permissions you want.
|3||Write and execute|
|5||Read and Execute|
|6||Read and Write|
|7||Read, Write and Execute|
The order of the numbers should be as followed owner, group and then others,
For example the command
cmod 777 samplefile will give full permissions to the user, group and others on a file called samplefile.
Example of using the chmod command:
chmod 754 file chmod u=rw file
We delve further into the chmod command in our guide.
This guide will explain the differences between the symbolic and numeric notation more thoroughly.
chown command can be used to change the user and/or the group that owns a file.
chown [OPTIONS] [USER]:[GROUP] [FILE/DIRECTORY]
For example we can use the following command
sudo chown pi:root samplefile to change the owner of a file called samplefile to pi and the group to root.
One thing to note is that the
chown command normally needs to be run as a super userto work.
You can do this by by either running
sudo su prior to running the command or just appending
sudo in front of the command.
Example of using the chown command:
sudo chown pi:root file
dd command is primarily utilized to copy and convert files on Unix based systems.
dd command is often used to create a copy of an entire disk to a single file, a feature that is useful for creating backups.
For example, using the command
dd if=/dev/sdd of=backup.img will create a backup image of an SD card or USB drive that is mounted at
Make sure to use the correct drive when restoring an image as the
dd utility will overwrite/wipe the disk that you restore to.
Example of using the dd command:
dd if=/dev/sdd of=backup.img dd if=backup.img of=/dev/sdd
df command will display the disk space available for all currently mounted file systems.
df [OPTIONS] [FILE]
If you specify a file with the
df command, then it will return the free space for the mount that contains the file.
You can also use the
df -h) to see the output in a human-readable format.
For example, bytes will be replaced with kilobytes (KB), megabytes (MB), gigabytes (GB) or terabytes (TB)
Example of using the df command:
df df /home/pimylifeup/samplefile df -h df -h /home/pimylifeup/samplefile
unzip command can be used to extract files and directories from a compressed zip archive.
unzip [OPTIONS] [ARCHIVE]
If you want to extract the files with the
unzip command to a particular destination, then you can make use of the
Example of using the unzip command:
unzip archive.zip unzip archive.zip /dir/to/unzip/to/
tar command can be used to compress files in the tar format as well as extract tar archives.
tar [OPTIONS] [ARCHIVE]
You can also use the
tar command to extract both
To create a compressed tar file you need to use the
tar -cvzf archive.tar.gz directory.
In order to extract the contents of a tar archive you need to use the
tar -xvzf filename.tar.gz.
If you want to extract the contents of a tar archive to a different directory then you can utilize the
tar -C /dir/tar/here -zxvf archive.tar.gz.
Example of using the tar command:
tar -cvzf archive.tar.gz directory tar -xvzf archive.tar.gz tar -C /dir/tar/here -zxvf archive.tar.gz
wget command is a useful utility for downloading files from a website to your device.
wget [OPTIONS] [URL]
The most basic usage of the
wget command involves using wget followed by the URL that you want to download a file from.
wget https://example.com/file.txt will download file.txt from the website https://example.com/ into the current directory.
If you would like to save the file to your device with a different name, then you can make use of the
-O flag, followed by the name of the file you want to use.
wget -O pimylifeup.txt https://example.com/file.txt will download the file called file.txt then redirect the download output to our pimylifeup.txt file.
Example of using the wget command:
Search Commands in Linux
This section of the Linux command cheat sheet is for commands that search/find directories and files.
These commands are handy for when you are trying to find something that is not in its usual location.
grep command is used to search inside files for certain patterns.
It is quite a powerufl tool as you are able to use complex
grep [OPTIONS] [REGEX] [FILE]
GREP stands for globally search a regular expression and print.
grep "search" *.txt will search in all the text files that are in the current directory for the string “search”.
GREP also supports regular expressions which allows special letter combinations to be included in the search.
Example of using the grep command:
grep "search" *.txt grep "Pi.*Life Up" *.txt
find command will search for directories and files that match a specific pattern.
find [DIRECTORY] [OPTIONS]
There are a lot of different combinations that can be used to help extend the accuracy of this command.
The results of the
find command can be piped (
|) through to other commands such as grep to again improve the search.
Example of using the find command:
find . -name 'help'
whereis command will display the documentation, binaries, and the source files of a specific command.
It will look through standard program locations until it finds the requested command.
Example of using the whereis command:
The following commands are related to networking and can be used for diagnostics when it comes to working out network-related issues or just for information gathering.
We have included these commands as they can be pretty useful for dealing with a Linux operating system and testing networking.
ping command is typically used to check if communication can be made with another host and monitoring the response time.
It can simply be be used with the default settings by just specifying a hostname (e.g.
ping pimylifeup.com) or an IP address (e.g.
Example of using the ping command:
ping pimylifeup.com ping 126.96.36.199
hostname command will display the current hostname of the system.
hostname [OPTIONS] [HOSTNAME]
A privileged (super) user can set the hostname to a new one by supplying it as an argument (
sudo hostname newName).
-I flag. can be used alongside the
hostname command to instead show the IP for the hostname of the device.
Example of using the hostname command:
hostname hostname -I sudo hostname newName
ifconfig command displays the network configuration details for the interfaces on the current system when it is run without any arguments.
By supplying the command with the name of an interface (e.g. eth0 or lo) you can see the configuration for that specific interface.
You can also configure interfaces and also set them to up or down. It’s best to refer to the manual pages for more information on how to do this.
Example of using the ifconfig command:
ifconfig ifconfig eth0
ssh command stands for “secure shell” and allows you to connect to another terminal over an encrypted network connection.
ssh [OPTIONS] [USERNAME]@[IPADDRESS]
This is how we normally connect to the Raspberry Pi remotely.
On a Windows system you would of likely used a tool such as Putty to connect to a network over SSH.
Example of using the ssh command:
scp command is useful for securely copying files from one computer to another using the SSH protocol.
scp [TO COPY FILE/DIRECTORY] [COPY TO FILE/DIRECTORY]
SCP is short for secure copy and works exactly like the
cp command, except it accepts locations over the SSH protocol.
Upon using the
scp command, you will be prompted for a password before the transfer will begin.
Example of using the scp command:
scp /home/bob/*.jpg firstname.lastname@example.org:/home/gus/archive scp email@example.com:/home/gus/archive/*.jpg /home/bob
Process Management Commands
In this section of the Linux command cheat sheet, we will cover commands that help with process management.
Process management, just like any operating system, is critical on Linux.
The commands below will help you diagnose, monitor, and kill processes if required.
ps command will provide a snapshot of the processes currently running on your Linux-based operating system.
There are a variety of options that you can use with this command. If you need more information, simply use
man ps to get all the details.
Example of using the ps command:
top command can be used to see real time information on the processes that are currently running.
Much like the
ps command there is a ton of additional options you’re able to use with this command.
Example of using the top command:
kill command might sound grim but is a useful utility used to terminate a process or processes.
kill [PID] pkill [NAME] killall [NAME]
It’s a useful command to use when you find yourself with a process that won’t terminate or is frozen.
There are a few variations on this command that you’re able to use.
See the examples below to get a good idea of how you can use each variation of the
Example of using the kill command:
#Kill process with id pid (pid is process id) kill pid #Kill the process with matching name pkill name #Kill all processes with the matching name killall name
These commands are mostly useful for anyone who is running multiple users on the same operating system.
They’re typically used by system administrators to be able to add, delete and view the users and what they may be doing.
id command is used to print the ids of the current users and groups.
id [OPTION] [USERNAME]
This command is extremely handy when it comes to setting permissions to a specific group or user where the id number is required.
-g floag will print the group id whilst the
-u flag will print the user id.
Example of using the id command:
id id -u pi id -g pi
who command will list all the users that are currently logged in and any other useful information about the logged in users.
Example of using the who command:
last command shows a list of users who have recently been logged in.
This command works by searching through through the file located at
Example of using the last command:
groupadd command will do exactly as it sounds, it will create a new group with the options that you provide it.
groupadd [OPTIONS] [GROUPNAME]
You will need to be logged in as root for this command to work correctly.
Example of using the groupadd command:
useradd command will again do exactly as it sounds and create a new user.
useradd [OPTIONS] [USERNAME]
When you create a new user you will need to use passwd to assign a password to that account before it’s able to be used.
You will need to have superuser rights or logged in as root for this to work.
Example of using the useradd command:
userdel command will do exactly as you would expect it to, delete a users account.
userdel [OPTIONS] [USERNAME]
It’s also extremely important to note that it will also delete all the associated files to do with that user.
If this sounds a little heavy handed then
deluser might be a better alternative as it won’t remove the home directory unless you use the
As you would expect both these commands need superuser rights.
Example of using the userdel command:
userdel gus deluser gus
usermod command is used to modify a user account.
usermod [OPTIONS] [USERNAME]
There are a ton of options that you’re able to use to make the changes.
-d will allow you to alter the home directory of the user.
You will need to be a superuser to be able to make any changes.
Example of using the usermod command:
usermod -d /home/gusNewDirectory gus
passwd command is one of the most important as this will allow you to change the password of an account.
If you specify a username then the
passwd command will modify the password for that account.
To modify the password of a different account, you require superuser privileges.
Example of using the passwd command:
passwd passwd gus
There is always more commands but hopefully this Linux commands cheat sheet has covered all the important ones.
If you’re just starting out with the Pi and want more information then be sure to check out the handy section on getting started with the Pi.
If you want a cool downloadable version of this Linux cheat sheet then you can download it right here. Again much like this article if you notice a problem then be sure to leave a comment below.
If you feel like I have missed some commands that are important to beginners and advanced users then be sure to leave a comment below.