Day 2 - Mastering Linux Commands for the DevOps Challenge (28 Nov, 2023)

Day 2 - Mastering Linux Commands for the DevOps Challenge (28 Nov, 2023)

Day 2 Task: Basics linux command

Task: What is the linux command to

  1. Check your present working directory.

  2. List all the files or directories including hidden files.

  3. Create a nested directory A/B/C/D/E

Introduction: Welcome back to Day 2 of the DevOps Challenge! Today, we're diving into the fundamental world of Linux commands. As we know, mastering these commands is essential for anyone navigating the DevOps landscape. In this blog post, we'll walk through some basic Linux commands and tackle the specific tasks assigned for today.

Task 1: Check your present working directory The first task is straightforward but crucial. To check your present working directory, use the pwd command. Open your terminal and type:

pwd

This command will display the full path of your current working directory, helping you stay oriented within the file system.

Task 2: List all files or directories, including hidden files Now, let's explore the contents of our current directory. The ls command is your go-to tool for listing files and directories. To include hidden files, use the -a option. Run the following command:

ls -a

This will provide a detailed list of all files and directories, including those with names starting with a dot (which are hidden in Unix-like systems).

Task 3: Create a nested directory A/B/C/D/E Creating nested directories is a common task in the world of DevOps. To create the specified nested directory structure A/B/C/D/E, we can use the mkdir command with the -p option. This option ensures that parent directories are created if they don't already exist. Execute the following command:

mkdir -p A/B/C/D/E

This one-liner magically creates the entire nested structure, saving you from the hassle of creating each directory one by one.

Basic linux commands

Listing commands

ls option_flag arguments --> list the sub directories and files avaiable in the present directory

Examples:

  • ls -l--> list the files and directories in long list format with extra information

  • ls -a --> list all including hidden files and directory

  • ls *.sh --> list all the files having .sh extension.

  • ls -i --> list the files and directories with index numbers inodes

  • ls -d */ --> list only directories.(we can also specify a pattern)

Directoy commands

  • pwd --> print work directory. Gives the present working directory.

  • cd path_to_directory --> change directory to the provided path

  • cd ~ or just cd --> change directory to the home directory

  • cd - --> Go to the last working directory.

  • cd .. --> change directory to one step back.

  • cd ../.. --> Change directory to 2 levels back.

  • mkdir directoryName --> to make a directory in a specific location

Examples:

mkdir newFolder              # make a new folder 'newFolder'

mkdir .NewFolder              # make a hidden directory (also . before a file to make it hidden)

mkdir A B C D                  #make multiple directories at the same time

mkdir /home/user/Mydirectory   # make a new folder in a specific location

mkdir -p  A/B/C/D              # make a nested directory