Basic Ubuntu Commands And Terminal Shortcuts (Cheat Sheet)

Basic Ubuntu Commands And Terminal Shortcuts (Cheat Sheet). First of all, Ubuntu is overwhelming, especially if you’re not familiar with using a terminal. After all, the Ubuntu terminal is the best way to interact with the system and execute tasks. Learning the basic Ubuntu commands and terminal shortcuts helps you take full advantage of this powerful operating system.

Whether you’re new to Ubuntu or a seasoned user, this cheat sheet boosts your productivity and optimizes your workflow. Well, you are able to navigate the terminal interface effortlessly, manage files and directories, install and update software packages, troubleshoot common problems and accomplish a host of other tasks. So let’s get started.

What is Ubuntu?

Primarily, Ubuntu is a free and open source Linux based operating system that delivers a host of impressive features. Hence, users particularly love it because of its intuitive interface, reliability, and ease of use. One of the standout features is the package management system, which makes it easy to install and update.

Whether you prefer a graphical interface or command line tools, Ubuntu has you covered. The OS also comes with pre installed software such as LibreOffice, Firefox, and Thunderbird. As a result, it’s an ideal choice for productivity, entertainment, and communication. 

Basic Ubuntu Commands

cd Command

First cd command, which stands for “change directory,” helps you navigate through folders and directories in Ubuntu. When you run the cd command, you have to specify the directory you want to change to by providing the path. Well, use an absolute path (starting with /) or a relative path (starting with ./ for the current directory or the name of a directory)

And the syntax for the cd command is:

				
					cd [options] directory
				
			

For Example: Let’s use the cd command navigate from the home directory to the Desktop. Starting from the home directory, enter the following command into the Ubuntu terminal and hit Enter. 

				
					cd Desktop
				
			

ls Command

Next is ls (list) command, that displays a list of files and subdirectories in the current directory.

Here, the basic syntax of the ls command is:

				
					ls [options] file/directory
				
			

Another Example: We list the files and directories stored in the Ubuntu desktop. So, we start by navigating to the Desktop using the cd command (shown above). Next, we use the ls command to display the files and directories.

Step 1: Go to Desktop by using the cd command. 

				
					cd Desktop

				
			

Step 2: Use the ls command to display the files and directories.

				
					ls
				
			

pwd Command

Are you curious to find out where you currently stand in the Ubuntu file system? Then, use the pwd command (Print Working Directory). In nutshell, this tool displays the directory you’re currently operating in.

Syntax for the pwd command is:

				
					pwd [-options]
				
			

Example: Let’s use the pwd command to print out the full path of our working directory in Ubuntu. Please, enter the following command and hit Enter. 

				
					pwd
				
			

mkdir Command

Another command, often used utility in Ubuntu and other Linux based operating systems. This abbreviation stands for “make directory,” which accurately reflects its purpose – to generate new directories or folders within a file system.

mkdir command looks like this:

				
					mkdir [option] directory_name 
				
			

Example: We generate a new directory named “myfiles” in the current working directory while providing the owner with read, write, and execute permissions, and only allowing read and execute permissions for group and others, we execute the following command:

				
					mkdir -m 755 myfolder 
				
			

Basically, use the ls command to view the newly created directory. 

rmdir Command

Deleting empty directories in Ubuntu one by one using the graphical interface is clunky affair. So using, rmdir command is a powerful and flexible command that enables you to remove empty directories quickly and efficiently using the command line.

Now let’s look at the rmdir syntax:

				
					rmdir [options] directory
				
			

Example: For this example, remove the “myfolder” directory we created with the mkdir command above.  

				
					rmdir myfolder
				
			

Confirm that the directory has been removed by running the ls command. 

Note: After you’ve executed this command, the “myfolder“ directory is deleted from your machine as long as it contains no files or subdirectors. Should there be any files or subdirectories in the target directory, any attempt to run the rmdir command returns an error message.

rm Command

Following is the rm command. Primarily used to delete files or directories.

 

Follow the basic syntax:

				
					rm [options] file(s)/directory(s)
				
			

Example: Lets remove file named “testfile.txt” using the -i option. Run the command below and then type yes to delete the file.

				
					rm -i testfile.txt
				
			

cp Command

Further, we have cp command. Simply put, in Ubuntu we use it to copy files or directories from one location to another.

 

Take a look at the command below:

				
					cp [options] source_file destination_file
				
			

Example: If you want to copy a file called “mycopiedfile.txt” from your current directory to a directory called “newfiles”, use the following command: 

				
					cp mycopiedfile.txt newfiles/
				
			

mv Command

Next is the the “mv” command, used to move or rename files and directories in Ubuntu.  Additionally, “mv” stands for “move.”

 

And the basic syntax of this command is as follows:

				
					mv [options] source destination
				
			

“Source” refers to the file or directory that you want to move or rename, and “destination” refers to the new location or name of the file or directory. If the “destination” is a directory, then the “mv” command moves the file or directory to that directory. If the “destination” is a filename, then the “mv” command renames the file to the new name.

Example 1: To move a file called “myfile.txt” from the current directory to a directory called “myfolder,” use the following command:

				
					mv myfile.txt myfolder/
				
			

Example 2: To rename the file “myfile.txt” to “mynewfile.txt,” you would use the following command:

				
					mv myfile.txt mynewfile.txt
				
			

