Beginner’s Guide to Fundamental Linux Commands

Joshua Adeyemi
9 min readJun 12, 2024

--

This blog post is designed for beginners new to Linux who want to understand the basics of using the Linux terminal. It provides an introduction to the terminal, explains how to access it, and covers essential commands for tasks like navigating the file system, managing files and directories, operating on text files, handling user management, and networking.

Why Linux?

Linux is an open-source operating system that can be installed on various types of hardware, enabling you to develop software, run applications, and more. The core component of Linux is the kernel. Today, Linux is the most installed operating system globally. Linux is usually managed through a command line interface (CLI), also referred to as a shell.

In cloud engineering, Linux is vital due to its stability, security, and flexibility. It is extensively used for server management, containerization (Docker), orchestration (Kubernetes), and automation through scripting.

Linux Distribution

Today, most people obtain Linux by downloading one of the numerous available distributions. A Linux distribution combines a specific version of the Linux kernel with various libraries, system daemons, development tools, applications, and life-cycle management tools that are compatible and tested for interoperability.

These distributions are available not only for servers, desktops, and laptops but also for a wide range of specialized devices running Linux. Examples include Ubuntu, Debian, Fedora, Centos and openSUSE

Navigating the Linux Directory Structure

Ubuntu Linux organizes its folder structure according to the Filesystem Hierarchy Standard (FHS), which defines how files and directories are arranged in Unix-like operating systems. Below is a summary of the key directories you will commonly find in Ubuntu:

1. /bin: Stores crucial command-line executable files (binaries) that are available for all users to access.

2. /boot: Contains crucial files for the boot process, including the Linux kernel, initial ram-disk (initrd), and bootloader settings.

3. /dev: Contains device files that represent and provide access to the system’s various hardware devices.

4. /etc: Stores configuration files that manage settings for various system-wide applications.

5. /home: Hosts the home directories for each user, with individual subdirectories for personal files and settings.

6. /opt: Houses optional software packages installed on the system, often with applications contained within their own directories for self-containment.

7. /proc: A virtual filesystem that supplies data on processes and system status, serving as a valuable resource for various system utilities to access real-time information.

8. /root: The home directory exclusively designated for the root user, who possesses administrative superuser privileges.

9. /sbin: Houses system binaries, executable files primarily employed by the root user for system administration purposes.

10. /tmp: A directory designated for temporary files generated by applications and users, typically emptied upon each system reboot.

11. /usr: Stores programs, libraries, documentation, and shared resources relevant to users. It encompasses subdirectories like /usr/bin for user binaries, /usr/lib for libraries, and /usr/share for shared data.

12. /var: Holds dynamic data that fluctuates during the system’s runtime, including logs, databases, and spool files.

Essential Linux Commands for Beginners

— pwd : When you initially open the terminal, you start in your user’s home directory. To determine your current directory, use the “pwd” command. This command provides the absolute path, starting from the home directory.

— cd: To navigate between directories in the terminal, use the “cd” (change directory) command. For instance, to switch to the /etc directory, which houses configuration files, you would use the “cd” command like this:

— ls: To see the contents of a directory (the files and subdirectories), we can use the ls (list) command. This command lists both the files and directories contained in the directory.

— rm: To delete files, use the “rm” command. To remove a directory, use “rm -r”. This option deletes both the directory and its contents as you see below. Without the “-r” option, “rm” only deletes individual files.

— mkdir & rmdir: To create a new folder or directory, use the “mkdir” (Make Directory) command. For instance, to create a directory named “myfolder,” you would type “mkdir myfolder”. To remove a directory, use the “rmdir” (Remove Directory) command. However, note that “rmdir” can only delete an empty directory as shown in the image below.

— touch : The “touch” command is used to create a file. This file can be of any type, such as an empty text file or an empty zip file. For example, you can create a file named “mydata.txt” by typing “touch mydata.txt”.

— cp : To copy files via the command line, use the “cp” command. It requires two arguments: the first specifies the file’s location to be copied, and the second indicates the destination where the file should be copied. Here is an example:

— mv: To move files using the command line, use the “mv” command. This command can also be used to rename files. For example, to rename the file “username.txt” to “users.txt,” you would use “mv username.txt users.txt”.

— cat: To view the contents of a file, use the “cat” command. This is especially handy for quickly accessing the content of programs and text files, as illustrated in the image.

— nano: The “nano” command is a user-friendly text editor that highlights keywords with color and supports syntax recognition for most programming languages. To open a file with “nano,” type nano hold.txt, Press Ctrl + O You’ll be prompted to confirm the file name. Press Enter to save with the current name. Press Ctrl + X to exit the editor.

