Relative Path
A relative path is a relative path starting from current directory. The word path contains both the file name and the directory name.
# Relative path foo foo/bar foo/bar/baz foo.txt foo/bar.pl foo/bar/baz.tar.gz
Linux recognizes paths that do not start with "/" as relative paths. Note that unlike absolute path, it does not start with a "/".
Sample using relative path
Use relative path with cd command
This is a sample that uses a relative path in the cd command.
cd foo/bar
If the current directory is "/home/kimoto", change the current directory to "/home/kimoto/foo/bar".
If the current directory is "/home/kimoto/labo", change the current directory to "/home/kimoto/labo/foo/bar".
Notice that the relative path is relative to the current directory.
Use relative path with ls command
This is a sample that uses a relative path in the ls command.
ls foo/bar
If the current directory is "/home/kimoto", a list of files existing in "/home/kimoto/foo/bar" will be displayed.
If the current directory is "/home/kimoto/labo", a list of files existing in "/home/kimoto/labo/foo/bar" will be displayed.
Use relative paths in other commands
touch command, mkdir command, rmdir command and rm command, can use relative paths.
touch foo/bar mkdir foo/bar rmdir foo/bar rm foo/bar
All Linux commands are designed to recognize relative paths.