LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2016, 02:13 PM   #1
Kumail_08
LQ Newbie
 
Registered: Jan 2016
Posts: 1

Rep: Reputation: Disabled
Shell script for cp n number of files in one time


How can I cp n number of file at one time and then again other n number files second time after 5 min of sleep and so on and once all file get copied it start with the first n number of file again

Last edited by Kumail_08; 01-17-2016 at 02:14 PM.
 
Old 01-17-2016, 03:01 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Kumail_08 View Post
How can I cp n number of file at one time and then again other n number files second time after 5 min of sleep and so on and once all file get copied it start with the first n number of file again

something like this my function works, the loop you have to modify to get it to work, maybe even use a different type of loop. you have to figure out what files you are going to copy and how, keeping same name different location, or a different name different location, different name same location, or...

Code:
#!/bin/bash

# takes in number of times you want script to run on the command line

function rst(){

if [[ convertN -lt runTime ]]; then
	echo " you forgot to enter an amount to resample"
	ConvertNum=0
	exit 1
	else
	ConvertNum=$((convertN))
return $ConvertNum #pass the var to space land

fi

}

rst


while [[ $cpAmountFiles -ne $ConvertNum ]] ; 
do

 cp -v /path/file /path/file
 ((cpAmountFiles++))
  sleep 5
  
done
Code:
cp -v file1 file2 file3 file4 file5 /location/
#or
find /path/to/old/dir -name "file1" -o -name "file2" -exec cp {} /path/to/new/dir \; 
#or
cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/
or all the many other ways to copy more then one file at a time.

Last edited by BW-userx; 01-17-2016 at 03:05 PM.
 
Old 01-19-2016, 11:59 AM   #3
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,016

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Quote:
Originally Posted by Kumail_08 View Post
How can I cp n number of file at one time and then again other n number files second time after 5 min of sleep and so on and once all file get copied it start with the first n number of file again
This question sounds to me like you are trying to accomplish something which could better be done in a different way. Can you give a bit more background information on what you are trying to do? Is this an automated backup that you want to run?

Typically when you want to periodically copy data from one location to another cp might not be the first choice. Tools like rsync allow you to do incremental copies, i.e. only copy data that actually changed since the last operation.
You also probably want to use cron jobs rather than having sleep commands in a script.

So again, I bet if you give us more background info you'll end up with a better solution for the problem you are trying to solve...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Major number from shell script answerme Programming 4 05-19-2015 06:38 AM
[SOLVED] Shell script to create files in terms of 2 hrs for a given time range. calvinz Linux - Newbie 5 10-20-2011 10:17 AM
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
Shell Script to copy and number files extasic Programming 1 12-12-2008 06:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration