Unix Shell - xcopy functionality in linux?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > November 2005 > xcopy functionality in linux?





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 xcopy functionality in linux?
TOC

2005-11-26, 7:49 am

I need to do a selective and recursive move. the function I am after is
done like this in windows:

xcopy c:\music\*.mp3 d:\music\ /s
del c:\music\*.mp3 /s


I can probably make a script using find and xargs but I thought I would ask
first.

I have looked at mmv and unison, (and rsync) none of those are what I am
looking for.

rsync is dooable, but it would copy the files and then delete the source,
as opposed to simply moving them (And retaining the original inode) so that
would take a while if I am moving 1000s of files.

Thanks in advance.
Benjamin Schieder

2005-11-26, 7:49 am

TOC wrote:
> I need to do a selective and recursive move. the function I am after is
> done like this in windows:
>
> xcopy c:\music\*.mp3 d:\music\ /s
> del c:\music\*.mp3 /s
>
>
> I can probably make a script using find and xargs but I thought I would ask
> first.


Maybe this is what you want?

http://shellscripts.org/project/mvpartial


Greetings,
Benjamin
--
#!/bin/sh #!/bin/bash #!/bin/tcsh #!/bin/csh #!/bin/kiss #!/bin/ksh
#!/bin/pdksh #!/usr/bin/perl #!/usr/bin/python #!/bin/zsh #!/bin/ash

Feel at home? Got some of them? Want to show some magic?

http://shellscripts.org
Icarus Sparry

2005-11-26, 7:49 am

On Sat, 26 Nov 2005 10:49:18 +0000, TOC wrote:

> I need to do a selective and recursive move. the function I am after is
> done like this in windows:
>
> xcopy c:\music\*.mp3 d:\music\ /s
> del c:\music\*.mp3 /s
>
>
> I can probably make a script using find and xargs but I thought I would ask
> first.
>
> I have looked at mmv and unison, (and rsync) none of those are what I am
> looking for.
>
> rsync is dooable, but it would copy the files and then delete the source,
> as opposed to simply moving them (And retaining the original inode) so that
> would take a while if I am moving 1000s of files.
>
> Thanks in advance.


Perhaps something like this? It uses 'find' to select the files, 'cpio -p'
to copy them, making links if it can, and "xargs rm" to clean up.

invoke as
cd c:\\music
scriptname d:\\music -name "*.mp3"

#!/bin/sh
usage(){
echo "Usage: $progname dest_dir [find_args]" >&2
exit 1
}
case "$#:$1" in
0:*|*:-h|*:.|* usage ;;
esac
dest=$1
if [ ! -d "$dest" ] ; then usage ; fi
shift
togo=/tmp/togo$$
find . -type f "$@" -print | tee $togo | cpio -padm "$dest"
if [ -s $togo ] ; then
xargs rm -f < $togo
fi
rm -f $togo

Janis Papanagnou

2005-11-26, 7:49 am

TOC wrote:
> I need to do a selective and recursive move. the function I am after is
> done like this in windows:


Since we are in a Unix newsgroup you may want to describe the semantics
of the xcopy command if there is anything special about it.

> xcopy c:\music\*.mp3 d:\music\ /s


In Unix shells a pattern like /music/*.mp3 would not mean to consider any
subdirectory; all *.mp3 files in the directory /music would be referenced.
So explain why you mean to need a recursive solution and why you use the
/s option of xcopy in this case.

> del c:\music\*.mp3 /s
>
> I can probably make a script using find and xargs but I thought I would ask
> first.
>
> I have looked at mmv and unison, (and rsync) none of those are what I am
> looking for.
>
> rsync is dooable, but it would copy the files and then delete the source,
> as opposed to simply moving them (And retaining the original inode) so that
> would take a while if I am moving 1000s of files.


If you have your files on different disk partitions you won't be able to
"move" them, you *have* to copy and remove them from the original location.

On which system are you working, and which tools using? On GNU/Linux there
is the 'cp -pR' which recursively copies and keeps as much information as
possible intact.

Janis
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com