Unix Shell - Trying to copy all *.csv files to another directory but fails - help

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > August 2006 > Trying to copy all *.csv files to another directory but fails - help





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Trying to copy all *.csv files to another directory but fails - help
phillip.s.powell@gmail.com

2006-08-24, 1:37 pm

# NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"

This code I thought would simply copy everything ending in ".csv" to
another directory, but I get the following error:

No such file or directory *.csv

What must I do to ensure copying files over?

Thanx
Phil

phillip.s.powell@gmail.com

2006-08-24, 1:37 pm


Stephan 'smg' Grein wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> phillip.s.powell@gmail.com wrote:
> Try that:
> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/clientCSV/${file}"; done
> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/projectCSV/${file}"; done
>
> You got wrong with the * quantifier.
>
> try above ;)
> np



Could you please explain that? None of it made sense to me, what is
that/??

Phil







>
> - --
> Stephan 'smg' Grein, <stephan at stephan minus rockt dot de>
> https://stephangrein.de
> GnuPG-Key-ID: 0xF8C275D4
> FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (GNU/Linux)
>
> iQIVAwUBRO3cJo1LAjD4wnXUAQLXAQ//azcZborYgbII4xSx7vHxDrIMTGSPyDdF
> leKFQ2+ql1geK6L2vKfhbc84JlUU5EPp3EWXtsHc
1jRAi65yzsH6ndKoogkSodRT
> oaFy4v9AuAfzxmoYn0qluC6dgJkaKYySjH5GjPKd
7n4anebB1ePVmg3TzDZPen07
> 9BvtNBd+FVBqf+RUPMp/ C2uKoncFMb4Nr3aJG4aWj3SvK5O9kuw5CqUTPBQ6
cz7j
> Z5+LF6vA3vS85zr6hvAINuASyR/B9nTgioAxjUPiBIBuY13HuggDOMZImqayc4B0
> iE0qPesW5n0F5WyrbV0MBDo09cugMvMCvzw/J0S7/gK2c97g959HG5pghnyMTE2W
> jvQ0Ke7k/ ojWZdhnNy+KSLRRzS2Ga9ZcDol8OWeldPmyWzkPs
gsIRnD6aNHdDwey
> pZxwlX0etjn4ff95IM6OLltXEgsXYmgkm9PuXEq+
cO5aeAb7Jcy9fGz8myCz2mWC
> ldSn8wfK57sJ8iMQdv2Twtndc06rOVRYUaSw5J1k
cheRezqOjJqy4YM8i4E8S5Qb
> GvkJlXAAZm8PWHWdJKrW4Qlr80MZLisHevAgLtxb
tclczkM7KECGheGtWxQ+KuPE
> 6SWRlFh5N4rrZpwm18A53fUnn/D2Rt+zdhAK+ty48T3XeeIHipqkrZ7vSWAdbu/o
> ya1Uhw9zJiU=
> =VzzK
> -----END PGP SIGNATURE-----


Xicheng Jia

2006-08-24, 7:26 pm

Stephan 'smg' Grein wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> phillip.s.powell@gmail.com wrote:
> Try that:
> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/clientCSV/${file}"; done
> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/projectCSV/${file}"; done


you may get into trouble if "$projectDocPath" is not an absolute path.
to keep the current directory info, you may want to use sub-shell with
your commands, like

( cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
"$csvBackupPath/clientCSV/${file}"; done )

Also, using 'find' might save OP some typing:

find "$clientDocPath" -type f -name "*.csv"
-exec cp -p "{}" "$csvBackupPath/clientCSV/" \;

or use find | xargs, find -exec ... + .....

(untested)
Xicheng

Chris F.A. Johnson

2006-08-24, 7:26 pm

On 2006-08-24, phillip.s.powell@gmail.com wrote:
> # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>
> This code I thought would simply copy everything ending in ".csv" to
> another directory, but I get the following error:
>
> No such file or directory *.csv


Filenames are not expanded inside quotes:

cp -pr "$clientDocPath/"*.csv "$csvBackupPath/clientCSV"
cp -pr "$projectDocPath/"*.csv "$csvBackupPath/projectCSV"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Bill Marcum

2006-08-25, 1:39 am

On 24 Aug 2006 10:10:52 -0700, phillip.s.powell@gmail.com
<phillip.s.powell@gmail.com> wrote:
>
> Stephan 'smg' Grein wrote:
>
>
> Could you please explain that? None of it made sense to me, what is
> that/??
>
> Phil
>

In sh and similar shells, if there is no file matching a wildcard
expression, the wildcard expression is left as is on the command
line. To avoid an error, you can use

if [ -f "$clientDocPath/*.csv" ]; then
cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
fi


--
Truth is the most valuable thing we have -- so let us economize it.
-- Mark Twain
Chris F.A. Johnson

2006-08-25, 7:33 am

On 2006-08-24, Bill Marcum wrote:
> On 24 Aug 2006 10:10:52 -0700, phillip.s.powell@gmail.com
> <phillip.s.powell@gmail.com> wrote:
> In sh and similar shells, if there is no file matching a wildcard
> expression, the wildcard expression is left as is on the command
> line. To avoid an error, you can use
>
> if [ -f "$clientDocPath/*.csv" ]; then


That doesn't work, because the wildcard will not be expanded.

> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> fi
>
>



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com