I have a zip file that contains a CSV and I would like to unzip that into a specific folder and rename the file the same as the zip file name. For example.,

I have a zip file named: youtube_videos.csv.zip and I would like to unzip it to a certain folder called target and rename the file in that folder to youtube-videos.csv. I have it, but in two lines as below:

unzip datasets/youtube_videos.csv.zip -d target 
mv target/videos_data.csv target/youtube_videos.csv

Is there a one liner that could be used?

  • 1
    Why do you need a one liner? It can complicate things unnecessarilly. Nov 3, 2021 at 20:32
  • Is that good enough what I did?
    – joesan
    Nov 3, 2021 at 20:35
  • 1
    I don't see a problem with it. I posted an answer for a one liner, but as you can see, there are complications. Nov 3, 2021 at 20:52
  • why don't just use unzip datasets/youtube_videos.csv.zip -d target; mv target/videos_data.csv target/youtube_videos.csv?
    – phuclv
    Nov 4, 2021 at 3:36

2 Answers 2


Here's a one liner option, but it doesn't rename the file, it outputs its contents to stdout. Also maybe can't be used with the -d option (I can't make it work):

$ unzip -p datasets/youtube_videos.csv.zip videos_data.csv > target/youtube_videos.csv

Or if there's just one file inside the zip, you can omit the name of the zipped files:

$ unzip -p datasets/youtube_videos.csv.zip > target/youtube_videos.csv

The option -p does, according to the manual:

-p extract files to pipe (stdout). Nothing but the file data is sent to stdout, and the files are always extracted in binary format, just as they are stored (no conversions).


With libarchive bsdtar:

bsdtar -xvvf youtube_videos.csv.zip -C target -'s/videos_data/youtube_videos/g'

Would extract the archive into the target directory with videos_data substituted with youtube_videos in the name of archive members.

(note that the target directory must exist beforehand).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .