Bird
Raised Fist0
Linux CLIscripting~10 mins

pwd (print working directory) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - pwd (print working directory)
User types 'pwd'
↓
Shell receives command
↓
Shell executes pwd program
↓
pwd reads current directory
↓
pwd outputs directory path
↓
Shell displays output to user
The shell runs the pwd command, which finds and prints the current directory path to the screen.
Execution Sample
Linux CLI
pwd
Prints the full path of the current working directory.
Execution Table
StepActionResultOutput
1User types 'pwd' and presses EnterShell receives command
2Shell runs pwd programpwd reads current directory path
3pwd outputs current directory pathOutput sent to shell/home/user/projects
4Shell displays outputUser sees current directory path/home/user/projects
5Command endsShell waits for next command
💡 pwd finishes after printing the current directory path
Variable Tracker
VariableStartAfter Step 2After Step 3Final
current_directoryundefined/home/user/projects/home/user/projects/home/user/projects
Key Moments - 2 Insights
Why does pwd print the full path instead of just the folder name?
pwd always prints the full absolute path to show exactly where you are in the system, as seen in execution_table step 3 where it reads and outputs the full path.
What happens if you run pwd in the root directory?
pwd will print '/', the root directory path, because it always shows the current directory, as shown in execution_table step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does pwd output at step 3?
A/usr/bin
Bpwd
C/home/user/projects
DNo output
💡 Hint
Check the 'Output' column in execution_table row for step 3
At which step does the shell display the current directory path to the user?
AStep 4
BStep 2
CStep 1
DStep 3
💡 Hint
Look at the 'Action' and 'Result' columns in execution_table for when output is shown to the user
If the current directory changes before running pwd, how would the output in step 3 change?
AIt would still show /home/user/projects
BIt would show the new current directory path
CIt would show an error
DIt would show the root directory '/'
💡 Hint
Refer to variable_tracker showing current_directory value at step 3
Concept Snapshot
pwd command prints the full path of your current directory.
Type pwd and press Enter.
Shell runs pwd, which reads and outputs the current directory.
Output helps you know exactly where you are in the system.
Useful before running other commands that depend on location.
Full Transcript
The pwd command in Linux prints the full path of the current working directory. When you type pwd and press Enter, the shell runs the pwd program. This program reads the current directory path from the system and outputs it. The shell then displays this path on the screen so you can see exactly where you are. For example, it might show /home/user/projects. This helps you keep track of your location in the file system before running other commands.

Practice

(1/5)
1. What does the pwd command do in a Linux terminal?
easy
A. Lists all files in the current directory
B. Deletes the current directory
C. Changes the current directory
D. Shows the full path of the current directory you are in

Solution

  1. Step 1: Understand the purpose of pwd

    The pwd command stands for 'print working directory'. It shows the full path of the directory you are currently in.
  2. Step 2: Compare with other options

    Options A, C, and D describe other commands like ls, cd, and rm, which do not print the current directory path.
  3. Final Answer:

    Shows the full path of the current directory you are in -> Option D
  4. Quick Check:

    pwd = current directory path [OK]
Hint: Remember: pwd = print working directory path [OK]
Common Mistakes:
  • Confusing pwd with ls (list files)
  • Thinking pwd changes directory
  • Assuming pwd deletes files
2. Which of the following is the correct syntax to display the current directory path in Linux?
easy
A. pwd
B. pwd -l
C. printwd
D. showdir

Solution

  1. Step 1: Identify the standard command

    The standard command to print the current directory is exactly pwd without any extra letters or options.
  2. Step 2: Check other options for validity

    Options B, C, and D are not valid Linux commands for this purpose. pwd -l is not a standard option, and printwd and showdir do not exist.
  3. Final Answer:

    pwd -> Option A
  4. Quick Check:

    Correct syntax = pwd [OK]
Hint: Type exactly 'pwd' to print current directory [OK]
Common Mistakes:
  • Adding wrong options like -l
  • Using non-existent commands
  • Confusing with print working directory spelled out
3. If you run these commands in order:
cd /usr/local
pwd
What will be the output of pwd?
medium
A. /usr
B. /usr/local
C. /local
D. /home/user

Solution

  1. Step 1: Understand the cd command effect

    The command cd /usr/local changes the current directory to /usr/local.
  2. Step 2: Check what pwd outputs

    After changing directory, pwd prints the full path of the current directory, which is /usr/local.
  3. Final Answer:

    /usr/local -> Option B
  4. Quick Check:

    cd changes directory, pwd shows it [OK]
Hint: pwd shows the directory set by last cd command [OK]
Common Mistakes:
  • Assuming pwd shows only part of the path
  • Confusing directory names
  • Thinking pwd shows home directory always
4. You run the command pwd but get an error: command not found. What is the most likely cause?
medium
A. The current directory is empty
B. You are not logged in as root
C. You typed pwd incorrectly or misspelled it
D. The terminal is broken and needs restart

Solution

  1. Step 1: Analyze the error message

    The error command not found means the shell cannot find the command you typed.
  2. Step 2: Identify common causes

    This usually happens if the command is misspelled or typed incorrectly. Being root or directory contents do not affect pwd availability.
  3. Final Answer:

    You typed pwd incorrectly or misspelled it -> Option C
  4. Quick Check:

    Misspelling commands causes 'command not found' [OK]
Hint: Check spelling if 'command not found' appears [OK]
Common Mistakes:
  • Assuming permissions cause 'command not found'
  • Thinking empty directory breaks pwd
  • Restarting terminal unnecessarily
5. You want to save the current directory path to a file named current_dir.txt (overwriting it if it exists). Which command correctly does this?
hard
A. pwd > current_dir.txt
B. pwd >> current_dir.txt
C. pwd | current_dir.txt
D. pwd current_dir.txt

Solution

  1. Step 1: Understand output redirection

    The symbol > redirects the output of a command to a file, overwriting it.
  2. Step 2: Apply redirection to pwd

    Using pwd > current_dir.txt writes the current directory path into the file current_dir.txt.
  3. Step 3: Check other options

    pwd >> current_dir.txt appends instead of overwriting. Options A and C are invalid syntax.
  4. Final Answer:

    pwd > current_dir.txt -> Option A
  5. Quick Check:

    Use > to save command output to a file [OK]
Hint: Use > to save output; >> appends output [OK]
Common Mistakes:
  • Using pipe (|) incorrectly to file
  • Forgetting > or >> for redirection
  • Using command with filename as argument
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard