If you are starting your journey into Linux and DevOps, it is important to learn some fundamental Linux commands. These commands will help you navigate through the system, manage files, and work with directories effectively. Here, we will cover some of the most commonly used commands, including listing files, navigating directories, and creating directories.

Listing Commands

The ls command is used to list the contents of a directory, such as subdirectories and files. It is one of the most basic and useful commands that you will use frequently.

Usage:

Bash
ls [option] [flag] [arguments]

Examples:

  • Bash
    ls -l
    – Lists files and directories in a long list format with extra information.
  • Bash
    ls -a
    – Lists all files, including hidden files and directories (hidden files start with a dot).
  • Bash
    ls *.sh
    – Lists all the files with a .sh extension.
  • Bash
    ls -i
    – Lists files and directories with their index numbers (inodes).
  • Bash
    ls -d */
    – Lists only directories. You can also specify a pattern to filter the results.

Directory Commands

Navigating between directories is essential for working in a Linux environment. The following commands are used to manage directories and navigate through them.

The pwd command prints the current working directory, which helps you know your current location in the file system.

Bash
pwd

Change Directory

The cd command is used to change the current directory. You can provide the path to the directory where you want to navigate.

Bash
cd [path_to_directory]

Examples:

  • Bash
    cd ~
    or simply cd – Changes directory to the home directory.
  • Bash
    cd -
    – Goes to the last working directory.
  • Bash
    cd ..
    – Changes directory to one level up (parent directory).
  • Bash
    cd ../..
    – Changes directory two levels up.

Create Directory

The mkdir command is used to create new directories at the specified location. This command helps organize files by creating new folders as needed.

Bash
mkdir [directoryName]

Examples:

  • Bash
    mkdir newFolder
    – Creates a new folder named 'newFolder'.
  • Bash
    mkdir .NewFolder
    – Creates a hidden directory (directories and files starting with a dot are hidden).
  • Bash
    mkdir A B C D
    – Creates multiple directories (A, B, C, and D) at the same time.
  • Bash
    mkdir /home/user/Mydirectory
    – Creates a new folder in a specific location.
  • Bash
    mkdir -p A/B/C/D
    – Creates a nested directory structure, creating all intermediate directories as needed.

Conclusion

Learning these basic Linux commands is essential for working efficiently in a Linux environment, especially when pursuing a DevOps career. These commands help you navigate the file system, manage files and directories, and perform essential tasks smoothly.

Keep practicing these commands to get comfortable with the Linux command line. Understanding these basics will make it easier for you to learn more advanced concepts in Linux and DevOps.