Hi,
First post here. I have something that may prove to be difficult.
I have the following files:
Example1.0.0.tar.gz
Example2.tar
Example3.zip
Example4.0.0.0.0.0.bzip2
I need to remove the file extensions and store as a variable so they look like this:
Example1.0.0
Example2
Example3
Example4.0.0.0.0.0
The way I see it, there are only two ways of doing it. First, is to check the name for certain terms, say ".tar",".gz",".zip" and then have it removed from the name. If this is the best way, is there an efficient and clean way to do this?
The second way I see, is that I get the name without the extension after I unzip it, then store as a variable. So, with my command: tar xzf $FILE_VAR, is there a way to grab the folder that is spat out?
$File_VAR = Example1.0.0.tar.gz
tar xzf $FILE_VAR
<code to find out resulting folder name and store as variable>
Output = Example1.0.0
I would really appreciate any help and advice you can give,
Thanks,
James
---------- Post updated at 03:33 PM ---------- Previous update was at 03:26 PM ----------
Sorry, second post. The whole reason I want to do this is because I need to CD into the untarred directory without knowing what it is actually called.
Thing is because I cant get the name without the extension, I dont know the name of the folder that will be output from the untar operation, then I cant CD into it.
I dont want to specify the folder name that it will be untarred into because I have thousands of these to do.