Shell script to copy files from on folder to another


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to copy files from on folder to another
# 8  
Old 12-15-2015
The cp utility will always give you a diagnostic message if a copy fails. You haven't told us what operating system you're using, but if my guess (based on the names of some of your filesystems) that you're using a Linux operating system is correct, changing:
Code:
-exec cp {} "$dstdir" \;

to:
Code:
-exec cp -v {} "$dstdir" \;

should give you what you want. If you're using a system where cp doesn't support the -v option, you could change it to:
Code:
-exec cp {} "$dstdir" \; -exec printf '%s copied successfully\n' {} \;

This User Gave Thanks to Don Cragun For This Post:
# 9  
Old 12-15-2015
I am using ubuntu 14.04 lts. I will give a try to the advices you have given. and will let you know how the things are going Smilie
I really appreciate you help in this regard Smilie
# 10  
Old 12-15-2015
If you find that someone's post has helped you solve your problem, you can hit the "Smilie Thanks" button at the lower left corner of that post to express your appreciation.

I hope it is working for you. It's past time for me to go to bed...
This User Gave Thanks to Don Cragun For This Post:
# 11  
Old 12-15-2015
@Don Cragun I hope you are having a pleasurable sleep. Do guide me on one more thing that i also want to create a log file as well. Like it saves when a file is copied with its source and destination locations. Also i want to include in the log file when a copy does not happen. the log file will help me to find out if the things are going smoothly or not.
# 12  
Old 12-15-2015
Quote:
Originally Posted by Aqeel Abbas
@Don Cragun I hope you are having a pleasurable sleep. Do guide me on one more thing that i also want to create a log file as well. Like it saves when a file is copied with its source and destination locations. Also i want to include in the log file when a copy does not happen. the log file will help me to find out if the things are going smoothly or not.
Does this mean you want a log file written on top of having the messages on screen? Try piping through the tee command. If you wish to catch error msgs as well, you'll need to combine stdout and stderr upfront.
# 13  
Old 12-15-2015
Quote:
Originally Posted by RudiC
Does this mean you want a log file written on top of having the messages on screen? Try piping through the tee command. If you wish to catch error msgs as well, you'll need to combine stdout and stderr upfront.
Can you please show me an example ? It would be great Smilie
# 14  
Old 12-15-2015
(untested)
Code:
cp -v * $destdir 2>&1 | tee $logfile

will show progress and errors on screen and save them to the logfile at the same time.
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

2. Shell Programming and Scripting

Shell script which will check the target file and folder exists and copy it

Hi All, I am a beginner in this and trying to write a shell script in linux which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder... (3 Replies)
Discussion started by: ashish_neekhra
3 Replies

3. Shell Programming and Scripting

How to copy files with the same filenames as those in another folder to that same folder?

Hello All A similar question like this was asked before but I need to change part of the question. I've two folders, Folder A contains some image files in 150 subfolders; Folder B contains text files in 350 subfolders. All image files in Folder A have the same filename as the text... (5 Replies)
Discussion started by: chlade
5 Replies

4. Shell Programming and Scripting

Shell script that lists files with different owner than the folder

Hello, I'm trying to write a script which is listing files based on different preferences, like filetype or permissions. All is fine, except for one: I want to list files in /home which has a different owner than the home directory it is in. Here is an example: /home/UserA is the directory, and... (10 Replies)
Discussion started by: Zwiebi
10 Replies

5. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

6. Shell Programming and Scripting

How to Process input files from folder in shell script?

Hi, I want to process all input files available into folder (C:\ShellPrg\InputFile\) Input files are abc.CSV , XYZ.zip (zip of CSV file), PQR.gz (zip of CSV file). I want to check the extension of file, If its .zip/.gz then need to unzip the file as .CSV I want to parse line by line of... (2 Replies)
Discussion started by: Poonamol
2 Replies

7. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

8. Shell Programming and Scripting

HOW TO CHECK ONLY .C FILES EXISTS OR NOT IN A FOLDER using IF in C shell script?

Hi friends.. I hav a problem.... I dont know how to check .c files exists r not in a folder using IF in C shell script actually i tried like this if(=~ *.c) even though some .c files or there in the current folder..it is not entering int o the if control statement...... (17 Replies)
Discussion started by: p.hemadrireddy
17 Replies

9. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies

10. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies
Login or Register to Ask a Question