how to unzip File which has no extension

Hi experts,

I have files as you see which is in gzip format. How can i uncompress it using gunzip/gzip/uncompress?? The file has NO extension. Do i need to rename the file as *.Z /or other and then unzip the file.

bash-2.05$ file Files029999200711101618
Files029999200711101618: gzip compressed data - deflate method

//purple

the rename is not nessesary... but if the file has the same name like the archive and you want to unzip it to the same directory... problem :wink: so a renmae to filename.gz should solve your problem.

hth,
DN2

Can you do "cat myfile | gunzip "?
(But noting the above comment about overwriting the original!)

how to uncompress the files 'Files029999200711101618' in different directory not renaming it to *.gz??

Try something like:
gunzip < Files029999200711101618 > /some/other/directory/some_output_file

Not exactly:
gunzip -c myfile
This will write the result on the standard output...

( -c --stdout write on standard output, keep original files unchanged)

So:
gunzip -c Files029999200711101618 > /some/other/directory/some_output_file

Below is working-- many thanks.
gunzip -c Files029999200711101618 > /some/other/directory/Files029999200711101618

I have arround more than thousand GZIP files in directory. Could the expert guys provide me the shell script how to unzip those thousand files keeping the original filename unchanged.

//purple

something like this?

for i in `ls -1`
do
gunzip -c $i > /path/to/file/$i
done

not tested!

duke, above script works. In fact, it only works if i run it from the same archive dir. now i need more help from you. suppose, filename= unixtt* i have thousand gziped unixtt* files in a directory called /home/thousand/gzipfiles/
But in that directory there Remaining several unixtt* files that are already been UnZip and some files with Different file name like exyz*. In that case, i cannot use variable $i in the script.

I now want to unzip the unixtt* files and send it to /some/other/directory/sameas/unixtt*

what could be the better script for the above situation? I would like to run that script from different directory.

//purple

What does prevent you moving first the unzipped and other files out from /home/thousand/gzipfiles/ to a different directory /home/thousand/temp_dir/ , and then continuing unzipping the left-overs zipped files using the above for script.

mv unixtt1 unixtt2 ... unixttN exyz1 ... exyzN...  /home/thousand/temp_dir  

or if the unzipped files can be grouped together somehow, use a for loop for them, say:

for files in `ls unix*`
do
mv $files   /home/thousand/temp_dir
done

After you're done unzipping move the files to the same directory again.

Yap its good idea to use loop for moving files. So can do the below lines in same script ??--
-------------------
!#/usr/sh/

for files in `ls unix*`
do
mv $files /home/thousand/temp_dir
done

for i in `ls -1`
do
gunzip -c $i > /path/to/file/$i
done
--------------

above script will work if i run it from the same archive directory. But i want to run the script from Another directory. Then what should i change in the script ???

work with an option (the path where to look)!

like this:

#yourscript.sh /path/to/files

and call the path in your script like this:

mv ${1}/${files} /home/thousand/temp_dir

Simple, copy your script to a different dir:

cp -p gunzip_script   /home/thousand/other_dir/

then slightly modify your script adding cd to gzipfiles directory, and executing the script now from the other directory. Then remove the previous old script.

cd /home/thousand/gzipfiles
for i in `ls -1`
do
gunzip -c $i > /path/to/file/$i
done 

Now regarding moving files, that depends on your specific situation, I brought my moving script simply as an example. You have to find a way how to group your files that you need to move: unixtt* and exyz*, using grep or some other utility.

So I would it in 2 steps. Execute the scripts separately. First the move script then use the unzip script.

If you can't find a way how to group the files move them manually:

mv unixtt1 unixtt2 ... unixttN exyz1 ... exyzN... /home/thousand/temp_dir

Hi rubionis,

its works well. Many thanks. Below script i run from other directory and works. The reason Not to run the script from the same archive file directory is - unix system also trying to unzip the scritname (myscript.sh) as well. Becuase in shell we put $i, which means any file.

----
#!/usr/bin/sh
cd /home/thousands/gzipfiles/
for i in `ls -1`
do
gunzip -c $i > /path/to/file/$i
done
----
In my directory there some GZIP file and also normal data files with same name unixtt* Is it possible I can just unzip only GZIP unixtt* files leaving the data unixtt* files.??