— man: Use the “man” command (short for “manual”) to access detailed documentation on almost every Linux command. For example:

— hostnamectl: The “hostnamectl” command displays the hostname of the Linux server along with other system information, such as the machine ID, virtualization hypervisor (if applicable), operating system, and Kernel version. For example:

— echo: The “echo” command in Linux is used to display a line of text or string on the standard output, typically the terminal window. It’s one of the most basic and frequently used commands in shell scripting and the command-line interface. Here’s how it works:

— df: To check the available disk space in each partition of your system, use the “df” command. Simply type “df” in the command line to view each mounted partition along with their used and available space, both in percentage and kilobytes.

— ps : The ps command displays a list of running processes in Linux. This command is often coupled with the -ef flag to show every process in the long list format shown below. You’ll see right at the top that “/sbin/init” is PID (process identifier) #1, and it’s owned by root.

— sudo: The “sudo” command, short for “SuperUser Do,” is widely used in the Linux command line to execute commands with administrative or root privileges. For example, to read a file called “shadow,” which requires root permissions, you can use: `sudo nano /etc/shadow`. Here’s how it works:

— head: To view the beginning of a file, use the “head” command. By default, this command displays the first 10 lines of the file. For example, the following command shows the first 10 lines of “dhclient.conf”:

— tail: The “tail” command is similar to the “head” command, but it displays the last lines of a file. For example, you can use it on “dhclient.conf” to view its ending lines.

This command showcases some of the final include lines from the rules files, but not all, as the default behavior of “tail” is to display 10 lines, similar to “head”.

— grep: The “grep” command is extensively utilized for text manipulation, allowing you to filter the content of a file for specific display. For example, if you wish to view all lines containing the word “output” in your “dhclient.conf” file, you can use “grep” to accomplish this task efficiently.

This command will initially display the contents of “dhclient.conf” and then utilize a pipe (|) to transmit it to “grep”. Subsequently, “grep” will take the file as input, scan for lines containing the word “output”, and exhibit only those lines. “grep” is an extremely potent and indispensable command in Linux, as it can significantly expedite the process of locating every instance of a word or command within a file, potentially saving hours of manual searching.

— gzip: The gzip command is used to compress files. When you gzip a file, it replaces the original file with a compressed version that ends with the “.gz” extension. For example, running gzip file1.txt will compress "file1.txt" and replace it with "file1.txt.gz".

— bzip2: Bzip2 is a command-line tool and file compression utility in Linux. It is used to compress and decompress files, similar to gzip but with different compression algorithms. To compress a file using bzip2, you would use the command bzip2 file1.txt. This will replace the original file with a compressed version ending in the ".bz2" extension.

— chmod: The chmod command in Linux stands for "change mode" and is used to change the permissions of files and directories. These permissions determine who can read, write, and execute a file or directory. To delve deeper into file permissions, feel free to explore this resource.

Linux networking commands

— ifconfig: The “ifconfig” command serves various purposes, including presenting current network configuration details, configuring IP addresses, netmasks, or broadcast addresses for network interfaces, establishing aliases for network interfaces, setting up hardware addresses, and enabling or disabling network interfaces.

— ping: Ping, short for Packet Internet or Inter-Network Groper, is a utility in computer network administration used to assess the accessibility of a host on an Internet Protocol (IP) network. In simpler terms, when you type “ping google.com” for instance, it tests if your device can establish a connection with the server and return. For everyday users, the primary use of this command is to verify their internet connection.

— ip addr show: “Ip addr show” displays extensive information on all network interfaces (active and inactive) on a system, including IP addresses, MAC addresses, network masks, and interface statuses. This command is valuable for diagnosing network problems and examining network interface configurations on a Linux system.

— dig: The “dig” command, short for Domain Information Groper, performs detailed DNS lookups and is excellent for troubleshooting DNS issues.

— traceroute: Traceroute examines the network path from the local system to a specified destination, collecting data on each IP router along the route. The traceroute command is particularly useful for diagnosing network issues, such as identifying a downed host or a slow response from an intermediary node, and pinpointing which node is causing the problem. For example:

I trust this blog will be beneficial. There’s no need to memorize these commands. Linux demands consistent practice, particularly for beginners. Experiment with new commands, conduct research, and practice regularly. In no time, you’ll gain proficiency in creating, administering, and enhancing virtualized environments effortlessly.

Connect with me on:

--

--

Joshua Adeyemi

I am a DevOps enthusiast specializing in automation and enhancing the efficiency of the build, test, and deployment phases.