Basic Linux Commands

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:

ls [option] [flag] [arguments]

Examples:

  • ls -l
    – Lists files and directories in a long list format with extra information.
  • ls -a
    – Lists all files, including hidden files and directories (hidden files start with a dot).
  • ls *.sh
    – Lists all the files with a .sh extension.
  • ls -i
    – Lists files and directories with their index numbers (inodes).
  • 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.

Print Working Directory

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

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.

cd [path_to_directory]

Examples:

  • cd ~
    or simply cd – Changes directory to the home directory.
  • cd -
    – Goes to the last working directory.
  • cd ..
    – Changes directory to one level up (parent directory).
  • 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.

mkdir [directoryName]

Examples:

  • mkdir newFolder
    – Creates a new folder named 'newFolder'.
  • mkdir .NewFolder
    – Creates a hidden directory (directories and files starting with a dot are hidden).
  • mkdir A B C D
    – Creates multiple directories (A, B, C, and D) at the same time.
  • mkdir /home/user/Mydirectory
    – Creates a new folder in a specific location.
  • 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.


Similar Articles