I need a way of getting the fullpath name of a file on a linux shell script. The full path may already be supplied or a relative file may be supplied.
afile.txt
/home/me/bfile.txt
to
/home/me/afile.txt
/home/me/bfile.txt
any ideas?
I need a way of getting the fullpath name of a file on a linux shell script. The full path may already be supplied or a relative file may be supplied.
afile.txt
/home/me/bfile.txt
to
/home/me/afile.txt
/home/me/bfile.txt
any ideas?
Quick hack:
get_fn()
{
echo $(cd $(dirname $1); pwd)/$(basename $1)
}
But it can be costly.
If the directory will be the same, you can list the files in that directory in this way:
DIRECTORY=/some/directory
FILE_NAME="my-file-list"
for i in `ls -1 $DIRECTORY`
do
echo $i >> $FILE_NAME
done
Otherwise, you would use the FIND
command in the How can I list files with their absolute path in linux?