When I was introduced to Linux, I had a pretty hard time getting used to and learning Linux commands. There’s no secret to learning Linux in a day or two easily but to practice, fail, stand up and practice again, and learn from your mistakes. The easiest way to learn Linux is not to abandon it if you don’t understand how it works. In this article, let’s look at some of the basic Linux commands for beginners.
This list of Linux terminal commands contains all the common commands. Think of it as a Linux command cheat sheet as it contains almost all the basic ones to get you started.
Basic Linux Commands: Linux For Beginners
The name says it all. The mkdir command in Linux is used to create a new directory or, if you’re coming from Windows, a Folder.
mkdir folder name
Where “folder name” is the name of the folder you want to create.
Echo is the simplest command in Linux. It is used to display text that is passed after the space in the command.
[email protected]:~$ echo fossbytes fossbytes
The echo command might seem useless, but it is used in debugging code and determining the program’s state. If you know a little bit of programming, think of it as a print statement that only outputs a string.
Python3 print("fossbytes") >> fossbytes
PWD stands for Print Working Directory. This gives us a quick way of finding out the working directory path.
[email protected]:~$ pwd /home/focusblast
Cd is an acronym for the change directory. As the name suggests, it is used to temporarily change the directory you’re working in.
[email protected]:~$ cd /Desktop [email protected]:~/Desktop$
The command cp is used to copy and paste a file to a directory specified as the second argument.
[email protected]:~/Desktop$ cp new.txt /home/focusblast/Downloads
In the above command, “new.txt” is the file that we copy to the directory “/home/focusblast/Downloads.”
The mv command in Linux stands for “Move.” It is used to move files or directories from one place to another. Consider a file “move.” To move it to the Downloads folder, all we need to do is:
[email protected]:~/Desktop$ mv move /home/focusblast/Downloads
The manual page (man) command is like software documentation using which you can know what a particular command does and how it works:
[email protected]:~$ man cp CP(1) User Commands CP(1) NAME cp - copy files and directories SYNOPSIS cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... DESCRIPTION Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY. Mandatory arguments to long options are mandatory for short options too. -a, --archive same as -dR --preserve=all --attributes-only don't copy the file data, just the attributes --backup[=CONTROL] Manual page cp(1) line 1 (press h for help or q to quit)
The ls command is used for listing the contents of a directory.
[email protected]:~$ ls Downloads Public Documents snap Templates Videos Music Pictures VMs
The cat command is used to print or merge the content from the line where the first file ends.
[email protected]:~$ cat file1
The command to merge two files and create a new file or merge them in any two files would be.
cat file1 file2 > file3 #This will merge files in file 1 and file 2 in a new file
Now, the cat command has a lot of commands that we couldn’t fit in this article. You can use the command “man cat” to learn more about it.
The rm command is used to remove files and directories. You’ll need both rm and -r (recursive) to remove a directory.
rm new2.txt #removes the file sudo rm -rf directory #removes the directory
The f in “-rf” is used to tell rm to ignore files and arguments that don’t exist.
Zip is used to create a new zip file, whereas Unzip is used to unzip zipped files. Here’s how you you Zip and Unzip commands.
[email protected]:~$ zip newzipfile.zip file1.txt file2.txt
In the above command, newzipfile.zip is the name of the zipped file in which we’re going to put the two text files file1.txt and file2.txt.
To extract all the files from a zipped file using the command.
[email protected]:~$ unzip newzipfile.zip
Replace “newzipfile” with the name of the zipped file you want to extract.
wget is a handy command that can help you download files from the internet. Here’s how to use it:
wget "download link"
Similar to Windows Task Manager, top command shows you the list of running processes and how much CPU is being used.
[email protected]:~$ top
The history command is used to display the commands that you’ve typed before.
[email protected]:~$ history
The wc command is used to count the number of lines (-l), words (-w), bytes (-c), and characters (m).
[email protected]:~$ wc -l filename.txt 33 filename.txt
As the name suggests, clear is used to clear the terminal screen.
[email protected]:~$ clear
You guessed it right! The passwd command is used to change the password of the user account. To use it, type passwd followed by the username.
[email protected]:~$ passwd focusblast
The chown command is used to transfer the ownership of files. Let’s assume there’s a file named file1 and you’re user0. You want to transfer the ownership to user1.
[email protected]:~$ chown user1 file1.txt
You can also transfer the ownership to root using the command.
sudo chown root file1.txt
Apt stands for Advanced Packaging Tool. It is one of the most popular and powerful package managers for Ubuntu/Debian. For starters, a package manager essentially automates the process of installing and removing applications.
The following command installs the flameshot application, which is one of the most popular screenshot tools on Linux.
sudo apt install flameshot
The name says it all. Reboot command is used to reboot, shut down, or halt the system.
The chmod command is used to change the read (-r), write (-w), and execute (-x) instructions of a file. An example of chmod command would be:
chmod 742 program.sh
Here’s what the numbers mean.
|3||Write and Execute||-wx|
|5||Read and Execute||r-x|
|6||Read and Write||rw-|
|7||Read, Write, and Execute||rwx|
The first number (7) in the above command represents the permissions that you’re giving to the user i.e. Read, Write, and Execute.
The second digit (4) is the permissions given to the file itself, which, in this case, is “Read Permissions only.”
The third and final digit (2) represents the permissions given to everyone who’s not a part of the group.
The grep command is used to search and find text in a file.
grep "fossbytes" text.save
Similar to the search command in Windows, the locate command is used to locate files in Linux.
$ locate text.save /home/focusblast/Desktop/text.save
The only command of all that you’ll end up using the most. The acronym for Sudo is SuperUser Do, using which you can fiddle with the files that require root permissions.
Mind you, if a file needs root privileges, it’s probably important to the OS. Hence, we suggest not to play around if you don’t know what you’re doing.
The hostname command is used to know your device name. Additionally, using the -I argument will help you know your IP address.
$ hostname pop-os $ hostname -I 220.127.116.11
The exit command can be used to close the terminal quickly.
Suppose you want to know the space in every disk partition, type df. The default space metric is Kilobytes but, you can use the argument “-m” to change it to Megabytes.
$ df -m
The netstat command can be used to check the network statistics, interface statistics, routing table information, and much more.
The fdisk command will list all the partitions and the information like the partition name, sectors, size, and partition types. fdisk needs superuser permissions to run.
$ sudo fdisk -l
Nano is my favorite text editor in Linux. If you want to open up a text file, you can type “nano” followed by the “filename” if you’re in the directory where the file is present to open it up.
When you’re done editing the text file, press the key combination “Ctrl+O” to write the changes and “Ctrl+X” to exit. To learn more about Nano, you can also go to the help section by pressing “Ctrl+G.”
Bonus Command For Fun
You can install sl using apt, and a train will appear whenever you type sl instead of the ls (list directory) command that we talked about earlier.
sudo apt install sl
The above commands are just the tip of the proverbial iceberg. There’s a lot more to Linux than what meets the eye. To acquire in-depth knowledge of Linux and make a career out of it, we suggest reading this free book.