Basic Linux commands

Basic Linux commands

Day 2 Task: Basics linux command

Β·

3 min read

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

  • How to Use Linux Commands to Manage Files and Directories πŸ“

Linux is a powerful operating system that offers a variety of commands for performing various tasks. In this blog post, we will learn how to use some of the most common Linux commands to manage files and directories. We will cover the following topics:

  • How to check your present working directory using the pwd command πŸ“

  • How to list all the files or directories, including hidden files, using the ls command πŸ“œ

  • How to create a nested directory A/B/C/D/E using the mkdir command πŸ“‚

    Let’s get started!

How to Check Your Present Working Directory Using the pwd Command πŸ“

The pwd command stands for print working directory. It displays the full path of the current directory you are in. This is useful when you want to know where you are in the file system hierarchy.

To use the pwd command, simply type pwd in the terminal and press Enter. For example:

$ pwd
/home/user

The output shows that the current working directory is /home/user.

How to List All the Files or Directories, Including Hidden Files, Using the ls Command πŸ“œ

The ls command stands for list. It displays the names of the files or directories in the current or specified directory. This is useful when you want to see what files or directories are available in a certain location.

To use the ls command, simply type ls in the terminal and press Enter. For example:

$ ls
Documents  Downloads  Music  Pictures  Videos

The output shows that the current directory contains five subdirectories: Documents, Downloads, Music, Pictures, and Videos.

To list all the files or directories, including hidden files, you need to use the -a option with the ls command. Hidden files are files that start with a dot (.) and are usually not visible by default. For example:

$ ls -a
.  ..  .bashrc  .profile  Documents  Downloads  Music  Pictures  Videos

The output shows that the current directory also contains two hidden files: .bashrc and .profile.

How to Create a Nested Directory A/B/C/D/E Using the mkdir Command πŸ“‚

The mkdir command stands for make directory. It creates a new directory with the specified name. This is useful when you want to organize your files or directories in a structured way.

To use the mkdir command, simply type mkdir followed by the name of the directory you want to create in the terminal and press Enter. For example:

$ mkdir Projects

The command creates a new directory called Projects in the current directory.

To create a nested directory, such as A/B/C/D/E, you need to use the -p option with the mkdir command. The -p option creates the parent directories if they do not exist. For example:

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

The command creates a nested directory structure A/B/C/D/E in the current directory.

You can verify the result by using the ls command:

$ ls A
B
$ ls A/B
C
$ ls A/B/C
D
$ ls A/B/C/D
E

The output shows that the nested directory A/B/C/D/E has been created successfully.

Conclusion

In this blog post, we have learned how to use some of the most common Linux commands to manage files and directories. We have learned how to:

  • Check your present working directory using the pwd command πŸ“

  • List all the files or directories, including hidden files, using the ls command πŸ“œ

  • Create a nested directory A/B/C/D/E using the mkdir command πŸ“‚

We hope you have found this blog post helpful and informative. If you have any questions or feedback, please feel free to leave a comment below. Thank you for reading! 😊.

Β