Jump to content

Linux - Get the last folder in path


xjx424

Recommended Posts

Hi, I am trying to zip a directory but when I zip and unzip it, it contains the whole path of the variable "album". I would just like to zip the last folder in the path. Here is what I have now. I tried basename but that didn't seem to work, possible I just can't make it work right.

#!/bin/shalbum=/var/www/hfandt.com/artists/*/*for al in $albumdo 		if [ ! -f "$al" ]; then	tar -zcvf "$al.tar.gz" "$al"	rm -r "$al"	fidone

Thanks

Link to comment
Share on other sites

When I untar the file I get the folder var. Then I open that and get every folder in the path. The folder being tar'ed is the var folder, not the target folder at the end of the path.I tried using basename like so

tar -zcvf "$al".tar.gz "$(basename "$al")"

but the path is wrongI'm assuming it's the absolute path that is the problem, I don't know how to get around that

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...