DEV Community

Aryan Vaishnani
Aryan Vaishnani

Posted on

Navigation (cd, pwd, ls)

Navigation commands are used to move between directories and view files in the Linux filesystem.

The most important navigation commands are:

  1. pwd → Show current directory
  2. ls → List files and directories
  3. cd → Change directory

These commands are used daily by:

  1. Linux administrators
  2. DevOps engineers
  3. Developers
  4. Cloud engineers

1. pwd Command

Meaning

pwd = Print Working Directory

Shows the current directory path.

Syntax

pwd

Example

/home/aryan/projects

This means:

  • Current location is projects directory.

2. ls Command

Meaning

ls = List directory contents

Shows files and folders.

Basic Syntax

ls

Example

file1.txt
script.sh
projects/

Important ls Options

Command Purpose
ls -l Long listing format
ls -a Show hidden files
ls -lh Human-readable sizes
ls -lt Sort by modified time
ls -R Recursive listing

Long Format

ls -l

Output shows:

  1. Permissions
  2. Owner
  3. File size
  4. Modification date

DevOps Example

ls /var/log

View log files.

Kubernetes Example

ls ~/.kube

View Kubernetes config files.

3. cd Command

Meaning

cd = Change Directory

Used to move between directories.

Syntax

cd directory_name

Examples

Move into Directory

cd projects

Move to Absolute Path

cd /var/log

Move Back One Directory

cd ..

Move to Home Directory

cd

or

cd ~

Move to Previous Directory

cd -

Very useful in server administration.

Relative vs Absolute Paths

Absolute Path

Starts from /

Example:

cd /etc/nginx

Relative Path

Starts from current location.

Example:

cd projects/backend

Top comments (0)