Understanding 'mkdir', 'cd', and 'pwd' Commands in Linux
Summary
Linux is a powerful operating system that provides users with robust command-line tools for managing files and directories.
Some of the essential linux commands
Among the essential commands are 'mkdir', 'cd', and 'pwd', which are foundational for navigating and organizing your system. This article will explain these commands in detail, complete with examples.
Understanding the 'mkdir', 'cd', and 'pwd' Commands
In this article, we will explore three essential commands used in the command-line interface: 'mkdir', 'cd', and 'pwd'. These commands are fundamental when working with directories in Linux, macOS, or any Unix-like operating system. We’ll also include examples to illustrate their usage.
1. mkdir Command: Create Directories
The mkdir command is used to create new directories. It stands for "make directory."
Common Options:
-p: Creates parent directories as needed.
-v: Displays a message for each directory created.
mkdir [options] directory_name
Examples using 'mkdir'
The following code will create a single directory, create nested directories and create multiple directories at once
$ mkdir my_folder
$ mkdir -p parent_folder/child_folder
$ mkdir dir1 dir2 dir3
2. cd Command: Change Directory
The 'cd' command is used to navigate between directories.
Examples for the 'cd' command
Below there are some examples about the cd command
Navigate to a directory:
$ cd my_folder
Move to the parent directory:
$ cd ..
Return to the home directory
$ cd ~
Move to a subdirectory
$ cd documents
Navigate to an absolute path
$ cd /usr/local/bin
3. The pwd command (Print Working Directory)
The 'pwd' command displays the full path of the current working directory.
Examples
Print the current directory path:
$ pwd
Output might look like:
/home/user/documents
Understanding the mkdir, cd, and pwd Commands in Linux The Linux command line provides powerful tools to interact with the file system. Three fundame
Let's create a directory structure and navigate through it.
# Step 1: Create a directory structure
mkdir -p project/src/assets
# Step 2: Navigate to the project directory
cd project
# Step 3: Verify the current working directory
pwd
# Output: /path/to/project
# Step 4: Move to the 'src' directory
cd src
# Step 5: Verify the current working directory again
pwd
# Output: /path/to/project/src
Summary
- mkdir: Creates directories.
- cd: Navigates between directories.
- pwd: Displays the current directory path.
These commands are foundational to working with the Linux command line and are essential for effective file system navigation and management.