Using the cd .. command moves you one level up from your current directory. If you are new to the command line, learning how to go up a directory in Linux is one of the first skills you need. This guide will show you every way to navigate upwards, from basic steps to advanced tricks.
Think of your Linux file system like a tree. You start at the root, and every folder is a branch. Moving up means going back toward the root. It is simple once you know the commands.
How To Go Up A Directory In Linux
The most common way is using cd ... This command works in almost every Linux shell. You type it, press Enter, and you move one folder up. For example, if you are in /home/username/Documents, cd .. takes you to /home/username.
Here is a quick breakdown of the syntax:
cdstands for “change directory”...represents the parent directory.- You can chain them:
cd ../..moves up two levels.
Let us test this. Open your terminal. Type pwd to see your current location. Then type cd .. and run pwd again. You will see the change.
Using Cd .. With Absolute Paths
Sometimes you want to go up and then into a specific folder. You can combine .. with a path. For instance, cd ../Downloads moves up one level and then into the Downloads folder. This saves time when you know where you want to land.
Another example: from /var/log/apache2, typing cd ../../ takes you to /var. Then you can add a folder name like cd ../../www to jump to /var/www.
Going Up Multiple Directories At Once
You can go up several levels with one command. Use cd ../../.. to move up three levels. Each .. represents one step upward. This is faster than typing cd .. three times.
For example, from /home/user/projects/myapp/src, cd ../../.. takes you to /home/user. Count the dots: three sets of two dots equals three levels up.
Be careful not to go too far. If you are at the root (/), cd .. does nothing. You cannot go above the root directory.
Alternative Commands To Move Up
The cd .. command is standard, but there are other ways. Some users prefer shortcuts or aliases. Here are a few alternatives:
cd -goes back to the previous directory you were in.pushd ..andpopdlet you navigate with a stack.cd ~takes you to your home directory, which is often several levels up.
Using Pushd And Popd For Navigation
If you move around a lot, pushd and popd are useful. pushd .. moves up and saves your current location to a stack. Later, popd returns you to that saved directory. This is great for temporary jumps.
Example workflow:
- You are in
/var/log. Typepushd ..to go to/var. - Do some work in
/var. - Type
popdto return to/var/log.
This method helps you avoid typing long paths repeatedly.
Setting Up An Alias For Going Up
If you type cd .. many times, create an alias. Add this line to your .bashrc or .zshrc file:
alias up='cd ..'
Now you can just type up to move one level up. You can also make aliases for multiple levels, like alias up2='cd ../..'. This speeds up your workflow.
After editing the file, run source ~/.bashrc to apply the changes. Test it by typing up in your terminal.
Common Mistakes When Going Up
New users often make small errors. Here are a few to watch for:
- Typing
cd ..with a space after the dots:cd ..works, butcd ..(extra space) is fine too. However,cd..without a space fails. - Forgetting the space between
cdand... The commandcd..is invalid. - Using
cd ...(three dots) by mistake. That is not a standard command. Usecd ../..instead. - Thinking
cd ..works in all contexts. It does not work in some scripts if the directory has special characters.
What If Cd .. Does Not Work?
Sometimes cd .. fails. This can happen if you do not have permission to access the parent directory. For example, if you are in a restricted folder, the system may block you. Use ls -la .. to check permissions.
Another issue is symbolic links. If your current directory is a symlink, cd .. might go to the link’s parent, not the target’s parent. Use cd -P .. to follow the physical path instead.
For example, if /home/user/link points to /var/www, cd .. from the link goes to /home/user. But cd -P .. goes to /var.
Going Up In Scripts And Automation
When writing bash scripts, you often need to move directories. Use cd .. inside scripts, but be careful. Changing directories in a script affects the script’s environment, not your terminal. After the script ends, you stay in the original folder unless you source the script.
Here is a simple script example:
#!/bin/bash
cd ..
echo "Now in $(pwd)"
Run it with bash script.sh. It prints the new directory, but your terminal stays put. To change your terminal’s directory, use source script.sh or . script.sh.
Using Cd .. With Find And Other Commands
You can combine cd .. with other commands. For instance, find .. -name "*.txt" searches for text files in the parent directory. This is useful for quick scans.
Another example: ls -la .. lists the contents of the parent folder. You can do this without changing your current directory. It is a read-only view.
If you want to copy a file from the parent directory, use cp ../file.txt .. The dot represents your current directory.
Understanding The File System Hierarchy
To master going up, know the structure. Linux has a root directory (/). Below it are folders like /home, /etc, /var, and /usr. Your user folder is usually /home/username.
When you open a terminal, you start in your home directory. From there, cd .. takes you to /home. Another cd .. takes you to /. You cannot go higher.
Here is a visual example:
- Current:
/home/user/Documents/work cd ..->/home/user/Documentscd ../..->/home/usercd ../../..->/homecd ../../../..->/
Going Up To A Specific Parent Directory
Sometimes you want to go up to a named folder, not just one level. For example, from /home/user/projects/myapp/src, you want to go to myapp. You can count the levels: cd ../.. works. But a better way is to use cd with a relative path from the root.
Another trick: use cd $(dirname $(pwd)) to go up one level programmatically. This is useful in scripts. For example, cd $(dirname $(pwd))/.. goes up two levels.
Using Tab Completion To Navigate Up
Tab completion works with cd ... Type cd .. and press Tab. The shell may show you available parent directories. This is handy if you forgot the exact folder name.
For instance, type cd ../D and press Tab. If there is a Downloads folder, it auto-completes. This saves typing and reduces errors.
You can also use Tab after typing cd ../../ to see options two levels up.
Going Up In Different Shells
Most shells use the same cd .. syntax. Bash, Zsh, and Fish all support it. However, there are minor differences. In Fish, you can use cd .. but also cd ... as an alias for cd ../.. in some configurations.
In Zsh, you can set up auto_cd to change directories without typing cd. Then just typing .. moves you up. Enable it with setopt auto_cd in your .zshrc.
Example in Zsh with auto_cd:
- Type
..and press Enter -> goes up one level. - Type
../..-> goes up two levels.
This is a time-saver for frequent navigation.
Practical Examples For Daily Use
Here are real-world scenarios where you need to go up a directory:
- You are editing a file in
/etc/nginx/sites-availableand want to check/etc/nginx. Usecd ... - You cloned a git repo into
/home/user/projects/repo. To go to the projects folder, usecd ... - You are in a deep log folder like
/var/log/apache2/old. Usecd ../..to return to/var/log.
Another example: you want to list files in the parent directory without moving. Use ls ... This is faster than changing directories and coming back.
Going Up And Running A Command
You can combine cd .. with other commands using &&. For instance, cd .. && ls moves up and then lists files. This is efficient for quick checks.
If you want to go up and then run a script, use cd .. && ./script.sh. The script runs from the parent directory.
Be careful with &&. If cd .. fails (e.g., permission denied), the next command does not run.
Troubleshooting Navigation Issues
Sometimes you get errors when trying to go up. Here are common fixes:
- Error: “bash: cd: ..: Permission denied”. Use
sudo cd ..? No, sudo does not work with cd. Instead, usesudo -sto become root, thencd ... - Error: “No such file or directory”. This happens if the parent directory was deleted. Check with
ls -la ... - Symbolic link confusion. Use
pwd -Pto see the physical path. Then navigate accordingly.
If you are stuck, use cd / to go to root, then navigate back down. This resets your position.
Advanced Techniques For Power Users
For those who want more, here are advanced methods:
- Use
cd $(dirs -l +1)to go up one level in the directory stack. - Create a function in your shell config:
up() { cd $(printf '%*s' $1 | tr ' ' '.'); }. Thenup 3goes up three levels. - Use
cd ..; cd -to go up and then back. This is a toggle.
These tricks require some shell scripting knowledge. They are not necessary for beginners but can boost productivity.
Going Up In A Docker Container
Inside a Docker container, the file system is isolated. The cd .. command works the same way. However, you might be in a minimal environment without bash. Use sh instead. The syntax is identical.
For example, in an Alpine container, cd .. still moves you up. The same rules apply.
Summary Of Key Points
Here is what you need to remember:
cd ..moves up one directory.cd ../..moves up two directories.- You can combine
..with folder names. - Use aliases to save time.
- Be aware of permissions and symlinks.
Practice these commands daily. Soon, moving up directories will be second nature.
Frequently Asked Questions
What is the command to go up one directory in Linux?
The command is cd ... It changes your current directory to the parent folder.
How do I go up multiple directories at once?
Use cd ../.. for two levels, or cd ../../.. for three. Each .. represents one level up.
Can I go up a directory without using cd?
Yes, in some shells like Zsh with auto_cd enabled, you can just type ... Also, you can use pushd .. or popd.
Why does cd .. not work sometimes?
It may fail due to permission issues, deleted parent directories, or symbolic links. Use ls -la .. to check.
How do I go to the root directory from anywhere?
Type cd /. This takes you to the root of the file system, regardless of your current location.
Learning how to go up a directory in Linux is a fundamental skill. With these methods, you can navigate the file system quickly and confidently. Practice in your terminal, and you will master it in no time.