How to copy specified files from list of files from dir A to dir B


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to copy specified files from list of files from dir A to dir B
# 1  
Old 09-29-2008
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 04:38 PM..
# 2  
Old 09-29-2008
is this homework?
# 3  
Old 09-29-2008
fjdsklfjlkds

Last edited by pmeesara; 09-29-2008 at 04:38 PM..
# 4  
Old 09-29-2008
Hammer & Screwdriver 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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Assign read write permission to the user for specific dir and it's sub dir and files in AIX

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. I do not want to assign user the same group of that directories too.... (0 Replies)
Discussion started by: blinkingdan
0 Replies

2. Shell Programming and Scripting

Copy files to a dir using from a list

Hi all, I'd very grateful for some help with the following: I have a directory with several subdirectories with files in them. All files are named different, even between different subdirectories. I also have a list with some of those file names in a txt file (without the path, just the file... (5 Replies)
Discussion started by: foracoffee
5 Replies

3. Shell Programming and Scripting

files copy to dir

Hi, I have a directory which is having many files. I want to copy 10files at a time to another directory. For example. First 10 files to one directory, then next 10 files to another directory and so on. Please let me know if any work around there for it. Thanks (4 Replies)
Discussion started by: Anjan1
4 Replies

4. Shell Programming and Scripting

KSH - Find paths of multiple files in CC (dir and sub-dir))

Dear Members, I have a list of xml files like abc.xml.table prq.xml.table ... .. . in a txt file. Now I have to search the file(s) in all directories and sub-directories and print the full path of file in a output txt file. Please help me with the script or command to do so. ... (11 Replies)
Discussion started by: Yoodit
11 Replies

5. Shell Programming and Scripting

Copy files and subdirs from dir to a new dir

Hello Comunity I am trying to make a bash shell script that it copies files and subdirs(with files) to a new dir. I would like the dest_dir to contain only subdirectories with files not other subdirs inside. it called : cpflatdir src_dir dest_dir Pleaze help me! Thank you in... (2 Replies)
Discussion started by: BTKBaaMMM
2 Replies

6. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

7. Shell Programming and Scripting

moving files from a dir in one machine to a dir in another machines

Hi, I am a unix newbie.I need to write a shell script to move my oracle READ WRITE datafiles from one serevr to another. I need to move it from /u01/oradata/W1KK/.. to /u01/oradata/W2KK, /u02/oradata/W1KK/.. to /u02/oradata/W2KK. That is, I actaully am moving my datafiles from one database to... (2 Replies)
Discussion started by: mathews
2 Replies

8. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

9. Shell Programming and Scripting

copy files from one dir to another

Hi , I want to copy files from one dir to anothe dir and check if destination dir exists ,if not exist ,has to create but when executing the below schell script ,the destination directory not exist and exit the shell script. #!/bin/sh src_path=/home/owngdw/abc tgt_path=/home/owngdw/abc/xyz if... (6 Replies)
Discussion started by: mohan705
6 Replies

10. UNIX for Dummies Questions & Answers

How to copy N files from one dir to another

Hi, I have a script that can only handLE limited number of input files. I need to be able to write a command (or a script) that: 1> copies N number of files from one directory (A) to another (B). 2> Files that are moved need to be renamed. 3> Files picked to be moved have... (1 Reply)
Discussion started by: GMMike
1 Replies
Login or Register to Ask a Question