System Navigation

System Navigation

These commands help you navigate the Linux file system and find information about files and directories.

cd

Changes the current working directory.

cd [directory]

Special directories:

Examples:

# Change to home directory
cd ~

# Change to /etc directory
cd /etc

# Go up one directory level
cd ..

# Go to the previous directory
cd -

ls

Lists files and directories in the current directory.

ls [options] [directory]

Options:

Examples:

# List all files with details
ls -la

# List files sorted by size
ls -lS

# List files with human-readable sizes
ls -lh

pwd

Prints the current working directory (full path).

pwd [options]

Options:

find

Searches for files and directories in a directory hierarchy.

find [path] [expression]

Common expressions:

Examples:

# Find all .txt files in the current directory and subdirectories
find . -name "*.txt"

# Find all directories named "log"
find / -type d -name log

# Find files larger than 100MB
find /home -type f -size +100M

# Find files modified in the last day
find /var/log -type f -mtime -1

whereis

Locates the binary, source, and manual page files for a command.

whereis [options] command

Options:

Examples:

# Find all locations related to the ls command
whereis ls

# Find only the binary for grep
whereis -b grep

which

Shows the full path of shell commands.

which [options] command

Options:

Examples:

# Find the path to the python command
which python

# Find all python executables in PATH
which -a python

tree

Displays directory structure in a tree-like format.

tree [options] [directory]

Options:

Examples:

# Display directory tree with 2 levels
tree -L 2

# Display only directories
tree -d

locate

Finds files by name using a previously built database.

locate [options] pattern

Options:

Examples:

# Find all files with "config" in the name
locate config

# Find files ignoring case
locate -i README

updatedb

Updates the file name database used by locate.

sudo updatedb [options]

Options: