Using realpath from GNU coreutils 8.23 is the simplest, I think:
$ realpath --relative-to="$file1" "$file2"
For example:
$ realpath --relative-to=/usr/bin/nmap /tmp/testing
../../../tmp/testing
More Related Contents:
- How to obtain the absolute path of a file via Shell (BASH/ZSH/SH)?
- Detect if PATH has a specific directory entry in it
- What is the most elegant way to remove a path from the $PATH variable in Bash?
- Expansion of variables inside single quotes in a command in Bash
- Reading quoted/escaped arguments correctly from a string
- Can a shell script set environment variables of the calling shell? [duplicate]
- How to add a progress bar to a shell script?
- What is the purpose of “&&” in a shell command?
- How can I remove the extension of a filename in a shell script?
- Automatic exit from Bash shell script on error [duplicate]
- How do I edit $PATH (.bash_profile) on OS X?
- YYYY-MM-DD format date in shell script
- How to suppress Terminated message after killing in bash?
- Get current directory name (without full path) in a Bash script
- Slash (/) vs tilde slash (~/) in style sheet path
- How do I redirect output to a variable in shell? [duplicate]
- What do $? $0 $1 $2 mean in shell script? [duplicate]
- Division in script and floating-point
- Copy folder recursively, excluding some folders
- Variable interpolation in the shell
- How to remove filename prefix with a Posix shell
- How to pipe multiple commands into a single command in the shell? (sh, bash, …)
- What does ” 2>&1 ” mean?
- How do I read user input into a variable in Bash?
- Count number of lines in a git repository
- How do I check if a directory exists or not in a Bash shell script?
- shell script respond to keypress
- How to update one file in a zip archive
- Why doesn’t my terminal output unicode characters properly?
- How to read variables from file, with multiple variables per line?