touch Command

Further, touch command is used to create an empty file or update the modification time of an existing file. If the file you’ve specified doesn’t exist, the touch command creates a new empty file with the specified name. What is more, if the file already exists, it updates the modification time of the file to the current system time. Note that it doesn’t modify the content of the file. 

See the touch command below:

				
					touch [options] file
				
			

Example: Run the following command to create a new file named mynewfile.txt:

				
					touch mynewfile.txt
				
			

cat Command

Another is the cat command, that allows you to create, merge, or print files to the standard output screen or to another file. The word “cat” stands for “concatenate”

Follow the basic syntax of the cat command:

				
					cat [options] [file(s)]
				
			

Example : Let’s print out the contents of files called myfile1.txt and myfile2.txt to standard output. The text in the files is “text in file (1/2).”

				
					cat file1.txt file2.txt
				
			

grep Command

Now here there is a grep command. Commonly used to search for a specific string or pattern in one or multiple files. Additionally, it allows for complex pattern matching when used with regular expressions.

Syntax of the command: 

				
					grep [options] pattern [file(s)]
				
			

Example: In this example, we search for the word “hello” in myfile.txt

				
					grep "hello" file.txt
				
			

chmod Command

Furthermore, there is chmod. A command used to change the permissions of files and directories. Also, you modify the read, write, and execute permissions for the owner, group, and others on a file or directory. Make the modifications using either a numeric representation or a symbolic representation. The numeric representation involves using a three digit number to represent the permissions, while the symbolic representation involves using letters to represent the permissions. 

Chmod syntax command : 

				
					chmod [options] mode file
				
			

Example: For example, to give read, write, and execute permissions to the owner of the file “myfile.txt”, and only read permissions to everyone else, you would use the following command:

				
					chmod 744 myfile.txt
				
			

wget Command

Besides, we have the wget command, used for retrieving files over the internet using HTTP, HTTPS, and FTP protocols. wget stands for “web get”. With this command, you download files, recursively mirror entire websites, and perform various other tasks related to file transfer.

 

All in all, the basic syntax for wget is as follows:

				
					wget [option] [URL]
				
			

Example: Use the following command to download VirtualBox to Ubuntu. Make sure to get the relevant download link from the VirtualBox download page

				
					wget https://download.virtualbox.org/virtualbox/7.0.6/virtualbox-7.0_7.0.6-155176~Ubuntu~jammy_amd64.deb
				
			

apt and apt-get Command

Certainly, apt and apt-get command helps you manage packages (software applications) installed on your Ubuntu PC. Concurrently, it simplifies the process of installing, removing, and updating packages.

As an illustration, the syntax for apt command is: 

Installing a package: 

				
					sudo apt install package_name
				
			

Removing a package: 

				
					sudo apt remove package_name
				
			

Updating a package: 

				
					sudo apt update
				
			

Upgrading a package: 

				
					sudo apt update
				
			

apt-get is a sub-command of apt. It comes in handy when you want to download and install packages from repositories. Certainly, use apt-get to perform other package-related operations such as upgrading packages, removing packages, and cleaning up the package cache.

As a result, see the syntax, that is similar to the apt command. 

Example: Here’s how to install VLC using the apt command. 

				
					sudo apt install vlc
				
			

ping Command

Equally, there is a ping command. Especially useful with verifying network connectivity between your system and other network devices. By all means, use the command to resolve the IP address of a URL or hostname.

Check out the syntax of the ping command below:

				
					ping [options] host-name/IP
				
			

Example: Let’s ping the Youtube.com website to see how this command works. 

				
					ping youtube.com
				
			

Basic Ubuntu Terminal Shortcuts

Now that you have the basic Ubuntu commands at your fingertips, it’s time to check out some time saving terminal shortcuts. These shortcuts make working with the Ubuntu terminal quicker and more efficient. 

Shortcut What it Does
Ctrl + Alt + T
Opens a new Terminal window.
Ctrl + Shift + T
Opens a new tab in the terminal.
Ctrl + L
Clears the terminal window.
Ctrl + C
Stops the command that's currently running.
Ctrl + D
Exits the current shell
Tab
Auto-completes file and folder names
Up arrow
Gives you access to previous commands.
Ctrl + R
Allows you to search through the command history.
Ctrl + A
Moves the cursor to the beginning of the command line
Ctrl + E
Moves the cursor to the end of the command line.
Ctrl + U
Clears the command line before the cursor.
Ctrl + K
Clears the command line after the cursor.
Ctrl + W
Deletes the word before the cursor.
Ctrl + Y
Pastes the last thing deleted with Ctrl + U or Ctrl + K.

Thank you for reading Basic Ubuntu Commands And Terminal Shortcuts (Cheat Sheet). It is time to conclude the article.

Basic Ubuntu Commands And Terminal Shortcuts Conclusion

When it comes to mastering basic Ubuntu commands and terminal shortcuts, nothing is more important than practice. By immersing yourself in the world of Ubuntu, you’ll gain a deep understanding of how the operating system works, allowing you to perform tasks with ease and troubleshoot any issues that arise. This cheat sheet, allows you to become a power user.

Avatar for Richard Kanyoro
Richard Kanyoro

The world’s biggest problems can be solved by progressively solving the little ones. I write to help people solve the “little” tech problems they face.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x