LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 11-21-2011, 02:23 PM   #1
me.
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Rep: Reputation: Disabled
script to copy files


hi all,

trying to write script that will copy all files from one directory to another directory one by one (donít use
Code:
cp * /another/directory/
)
and prompt if any errors example if another directory dont exist, or trying to copy files that already are there.

I managed to list all files and check if they exist or not but how can I change it so script will copy one file at a time and display each copied file in separate lines:

Quote:
#!/bin/bash

dest=~/Documents/Scripts/Copy

for file in $( ls )
do
if [ -d $file ]; then
[ -f $dest/$file ]
cp $file $dest/${file}1
else
echo " file $file already exist "
fi
done
 
Old 11-21-2011, 02:37 PM   #2
Nermal
Member
 
Registered: Jan 2009
Distribution: Debian
Posts: 59
Blog Entries: 2

Rep: Reputation: 6
I would use cpio, just to be different.

Code:
# Make the directory
mkdir -p ~/Documents/Scripts/Copy

# Copy files from here aka .
find . -name -print | cpio -o | (cd ~/Documents/Scripts/Copy ; cpio -ivBud)
 
Old 11-21-2011, 02:44 PM   #3
me.
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
that would be handy but I dont want to use cp...

another issue arrived, I thought I can use counter for copying files (if its good idea help me with it ) if not just suggest something else:

when I use these code:
Code:
#!/bin/bash
dir=/home/andre/Documents/Scripts/Copy
files=$(pwd || ls -m || wc -w )
counter=

echo " $files "
echo " $files " shows how many files I do have in folder BUT I want it to BOTH display all files and count how many of them is, just to use counter later for a copying....

does that make sense?
 
Old 11-21-2011, 07:58 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
You seem to keep saying:
Quote:
I dont want to use cp
If this is the case, are you able to explain the following from your code?
Code:
cp $file $dest/${file}1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] A script to copy files. stf92 Linux - Newbie 17 12-08-2010 11:08 AM
Copy Files help script. da_bizkit Linux - Newbie 6 12-15-2009 09:10 PM
Creating a script to move or copy files into multiple directories below the files matthes138 Linux - Newbie 5 08-25-2009 05:57 PM
script to copy files scofiled83 Programming 9 07-06-2009 09:18 PM
Script to copy files defend Linux - Newbie 2 12-11-2008 11:56 AM


All times are GMT -5. The time now is 08:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration