Basic Linux Commands Every Beginner Should Know
By Hajra Umer

Basic Linux Commands Every Beginner Should Know

Linux plays a crucial role in the tech world, especially in DevOps environments. Many modern DevOps tools are initially developed for Linux before being ported to other platforms. For instance, containerization tools like Docker were Linux-exclusive for years before becoming available on Windows. Similarly, automation tools like Ansible must be installed on a Linux system to act as the Ansible controller, even though they can manage Windows systems as targets. In Kubernetes, master nodes in a cluster also require Linux systems.

Linux comes in various distributions (or "flavors") such as Red Hat Enterprise Linux, CentOS, Ubuntu, and more. These systems provide both a Command Line Interface (CLI) and a Graphical User Interface (GUI), but the CLI is particularly powerful and essential for many tasks.

Below are some basic Linux commands that can help you get started:

Getting Started with Linux Shell

The Linux shell is a text-based CLI used to interact with the operating system. Different shells (like Bash, Zsh, etc.) may behave slightly differently. To check which shell you are using, you can run:

echo $SHELL        

The echo command prints text or environment variable values to the screen. It's often used in scripts to display information.


Essential Commands

1. Listing Directory Contents

  • Command: ls
  • Usage: Lists all files and directories in the current location.

2. Changing Directories

  • Command: cd
  • Usage: Navigates to a specified directory.

3. Printing Current Directory

  • Command: pwd
  • Usage: Displays the absolute path of your current working directory.

4. Creating Directories

  • Command: mkdir
  • Usage: Creates a new directory.

Example:

mkdir -p /asia/uk/country/world        

The -p option ensures that intermediate directories are created if they do not already exist.

5. Removing Directories

  • Command: rm -r
  • Usage: Removes a directory and all its contents.

Example:

rm -r /asia/uk/country/world        

6. Copying Directories

  • Command: cp -r
  • Usage: Copies a directory and its contents to a new location.

Example:

cp -r my_dir /asia/uk/country/world        

File Operations

1. Creating a File

  • Command: touch
  • Usage: Creates a new, empty file.

Example:

touch new_file.txt        

2. Adding Content to a File

  • Command: cat > filename
  • Usage: Allows you to input content directly into a file.

Example:

cat > new_file.txt        

Type your content, then press Ctrl + D to save and exit.

3. Viewing File Content

  • Command: cat
  • Usage: Displays the content of a file.

Example:

cat new_file.txt        

4. Editing Files

  • Use text editors like vi or vim to modify file contents.

5. Copying Files

  • Command: cp
  • Usage: Copies a file to a new location or creates a duplicate with a new name.

Example:

cp new_file.txt copy_file.txt        

6. Moving (or Renaming) Files

  • Command: mv
  • Usage: Moves or renames a file.

Example:

mv new_file.txt sample_file.txt        

7. Deleting Files

  • Command: rm
  • Usage: Deletes a file.

Example:

rm new_file.txt        

Running Multiple Commands

Commands can be chained together using a semicolon (;). For example:

mkdir -p /asia/uk/country/world; cd /asia/uk/country/world; pwd        

This creates a directory, navigates to it, and prints the current directory path.


Conclusion

Mastering these basic Linux commands is an essential step for anyone entering the world of DevOps or IT. They form the foundation for working effectively with Linux systems, whether you're managing servers, deploying applications, or automating tasks. Happy learning!

To view or add a comment, sign in

More articles by Hajra Umer

Insights from the community

Others also viewed

Explore topics