The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
list the files but exclude the files in subdirectories shyjuezy UNIX for Dummies Questions & Answers 8 10-15-2008 01:42 PM
How list of files apart from *.class files in certain folder itsjoy2u Shell Programming and Scripting 3 09-04-2008 10:28 AM
counting a list of string in a list of txt files Pep Puigvert UNIX for Dummies Questions & Answers 4 08-15-2008 03:55 PM
How to List and copy the files containing a string redlotus72 UNIX for Dummies Questions & Answers 11 09-28-2007 11:58 AM
copy and rename list of files kinmak UNIX for Dummies Questions & Answers 7 02-27-2005 09:23 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-29-2008
pmeesara pmeesara is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
How to copy specified files from list of files from dir A to dir B

Hello,

fjalkdsjfkldsajflkajdskl

Last edited by pmeesara; 09-29-2008 at 03:38 PM..
  #2 (permalink)  
Old 09-29-2008
DukeNuke2's Avatar
DukeNuke2 DukeNuke2 is offline Forum Staff  
Soulman
  
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,947
is this homework?
  #3 (permalink)  
Old 09-29-2008
pmeesara pmeesara is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 2
fjdsklfjlkds

Last edited by pmeesara; 09-29-2008 at 03:38 PM..
  #4 (permalink)  
Old 09-29-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink Many approaches, but here is one

The following example script checks to see if the archive (destination) folder exists; if not, it creates it.
Then it copies the files in the directory (that are called file*) to the archive folder (it displays them on the screen as it does it).
Finally, it lists the files that are now in the archive folder.

If you only want to copy certain files, it would be in that middle section where you could restrict the files to copy - for example
for zf in [X-Z].txt
to copy X.txt and Y.txt and Z.txt files.


Code:
> cat mv2arch 
#! /usr/bin/bash

# check on existence of archive
if [ ! -d archive ]
   then
   mkdir archive
fi

# copy the files
for zf in file*
   do
   echo $zf
   cp $zf "./archive/"$zf".bak"
done

# see what is in the archive folder
ls -l ./archive

exit 0
> mv2arch
file1
file2
file3
total 24
-rw-rw---- 1 xxx dp 21 Sep 29 12:33 file1.bak
-rw-rw---- 1 xxx dp 21 Sep 29 12:33 file2.bak
-rw-rw---- 1 xxx dp 21 Sep 29 12:33 file3.bak
Sponsored Links
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0