DEV Community

Cover image for Understanding Linux and Its Commands
Amarachi Iheanacho
Amarachi Iheanacho

Posted on

Understanding Linux and Its Commands

Operating systems are the core of daily applications, managing the communication between the hardware and software. Operating systems include Windows, iOS, Mac OS, and Linux.

This article will discuss what the Linux operating system is, why anybody should be interested in the Linux operating system, and, more importantly, basic commands we can run with Linux.

What is Linux?

Linux is an entire family of open-source Unix operating systems based on the Linux Kernel. The Linux kernel was created to work with various hardware, from phones and computers to cars. It manages the hardware resources and software packages.

Prerequisites

To get started with this article, we must have the following:

  • A Command line interface (CLI) is installed on the computer. For Windows users, it is advisable to use GIT Bash to run the commands. To download GIT Bash, check out this page
  • An IDE, download the Visual Studio code IDE here

Why Linux?

Understanding that there are other operating systems, Linux, in particular, has been gaining popularity in recent years because of the following reasons:

  • The Linux operating system is open-source. Open-source infers that the software is available to the public for studying, modification and distribution.
  • Many people use the Linux operating system, so we can easily leverage this community support and outsource solutions to our problems.
  • Linux supports a wide range of hardware like phones, laptops, servers, etc.
  • Linux effectively automates processes. ## Basic Linux Commands

This article section will discuss some of the CLI commands available to us with Linux. Open up our Git Bash CLI and run the following commands.

  • pwd: This command tells us the path of the directory we are currently in.
    Linux Command

  • ls:: Use this command to list all the files and directories in our current directory.
    Linux Command

  • mkdir: Use the Linux command to create a new directory or folder. We run this command to create a folder or directory named linux_practice.
    Linux Command

In the image above, we create a directory and list all the files and directories with the ls command.

  • cd : Use this command to navigate through different directories. This cd command requires the absolute or relative path of the directory we want to change to. Linux Command

In the screenshot above, we can see that our current directory has changed to linux_practice.

We can use some shortcuts to navigate through directories using the cd command. The shortcuts are listed below:

- The `cd` or `cd ~` command will navigate the user to their home directory.
- The `cd ..` command will move the user up one directory, so if the user was in the `/first/second`, running the `cd ..` command moves the user to the `/first` directory.
- The `cd -` command navigates the user to the previous directory.
Enter fullscreen mode Exit fullscreen mode
  • touch: Use the command to create empty files in Linux. The touch command creates a file on our machine that we can open and update in our IDE. Linux Command

Linux Command
Linux Command
Linux Command

  • cp: Use this command to copy files into a directory or copy directories from one location to another.

To copy files into a directory, we specify what file we want to copy and the directory we want to copy the file into, alongside the cp command.

Linux Command

In the screenshot above, we copied the practice_file from the linux_practice directory and pasted it into the linux_test directory.

We use the ls command to verify that we successfully copied and pasted the file.

To copy directories, we add the -rvfp parameter.

  • rm: Use this command to delete files and directories in a directory.

    • To delete files or directories, we specify the file or directory we want to delete alongside the rm command. To delete directories, add the -rf parameter.
  • To delete files

    Linux Command

To delete directories

Linux Command

  • cat: Use this Linux command to display the contents of a file.
    Linux Command

  • locate: Use this command to locate a file on the Linux system. To make the search case insensitive, use the -i flag.

  • grep: Use this command to search through a text file.
    Linux Command

  • head: Displays the first ten lines of a file.

  • tail: Displays the last ten lines of a file.

  • sed: Use this command to replace texts in a file.
    Linux Command

  • find: Use this command to find files or a directory’s path.

  • sudo: Use this command to execute commands usually executed by the root user.

Conclusion

This article discussed what Linux is, why we should care about the Linux operating system, and, more importantly, how commands we can execute in Linux.

Resources

The resources below can be helpful:

Top comments (0)