Level Up Linux: 20 Must-Know Commands for Newbies

Introduction

Level Up Linux: 20 Must-Know Commands for Newbies


So, are you planning to switch from Windows to Linux or have you recently made the switch to Linux? Oops! What am I asking? Why else would you be here?

In my earlier experience as a newcomer, Linux commands and terminals were quite intimidating. I had concerns about the commands and wondered to what extent I needed to remember and memorize them to become proficient and fully functional with Linux.

Undoubtedly, online documentation, Linux books, man pages, and the user community provided significant assistance.

However, I strongly believe that there should be an article featuring basic Linux commands in easy-to-learn and understood language.

These motivations inspired me to master Linux and make it more user-friendly. This article is a step towards that goal.”

1. ls Command

The command ‘ls‘ stands for ‘List Directory Contents‘, which is used to display the contents of the folder, whether they are files or subfolders, from which the command is executed.

ls

The ‘ls -l‘ command lists the contents of the folder in a detailed, long listing format.

ls -l

The ‘ls -a‘ command lists the contents of a folder, including hidden files that start with '.'.

ls -a

In Linux, a file name starting with '.' is considered hidden. In Linux, every file, folder, device, or command is treated as a file.

Listing Files in Linux
Listing Files in Linux

The result of the ls -l command is:

  • File Type – The first character represents the file type ('-' for a regular file, 'd' for a directory, 'l' for a symbolic link, etc.).
  • Permissions – The next nine characters represent the file’s permissions for the owner, group, and others. These characters can include 'r' for read, 'w' for write, and 'x' for execute permissions.
  • Number of Links – Indicates the number of hard links pointing to the file or directory.
  • Owner and Group – Specifies the user (owner) and group associated with the file or directory.
  • File Size – Shows the size of the file in bytes.
  • Modification Time – Displays the date and time when the file or directory was last modified.
  • File or Directory Name – The actual name of the file or directory.

For more “ls” command examples read our series of articles:

2. lsblk Command

The ‘lsblk‘ command, short for ‘List Block Devices,’ displays block devices by their assigned names (excluding RAM) in a tree-like format on the standard output.

lsblk

The ‘lsblk -l‘ command lists block devices in a ‘list‘ structure rather than a tree-like fashion.

lsblk -l
List Block Devices
List Block Devices

lsblk is a very useful and easy way to identify the name of the new USB device you just plugged in, especially when you have to work with disks or blocks in the terminal.

3. md5sum Command

The ‘md5sum‘ stands for ‘Compute and Check MD5 Message-Digest‘. MD5 checksum (commonly referred to as a ‘hash‘) is used to match or verify the integrity of files that may have changed due to a faulty file transfer, disk error, or non-malicious interference.

md5sum teamviewer_linux.deb 

47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

The user can compare the generated md5sum with the one provided officially. MD5sum is considered less secure than sha1sum, which we will discuss later.

4. dd Command

The dd command stands for ‘Convert and Copy a file‘ and can be utilized to convert and copy a file. Most often, it is used to copy an ISO file (or any other file) to a USB device (or another location), making it suitable for creating a bootable USB stick.

dd if=debian.iso of=/dev/sdb1 bs=512M; sync
Note: In the above example the usb device is supposed to be sdb1 (You should verify it using the command lsblk, otherwise you will overwrite your disk and OS), use the name of the disk very cautiously!

The dd command takes some time ranging from a few seconds to several minutes in execution, depending on the size and type of file and read and write speed of the Usb stick.

5. uname Command

The uname command stands for (Unix Name), and prints detailed information about the machine name, operating system, and kernel version.

uname -a

Linux Jassweb 6.2.0-39-generic #40~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC 
Thu Nov 16 10:53:04 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

The result of the uname -a command is:

  • Linux“: The machine’s kernel name.
  • tecmint“: The machine’s node name.
  • 6.2.0-39-generic“: The kernel release.
  • 22.04.1-Ubuntu SMP“: The operating system release version.
  • x86_64“: The architecture of the processor.
  • GNU/Linux“: The operating system name.

6. history Command

The history command stands for History (Event) Record, it prints the history of a long list of executed commands in the terminal.

history
List Previously Executed Commands
List Previously Executed Commands

Note: Pressing 'Ctrl + R' allows you to search for previously executed commands, enabling your command to be completed using the auto-completion feature.

