In Linux, the "current directory" refers to the directory you're currently working in while using the terminal. This is also known as the **working directory**.
The current directory serves as the default location for executing file-related commands like ls, cp, mv, and touch. If you don’t provide full paths, Linux assumes the file or folder is in the current directory.
$ pwd
/home/username/Documents
This command shows your absolute path, starting from the root (/).
Use the cd command:
$ cd /etc
$ pwd
/etc
/home/user/Desktop../images. → Current directory.. → Parent directory~ → Home directory$ pwd
/home/user
$ cd Desktop
$ pwd
/home/user/Desktop
pwd before running file operations.In Linux, the concept of the "current directory" is fundamental to how you navigate, manipulate files, and execute commands in the terminal. Whether you're a beginner exploring the Linux filesystem or an advanced user writing scripts, knowing your current directory and how to work with it effectively is essential. This guide dives deep into the definition, tools, commands, examples, and best practices for managing the current directory in Linux.
The current directory in Linux is the directory you are “in” when executing commands in the terminal. It's the default location the shell refers to when handling files without an absolute path. Each terminal session has its own current working directory, which can be changed using navigation commands like cd.
To see your current directory in Linux, use the pwd command:
pwd
Example output:
/home/venkatesh/projects/website
This shows you're currently located inside the website directory, which resides in /home/venkatesh/projects/.
You can switch to a different directory using the cd command (change directory):
cd /etc
Now your current directory is /etc.
cdorcd ~
cd ..
cd -
The behavior of many commands in Linux depends on the current directory. You can use either:
/) – e.g., /home/user/docs../images or ./script.shIn Linux, a single dot . refers to the current directory. It’s commonly used in scripts and command-line utilities.
./script.sh
Runs the script located in the current directory.
find . -name "*.txt"
Searches for all .txt files in the current directory and subdirectories.
.. represents the parent directory (one level up).
cd ..
Moves you up to the parent folder.
$PWD is an environment variable that stores the absolute path of the current directory. It’s frequently used in shell scripting and automation.
echo $PWD
In bash and other shells, determining the current directory is crucial for creating portable scripts.
#!/bin/bash
echo "Script is running from: $(pwd)"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "Script directory: $SCRIPT_DIR"
By default, any file command will target files in the current directory unless an absolute path is provided.
touch file.txt
ls
rm file.txt
#!/bin/bash
echo "Current directory is: $(pwd)"
Since cron runs in a different environment, specifying full paths using pwd or $PWD ensures your script functions correctly.
* * * * * /usr/bin/bash /home/user/scripts/backup.sh >> /home/user/logs/$(date +\%F)_cron.log
To perform actions in the current directory, your user must have appropriate permissions:
lsls -ld .
Hidden files start with a dot . and are not shown by default.
ls -a
In GUI file managers like Nautilus or Dolphin, the current directory is shown in the window title or address bar. In CLI, use pwd.
pwd before executing file commands to confirm your locationcd - to toggle between last two directoriesrm in sensitive folders. without using ./The current directory in Linux is the foundation of all file operations in the shell. Understanding how to view, change, and manipulate it is key to working efficiently in the Linux environment. Whether you're managing large filesystems, writing scripts, or simply navigating your files, mastering the current directory concept will make your Linux experience faster, safer, and more productive.
Each shell in Linux—like bash, zsh, or fish—maintains its own internal state for the current working directory. This state is reset when a new shell is launched, which is why you always start in your home directory unless configured otherwise.
When you open a terminal, the current directory is typically set to:
/home/username
This behavior is controlled by your shell’s configuration file like .bashrc or .zshrc.
By default, Linux doesn’t remember your last working directory between sessions. However, you can configure terminal tools or the shell itself to resume from the last directory.
# Save current directory on logout
trap 'echo "$PWD" > ~/.lastdir' EXIT
# Restore it on new session
cd "$(cat ~/.lastdir 2>/dev/null)"
This approach ensures continuity in workflows, especially in long-term projects or remote work environments.
If you want to share the current directory between scripts or subshells, you can export the PWD environment variable.
export WORK_DIR=$(pwd)
echo "Working in directory: $WORK_DIR"
To execute a script or binary in the current directory, you must explicitly use ./ (dot slash), because . is not usually in your system’s PATH variable for security reasons.
./run.sh
This runs run.sh located in your current directory.
When working on large projects or in complex directory structures, maintaining awareness of the current directory is crucial to avoid file misplacement or command errors.
tree -L 2
This lists your current directory and its subfolders (2 levels deep).
You can set your shell prompt to always show your current path, aiding orientation.
PS1="\w $ "
Sysadmins regularly work across multiple directories when configuring servers, databases, or services. Knowing their exact location ensures they modify correct files and avoid costly mistakes.
/etc – System configuration files/var/log – Log files/usr/local/bin – Custom executables/home/username – User’s personal spaceIn containerized environments or VMs, you often mount volumes relative to your current directory:
docker run -v "$(pwd)":/app myimage
This maps your local current directory into the container’s /app folder.
If you want to trigger shell re-evaluation of the current directory (helpful when changes have occurred externally), you can use:
cd .
This re-enters the current directory and refreshes internal state variables.
Sometimes you need to work in a temporary folder. You can change your current directory to a temp folder using:
cd "$(mktemp -d)"
This creates and switches into a temporary directory safely.
In desktop environments like GNOME or KDE, you can configure file managers to show the full current directory path in the title bar or address bar. This setting mirrors the CLI concept visually for GUI users.
IDE tools like VS Code, PyCharm, or Eclipse often use the current directory as the root for:
scp -r $(pwd)/* user@server:/var/www/html
tar -czf backup.tar.gz $(pwd)
rsync -av . user@server:/data/$(basename $(pwd))
rm, mv, or chmod/ or /etc without absolute certaintyFor instructors teaching Linux, the concept of the current directory provides a practical entry point to:
cd, pwd, and lsRunning executables from the current directory using ./ can be risky in shared environments. Malicious users may place harmful scripts in common folders, relying on unknowing users to execute them.
. in your PATH environment variablealias rm='rm -i' to avoid accidental deletionsMastering how to manage and navigate the current directory in Linux is foundational for anyone working in a Unix-based environment. From basic navigation to advanced scripting, Docker workflows, system administration, and automation, the concept of the current directory appears everywhere. By understanding tools like pwd, cd, $PWD, and ., you can confidently control your environment, reduce errors, and write more reliable shell commands and scripts.