开发者

linux releative path to fullpath file name

I need a way of getting the fullpath name of a file on a linux shell script. The full path ma开发者_如何学Cy 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?


Use readlink(1).

readlink -f afile


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