(reverse-i-search)`if': ifconfig

For more examples of history commands, please refer to our series of articles:

7. sudo Command

The “sudo” (superuser do) command allows a permitted user to execute a command as the superuser or another user, as specified by the security policy in the sudoers list.

sudo apt update

Note: sudo allows users to borrow superuser privileges, while a similar command ‘su‘ allows users to log in as superusers. Sudo is safer than su.

It is not advised to use sudo or su for day-to-day normal use, as it can result in serious errors if accidentally you do something wrong, that’s why a very popular saying in the Linux community is:

“To err is human, but to really foul up everything, you need a root password.”

For more examples of sudo commands, please refer to our series of articles:

8. mkdir Command

The (make directory) creates a new directory with a name path. However is the directory already exists, it will return an error message “cannot create a folder, folder already exists”.

The mkdir command (make directory) is used to create a new directory with a specified path. However, if the directory already exists, it will return an error message stating, ‘cannot create a folder, folder already exists‘.

mkdir tecmint

Directories can only be created within folders for which the user has write permissions.

9. touch Command

The touch command stands for ‘update the access and modification times of each FILE to the current time.’ The ‘touch‘ command creates the file only if it doesn’t exist. If the file already exists, it will update the timestamp but not the contents of the file.

touch tecmintfile

The `touch` command can be used to create a file in a directory for which the user has written permission, only if the file doesn’t already exist there.

10. chmod Command

The “chmod” command stands for “change file mode bits,” which alters the file mode (permissions) of each specified file, folder, script, etc., according to the specified mode.

There exist 3 types of permission on a file (folder or anything but to keep things simple we will be using file).

Read (r)=4
Write(w)=2
Execute(x)=1

So if you want to give only read permission on a file it will be assigned a value of ‘4‘, for write permission only, a value of ‘2‘ and for execute permission only, a value of ‘1‘ is to be given. For read and write permission 4+2 = ‘6‘ is to be given, and so on.

Now, permission needs to be set for 3 kinds of users and user groups. The first is the owner, then the user group, and finally the world.

rwxr-x--x   abc.sh

Here the root’s permission is rwx (read, write, and execute). usergroup to which it belongs is r-x (read and execute only, no write permission) and for the world is –x (only execute).

To change its permission and provide read, write, and execute permission to the owner, group, and world.

chmod 777 abc.sh

only read and write permission to all three.

chmod 666 abc.sh

The read, write, and execute to the owner and only execute to group and world.

chmod 711 abc.sh

chmod is one of the most crucial commands that proves beneficial for both system administrators and users. In a multi-user environment or on a server, this command is indispensable, as incorrectly setting permissions can render a file inaccessible or grant unauthorized access to individuals.

11. chown Command

The chown command stands for “change file owner and group“, which is used to change the owner and/or group of a file or directory.

Below is an example of how the chown command is typically used.

chown newowner:newgroup filename

For instance, if you want to change the owner of a file named “example.txt” to a user named “tecmint” and a group named “users“, the command would be:

chown tecmint:users example.txt

12. apt Command

On Debian-based distributions such as Ubuntu and Linux Mint, the apt command stands for (Advanced Package Tool), which is used to install, upgrade, and manage software packages on a system from the command line.

sudo apt search wget
sudo apt install wget
sudo apt update

The apt command is considered more advanced and intelligent as compared to yum or dnf command.

13. tar Command

The tar command is a Tape Archive that is useful in the creation of an archive, in several file format and their extraction.

tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: A ‘tar.gz‘ means gzipped. ‘tar.bz2‘ is compressed with bzip which uses a better but slower compression method.

14. cal Command

The “cal” (Calendar), is used to display the calendar of the present month or any other month of any year that is advancing or passed.

cal 

Show the calendar of the year 1835 for February, which already has passed.

cal 02 1835

Shows the calendar of the year 2145 for July, which will be advancing

cal 07 2145
Show Calendar in Linux
Show Calendar in Linux

Note: You don’t need to turn the calendar back by 50 years, nor do you need to perform complex mathematical calculations to determine the day you were born or the day your upcoming birthday will fall on.

15. date Command

The date command is used to display the current date and time. It can also be used to set the system date and time.

To display the current date and time.

date

To display the current date in the format “YYYY-MM-DD“.

date +"%Y-%m-%d"

To set system date and time.

sudo date MMDDhhmm[[CC]YY][.ss]

The above command allows you to set the system date and time. Replace MM, DD, hh, mm, CC, YY, and ss with the desired values for month, day, hour, minute, century, year, and second, respectively.

Note: The date command is highly useful in scripting, especially for time and date-based operations. Moreover, changing the date and time using the terminal can make you feel like a true GEEK! (Of course, you need to have root permissions to perform this operation, as it involves a system-wide change).

16. cat Command

The cat command stands for (Concatenation), which means (join) two or more plain files and/or print contents of a file on standard output.

To display the contents of a file.

cat filename

To concatenate multiple files means the following command concatenates the contents of file1 and file2 and displays the result in the terminal.

cat file1 file2

The content of a.txt, b.txt, c.txt, and d.txt will be combined and appended to the end of the abcd.txt file.

cat a.txt b.txt c.txt d.txt >> abcd.txt

cat abcd.txt

Note: The “>>” and “>” are called append symbols. They are used to append the output to a file and not to standard output.

The “>” symbol will delete a file that already existed and create a new file hence for security reasons it is advised to use “>>” that will write the output without overwriting or deleting the file.

Before proceeding further, I must let you know about wildcards (you would be aware of wildcard entries, in most of Television shows) Wildcards are a shell feature that makes the command line much more powerful than any GUI file manager.

You see, if you want to select a big group of files in a graphical file manager, you usually have to select them with your mouse. This may seem simple, but in some cases, it can be very frustrating.

For example, suppose you have a directory with a huge amount of all kinds of files and subdirectories, and you decide to move all the HTML files, that have the word “Linux” somewhere in the middle of their names, from that big directory into another directory.

What’s a simple way to do this? If the directory contains a huge amount of differently named HTML files, your task is everything but simple!

In the Linux command line that task is just as simple to perform as moving only one HTML file, and it’s so easy because of the shell wildcards. These are special characters that allow you to select file names that match certain patterns of characters.

This helps you to select even a big group of files by typing just a few characters, and in most cases, it’s easier than selecting the files with a mouse.

Here’s a list of the most commonly used wildcards :

Wildcard			Matches
   *			zero or more characters
   ?			exactly one character
[abcde]			exactly one character listed
 [a-e]			exactly one character in the given range
[!abcde]		any character that is not listed
 [!a-e]			any character that is not in the given range
{debian,linux}		exactly one entire word in the options given

The ! is called not a symbol, and the reverse of the string attached with '!' is true.

17. cp Command

The cp command stands for (copy), it copies a file from one location to another location.

cp /home/user/Downloads abc.tar.gz /home/user/Desktop

Note: The cp is one of the most commonly used commands in shell scripting and it can be used with wildcard characters (describe in the above block), for customized and desired file copying.

18. mv Command

The mv command moves a file from one location to another location.

mv /home/user/Downloads abc.tar.gz /home/user/Desktop

Note: The mv command can be used with wildcard characters. mv should be used with caution, as moving of system/unauthorized files may lead to security as well as a breakdown of the system.

19. pwd Command

The pwd command (print working directory), prints the current working directory with the full pathname from the terminal.

pwd 

/home/user/Desktop

Note: The pwd command won’t be frequently used in scripting but it is an absolute lifesaver for a newbie who gets lost in the terminal in their early connection with Linux. (Linux is most commonly referred to as nux or nix).

20. cd Command

Finally, the frequently used cd command stands for (change directory), which changes the working directory to execute, copy, move write, read, etc. from the terminal itself.

cd /home/user/Desktop
pwd

/home/user/Desktop

Note: The cd command comes to the rescue when switching between directories from the terminal. The "cd ~" will change the working directory to the user’s home directory, which is very useful if a user finds themselves lost in the terminal. The "cd .." will change the working directory to the parent directory of the current working directory.

Conclusion

These commands will undoubtedly enhance your comfort with Linux. However, this is not the conclusion. Soon, I will introduce additional commands that will prove valuable for ‘Middle-Level Users‘. You will observe a promotion in your user-level status, progressing from a newbie to a middle-level user.

In the next article, I will be coming up with commands like ‘Kill‘, ‘ps‘, and ‘grep‘.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?