Quantcast
Browsing all 46 articles
Browse latest View live

Answer by Mecki for bash/fish command to print absolute path to a file

The answer of Alexander Klimetschek is okay if your script may insist on a bash or bash compatible shell being present. It won't work with a shell that is only POSIX conforming.Also when the final file...

View Article


Answer by David P. Chassin for How to obtain the absolute path of a file via...

I use the single line(cd ${FILENAME%/*}; pwd)However, this can only be used when $FILENAME has a leading path of any kind (relative or absolute) that actually exists. If there is no leading path at...

View Article


Answer by Mecki for How to obtain the absolute path of a file via Shell...

The answer of Alexander Klimetschek is okay if your script may insist on a bash or bash compatible shell being present. It won't work with a shell that is only POSIX conforming.Also when the final file...

View Article

Answer by Zorayr for How to obtain the absolute path of a file via Shell...

Answer with Homebrewrealpath is the best answer, but if you don't have it installed, you must first run brew install coreutils which will install coreutils with lots of awesome functions. Writing a...

View Article

Answer by Arj for How to obtain the absolute path of a file via Shell...

The simplest if you want to use only builtins is probably:find `pwd` -name fileNameOnly an extra two words to type, and this will work on all unix systems, as well as OSX.

View Article


Answer by Eugen Konkov for How to obtain the absolute path of a file via...

The dogbaneanswer with the description what is coming on:#! /bin/shecho "$(cd "$(dirname "$1")"; pwd)/$(basename "$1")"Explanation:This script get relative path as argument "$1"Then we get dirname part...

View Article

Answer by Atika for How to obtain the absolute path of a file via Shell...

An alternative to get the absolute path in Ruby:realpath() {ruby -e "require 'Pathname'; puts Pathname.new('$1').realpath.to_s";}Works with no arguments (current folder) and relative and absolute file...

View Article

Answer by fred.johnsen for How to obtain the absolute path of a file via...

I have placed the following script on my system & I call it as a bash alias for when I want to quickly grab the full path to a file in the current dir:#!/bin/bash/usr/bin/find "$PWD" -maxdepth 1...

View Article


Answer by Alek for How to obtain the absolute path of a file via Shell...

This is not an answer to the question, but for those who does scripting:echo `cd "$1" 2>/dev/null&&pwd||(cd "$(dirname "$1")";pwd|sed "s|/*\$|/${1##*/}|")`it handles / .. ./ etc correctly. I...

View Article


Answer by icyyd for How to obtain the absolute path of a file via Shell...

Hey guys I know it's an old thread but I am just posting this for reference to anybody else who visited this like me. If i understood the question correctly, I think the locate $filename command. It...

View Article

Answer by ShellFish for How to obtain the absolute path of a file via Shell...

#! /bin/bashfile="$@"realpath "$file" 2>/dev/null || eval realpath $(echo $file | sed 's/ /\\ /g')This makes up for the shortcomings of realpath, store it in a shell script fullpath. You can now...

View Article

Answer by Alexander Klimetschek for How to obtain the absolute path of a file...

This relative path to absolute path converter shell functionrequires no utilities (just cd and pwd)works for directories and fileshandles .. and .handles spaces in dir or filenamesrequires that file or...

View Article

Answer by bsingh for How to obtain the absolute path of a file via Shell...

For directories dirname gets tripped for ../ and returns ./.nolan6000's function can be modified to fix that:get_abs_filename() { # $1 : relative filename if [ -d "${1%/*}" ]; then echo "$(cd ${1%/*};...

View Article


Answer by peterh for How to obtain the absolute path of a file via Shell...

Forget about readlink and realpath which may or may not be installed on your system.Expanding on dogbane's answer above here it is expressed as a function:#!/bin/bashget_abs_filename() { # $1 :...

View Article

Answer by babou for How to obtain the absolute path of a file via Shell...

There is generally no such thing as theabsolute path to a file (this statement means that there may be more than one in general, hence the use of the definite article the is not appropriate). An...

View Article


Answer by Flimm for How to obtain the absolute path of a file via Shell...

$ readlink -m FILE/path/to/FILEThis is better than readlink -e FILE or realpath, because it works even if the file doesn't exist.

View Article

Answer by wjv for How to obtain the absolute path of a file via Shell...

Here's a zsh-only function that I like for its compactness. It uses the ‘A’ expansion modifier — see zshexpn(1).realpath() { for f in "$@"; do echo ${f}(:A); done }

View Article


Answer by lessthanideal for How to obtain the absolute path of a file via...

The find command may helpfind $PWD -name ex*find $PWD -name example.logLists all the files in or below the current directory with names matching the pattern. You can simplify it if you will only get a...

View Article

Answer by hluk for How to obtain the absolute path of a file via Shell...

If you don't have readlink or realpath utilities than you can use following function which works in bash and zsh (not sure about the rest).abspath () { case "$1" in /*)printf "%s\n""$1";; *)printf...

View Article

Answer by Dennis Williamson for How to obtain the absolute path of a file via...

Try readlink which will resolve symbolic links:readlink -e /foo/bar/baz

View Article
Browsing all 46 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>