Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-21-2011, 01:23 PM   #1
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
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:



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

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

# 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, 01:44 PM   #3
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:
files=$(pwd || ls -m || wc -w )

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, 06:58 PM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

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


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

All times are GMT -5. The time now is 08:37 AM.

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