Linux is a free and open-source operating system that has several distributions such as Debian, Ubuntu, Fedora, etc. Linux is free, efficient, and provides better security features.

Quick Answer

Use pwd to see your current directory, ls to list files, mkdir to create folders, touch to create files, cat to read files, and sudo for admin commands. For disk usage, use df -m and du.

Command Reference

Here is a quick reference for all commands covered in this guide:

Command What It Does
pwd Shows the current working directory path
ls Lists files in the current directory
ls -a Lists all files including hidden ones
mkdir Creates a new directory
rmdir Removes an empty directory
rm -r Removes a directory and all its contents
touch Creates an empty file
man Shows the manual page for a command
mv Renames or moves a file
locate Finds the path of a file by name
echo Writes text into a file or prints to terminal
cat Prints file contents to the terminal
nano Opens a terminal text editor
sudo Runs a command as superuser (admin)
df -m Shows available disk space in megabytes
du Shows disk usage in a directory
zip Compresses files into a .zip archive
unzip Extracts a .zip archive
uname -a Prints system and kernel information
hostname -i Displays the hostname and IP address
apt-get install Installs a package from the repository

Basic Commands in Linux

Some of the basic commands in Linux are listed below:

Basic Command 1: pwd

The pwd command tells us about the directory we are present in. It provides us complete path to the directory which means the path that starts from the root.

In our case, the user directory is /home/linuxuser.

Terminal output of pwd command showing /home/linuxuser on Linux

Basic Command 2: ls

This command displays all the files in the directory that we are currently present in.

Terminal output of ls command listing files in directory on Linux

Basic Command 3: ls -a

This command prints all the hidden files in the system.

Terminal output of ls -a command showing hidden files on Linux

Basic Command 4: mkdir

To create a new folder or directory in the system, use the mkdir command. For instance,

Let’s create a folder named “Ubuntu1”. Type the mkdir command along with the folder name in the terminal as shown below:

Terminal output of mkdir Ubuntu1 creating a new directory on Linux

To verify the creation of your folder, go to files and you will see the folder present there.

File manager showing the newly created Ubuntu1 folder on Linux

Basic Command 5: rmdir

To delete a folder or directory, use the rmdir command.

Terminal output of rmdir Ubuntu1 removing an empty directory on Linux

Note: This command is only used to delete empty directories.

It can be seen that the folder is deleted successfully.

File manager showing Ubuntu1 folder removed successfully on Linux

Basic Command 6: rm -r

This command is used to delete the folders and directories and all the files present within them.

For instance, let’s delete the uni_files folder in our system.

File manager showing uni_files folder before rm -r deletion on Linux
Terminal output of rm -r uni_files deleting directory and contents on Linux

It can be seen that the folder is deleted successfully.

File manager showing uni_files folder removed successfully on Linux

Basic Command 7: touch

To create an empty text file, the most commonly used command is the touch command. For instance, let’s create a new text file named new.txt.

Terminal output of touch new.txt creating an empty text file on Linux

By looking at the snapshot below, we can see that the new text file is created successfully.

File manager showing new.txt file created successfully on Linux

Basic Command 8: man

This command tells us about the details of any command and how to use it as well.

For instance, let’s find out some details about the pwd command.

Terminal output of man pwd command on Linux

It can be seen that the details are displayed successfully.

Terminal showing man page for pwd command on Linux

Basic Command 9: mv

To rename a file through the command line, use the mv command.

For instance, let’s rename a file new.txt to file1.txt.

File manager showing new.txt file before rename with mv command on Linux
Terminal output of mv new.txt file1.txt renaming file on Linux

It can be seen that the file name is changed successfully.

File manager showing file renamed to file1.txt with mv command on Linux

Basic Command 10: locate

To locate or find any file in a Linux system, use the locate command. When you are unsure of the location or name of a file, this command can be helpful.

For instance, let’s locate our newly created file.txt in our Linux system.

Terminal output of locate command showing file path on Linux

It can be seen that the path of the file is displayed successfully.

Intermediate Commands

Some of the intermediate commands in Linux are listed below:

Intermediate Command 1: echo

The echo command is used to move data, usually text into a file. It can also be used to create a new file.

For example, let’s move some data into a file.

Terminal output of echo writing Welcome to Ubuntu into new.txt on Linux

It can be seen that the text “Welcome to Ubuntu” is successfully added to the new.txt file.

File manager showing new.txt with Welcome to Ubuntu content on Linux

Intermediate Command 2: cat

This command prints the contents of a file.

For example, let’s see the contents inside a file in our Linux system.

Terminal output of cat new.txt displaying file contents on Linux

It can be seen that the content inside the new.txt file is displayed successfully.

Intermediate Command 3: nano

nano is a text editor that comes pre-installed in many linux distros. It can recognize most of the languages and denotes keywords with colors. It can be used to create and modify files.

For instance, let’s create a file named Ubuntu1 using nano editor.

nano editor with Ubuntu1 file open on Linux

Press CTRL+S to save the file. CTRL+X to leave the editor.

Intermediate Command 4: sudo

Sudo means “SuperUser Do”. sudo command performs administrative and root privileges.

For instance, let’s change the password of our Linux system using sudo.

Terminal output of sudo passwd updating password on Linux

It can be seen that the password is updated successfully.

Intermediate Command 5: df

This command is used to display the available disk space in each of the partitions in your system. Use the df -m command to display it in megabytes.

Terminal output of df -m showing disk space in megabytes on Linux

It can be seen that the available disk on our system is displayed successfully.

Intermediate Command 6: du

This command tells us about the disk usage in a specific directory.

For instance, let’s see the disk usage in our Downloads folder.

Terminal output of du showing disk usage in Downloads folder on Linux

The disk usage is displayed successfully.

Intermediate Command 7: zip and unzip

Use the zip command to zip a file or multiple files in your system. Unzip is used to extract the zipped archive.

Let’s zip some files in our Linux system.

Terminal output of zip command creating archive on Linux

Now to extract these zip files, use the unzip command.

Terminal output of unzip command extracting archive on Linux

It can be seen that the zip files are extracted successfully.

Intermediate Command 8: uname

This command displays information about the linux distro your system is running on. uname -a command prints most of the information about the system.

Terminal output of uname -a showing system information on Linux

The information is displayed successfully.

Intermediate Command 9: hostname

This command prints your name in the host or network. hostname -i displays the IP address of the network.

Terminal output of hostname -i showing hostname and IP address on Linux

The hostname and IP address are printed successfully.

Intermediate Command 10: apt-get

Use the apt-get command to install packages in your Linux system.

For instance, let’s install a new text editor jed using apt-get.

Terminal output of sudo apt-get install jed showing package install on Linux
Terminal showing jed text editor installed successfully on Linux

The text editor has been installed successfully.

Related Linux guides