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
2. Changing Directories
3. Printing Current Directory
4. Creating Directories
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
Example:
rm -r /asia/uk/country/world
6. Copying Directories
Example:
cp -r my_dir /asia/uk/country/world
File Operations
1. Creating a File
Example:
Recommended by LinkedIn
touch new_file.txt
2. Adding Content to a File
Example:
cat > new_file.txt
Type your content, then press Ctrl + D to save and exit.
3. Viewing File Content
Example:
cat new_file.txt
4. Editing Files
5. Copying Files
Example:
cp new_file.txt copy_file.txt
6. Moving (or Renaming) Files
Example:
mv new_file.txt sample_file.txt
7. Deleting Files
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!