Jump to content

Linux - Get the last folder in path


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


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...