Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 12th, 2011, 09:58 AM
pedroz pedroz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 112 pedroz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 14 h 59 m 45 sec
Reputation Power: 9
Copy files grabbing destination folder from file name

Hi all...

Below is what I am trying to do:
1. Having the following folder with the files...
/source_folder/dodiddone.tar.gz
/source_folder/gowentgone.tar.gz
/source_folder/gowentgone.log

2. I need to copy and chown files with extension .tar.gz to another folder
copy /source_folder/dodiddone.tar.gz /dodiddone/destiny_folder/dodiddone.tar.gz
copy /source_folder/gowentgone.tar.gz /gowentgone/destiny_folder/gowentgone.tar.gz

3. code
#!/bin/sh
SOURCE="/source_folder"
EXTENSION="tar.gz"

for i in "$SOURCE"/*.$EXTENSION
do
copy $i /(???-1-)/(???-1-).$EXTENSION
chown /(???-1-)/(???-1-).$EXTENSION
done

4. my doubts!
(???-1-) : here would be something like ${i%%.$EXTENSION} |sed 's#^.*/##' to grab the file name

***
Could you please help to solve this problem?

Many thanks!!!

Reply With Quote
  #2  
Old November 12th, 2011, 03:03 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,383 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 13 h 44 m 42 sec
Reputation Power: 383
bash

This works with bash. And with other shells too. Remove echo when you are satisfied the commands are correct.
Code:
#!/bin/sh
SOURCE="/source_folder"
EXTENSION="tar.gz"

destinationPath=/dodiddone/destiny_folder/

for i in "$SOURCE"/*.$EXTENSION
do
  destination="$destinationPath"/"${i##*/}"
  echo copy "$i" "$destination"
  echo chown "$destination"
done

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Copy files grabbing destination folder from file name

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap