Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 21 Nov 2019, 00:46
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Archive only Specific Files in a Dir
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [1 Post]  
Author Message
s243a

Joined: 02 Sep 2014
Posts: 2161

PostPosted: Mon 15 Apr 2019, 14:45    Post subject:  Archive only Specific Files in a Dir
Subject description: A simple example
 

I created a short script to archive only specific files in a directory. This keeps one from having to clean working files (and other examples) before archiving. It is also a work-around for annoying errors like being unable to unmount a directory.

The basic code is:
Code:

echo_items(){
  for item in "${code_to_include}" "${directories_to_include}"; do
      if [ -d "$item" ]; then
        find . -wholename "./$item"'/*'
      else
        echo "./$item"
      fi
  done
}
echo_items | tar -czvf "$output_name" --files-from -

https://pastebin.com/AKZkViEx

And the above link is an example of how one might use it. I could make this code more robust by adding the " -print0" option to the above find statment, in which case one would need to add the "--null" option to tar.
See:
https://stackoverflow.com/questions/2597875/how-can-i-build-a-tar-from-stdin

but I would probably need to do a few more changes to the above code for this to work.

Note that when I tried this it says that tar exited with an error but the code seems to work and the archive looks like it was created. Perhaps this is due to some strange file I have in one of my directories (or maybe I need to repair my file system).

Edit 1
Actually, I'm surprised this worked because I would think that an ampersand is missing and the above line should be:
Code:

for item in "${code_to_include[@]}" "${directories_to_include[@]}"; do


maybe bash lets one be a bit sloppy but with out this fix the code would fail in ash.
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [1 Post]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0489s ][ Queries: 11 (0.0124s) ][ GZIP on ]