Essential Linux Commands for Filesystem Navigation and Management

  1. pwd: Print Working Directory

The pwd utility outputs the absolute path of the current working directory. It is primarily used to verify your location within the filesystem hierarchy before executing path-dependent operations.

Syntax

pwd [options]

Usage Example

$ cd /var/log/nginx
$ pwd
/var/log/nginx
  1. cd: Change Directory

The cd command modifies the shell's current working directory. It supports both absolute and relative path resolution.

Syntax

cd [target_path]

Common Path Shortcuts

Usage Examples

# Navigate using an absolute path
$ cd /etc/sysconfig
$ pwd
/etc/sysconfig

# Jump to home directory
$ cd ~
$ pwd
/home/operator

# Return to the previous location
$ cd -
/etc/sysconfig

# Traverse upward using relative paths
$ cd ../../usr/local
$ pwd
/usr/local
  1. ls: List Directory Contents

The ls command displays files and directories within a specified path. It provides metadata such as permissions, ownership, size, and modification timestamps when combined with formatting flags.

Syntax

ls [options] [target_path]

Frequently Used Options

FlagDescription-lLong format: displays permissions, owner, group, size, and timestamp-aIncludes hidden files (those starting with a dot)-iDisplays the inode number for each entry-dLists directory entries themselves, not their contents-tSorts output by modification time (newest first)-rReverses the sorting order-RRecursively lists subdirectories

Usage Examples

# Verify file existence and view attributes
$ ls -l /etc/hostname
-rw-r--r-- 1 root root 14 Oct 12 09:30 /etc/hostname

# List multiple targets simultaneously
$ ls -l /etc/hosts /var/data/config.json
-rw-r--r-- 1 root root 221 Oct 12 09:30 /etc/hosts
-rw-r--r-- 1 app  app  1045 Nov 05 14:22 /var/data/config.json

# Display hidden files in the home directory
$ ls -a ~/
.  ..  .bash_history  .bashrc  .config  documents  .ssh

# Show inode numbers for current directory entries
$ ls -i
524891 config.yaml  524892 deploy.sh  524893 .env
  1. mkdir: Create Directories

The mkdir utility generates new directories. It can create single folders, multiple sibling folders, or nested hierarchies in a single invocation.

Syntax

mkdir [options] directory_name [directory_name...]

Key Options

Usage Examples

# Create multiple sibling directories
$ mkdir src build dist
$ ls -d src build dist
build  dist  src

# Generate a nested directory structure
$ mkdir -p archive/2023/november/reports
$ tree archive
archive
└── 2023
    └── november
        └── reports

3 directories, 0 files
  1. cp: Copy Files and Directories

The cp command duplicates files or directory trees to a specified destination. When copying directories, recursive mode must be enabled.

Syntax

cp [options] source destination

Key Options

Usage Examples

# Copy and rename in one step
$ cp app.conf /backup/app.conf.bak

# Copy multiple files into a target directory
$ cp data.csv metrics.csv /backup/

# Recursively duplicate a directory tree while preserving attributes
$ cp -a module_core/ /backup/modules/
$ ls -l /backup/
total 12
-rw-r--r-- 1 user user   0 Oct 20 14:10 app.conf.bak
-rw-r--r-- 1 user user   0 Oct 20 14:11 data.csv
-rw-r--r-- 1 user user   0 Oct 20 14:11 metrics.csv
drwxr-xr-x 2 user user  40 Oct 20 14:12 modules
  1. rm: Remove Files and Directories

The rm utility deletes filesystem objects. It operates permanently by default, bypassing any trash or recycle bin mechanisms.

Syntax

rm [options] target [target...]

Key Options

Usage Examples

# Delete a single file
$ rm draft_notes.txt

# Force-remove a directory and all nested contents
$ rm -rf old_cache/

# Interactive deletion for safety
$ rm -i temp_session.log
rm: remove regular empty file 'temp_session.log'? y
  1. mv: Move or Rename Files and Directories

The mv command relocates filesystem objects or changes their names. Unlike copying, moving updates directory entries without duplicating data blocks on the same filesystem.

Syntax

mv [options] source destination

Key Options

Usage Examples

# Relocate a script to a binary directory
$ mv setup.sh /usr/local/bin/

# Rename a file in place
$ mv readme.md README.md

# Move multiple logs into an archive folder
$ mv access.log error.log /var/log/archive/

# Relocate an entire directory
$ mv legacy_app/ /opt/deprecated/
  1. tree: Display Directory Structure

The tree command renders a visual, indented representation of directory hierarchies. It is highly useful for auditing project layouts or verifying nested structures.

Syntax

tree [options] [target_directory]

Key Options

Usage Examples

# Visualize a project layout
$ tree project_root/
project_root/
├── config
│   └── settings.json
├── src
│   ├── main.py
│   └── utils.py
└── tests
    └── test_main.py

3 directories, 4 files

# Limit output to two levels deep
$ tree -L 2 /var/www/
/var/www/
├── html
│   ├── index.html
│   └── assets
└── logs
    ├── access.log
    └── error.log

3 directories, 3 files
  1. du: Estimate File Space Usage

The du utility calculates disk consumption for files and directories. It is essential for identifying storage bottlenecks and monitoring partition utilization.

Syntax

du [options] [target_path]

Key Options

Usage Examples

# Summarize directory size in readable format
$ du -sh /var/www/html
142M    /var/www/html

# Identify largest subdirectories within a path
$ du -h --max-depth=1 /var/log | sort -rh | head -n 5
85M     /var/log
42M     /var/log/journal
28M     /var/log/apache2
10M     /var/log/syslog
5.2M    /var/log/kern.log

Tags: Linux bash coreutils filesystem-navigation directory-management

Posted on Fri, 08 May 2026 17:05:41 +0000 by webtuto