LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-26-2019, 12:31 PM   #1
xpac
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Rep: Reputation: 0
Question Search for files w/extension, then zip them to a different directory?


Hi, basically I'm trying to find files with a certain extension in a directory (this part works fine), and then zip those files to a different location.

This works fine for zipping them to the location they are found in:

Code:
find ../somedirectory -type f -name "*.txt" -exec zip "$(basename {})"zip {} \;
However I need to send the zip file to a different directory so I'm trying this with no luck:

Code:
find ../somedirectory -type f -name "*.txt" -exec zip "/someotherdirectory/$(basename {})"zip {} \;
I get this:
Code:
zip I/O error: No such file or directory
I'm sure this is something simple I am missing?

Last edited by xpac; 06-26-2019 at 12:37 PM.
 
Old 06-26-2019, 01:30 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
The command substitution seems to be not getting the {} placeholder filled in time. Try it in a shell:

Code:
find ../somedirectory -type f -name "*.txt" \
    -exec sh -c 'zip "/someotherdirectory/$(basename {})".zip {}' \;
It will slow it down but it should work.
 
1 members found this post helpful.
Old 06-26-2019, 03:17 PM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
puts it all into one zip file
Code:
 find path -type f -name "*.txt" -print | zip path/nameOfFile.zip -@
 
1 members found this post helpful.
Old 06-26-2019, 04:32 PM   #4
xpac
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Turbocapitalist View Post
The command substitution seems to be not getting the {} placeholder filled in time. Try it in a shell:

Code:
find ../somedirectory -type f -name "*.txt" \
    -exec sh -c 'zip "/someotherdirectory/$(basename {})".zip {}' \;
It will slow it down but it should work.
Thanks, I got it working using this
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can I have zip -d file.zip "__MACOSX*" work on all zip files in directory? thomwblair Linux - Newbie 10 10-08-2018 02:30 PM
LXer: Linux kernel bugs: we add them in and then take years to get them out LXer Syndicated Linux News 0 10-27-2016 05:03 AM
search file name with same first 5 char and zip them barathan Linux - Newbie 2 12-15-2013 05:34 AM
[SOLVED] shell script to search for files of specific extension and delete them all rhklinux Linux - Newbie 12 07-12-2010 12:14 AM
command tofind files by extension through a directory tree, and copy them all to the budword Linux - Newbie 2 06-27-2009 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration