UnixDroid

Files · Linux command

cd command in Linux

What does cd do?

cd (change directory) moves you into another folder. cd alone or cd ~ goes to your home folder, cd .. goes one level up and cd - returns to the previous folder.

cd [path]

Most useful options

OptionWhat it does
~your home folder
..the parent folder
-the previous folder
/the root of the file system

cd examples

$ cd /var/log Try it ›

go to the log folder (absolute path)

$ cd .. Try it ›

go up one level

$ cd Try it ›

go home

$ cd - Try it ›

jump back to where you were

In security work

Paths like ../../ ("path traversal") are how attackers escape a folder in vulnerable web apps.

Questions about cd

What is the difference between absolute and relative paths?

An absolute path starts with / and works from anywhere (/var/log). A relative path starts from your current folder (logs/app.log).