|
Home > Archive > Unix Shell > February 2006 > how to use cp and mv
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 |
how to use cp and mv
|
|
|
| hi I'm trying to move files up to a parent directory from a
subdirectory using the cp or mv command. but when ever I go something
like cp way.in home/ it just creates a new home/ subdirectory and puts
the file in there instead of moving it up.
Also say you have two directories Run/ and exp1/ both at the same
level. What syntax would you use to move a file directly from Run/ to
exp1/?
Thanks...
| |
| Barry Margolin 2006-02-20, 5:54 pm |
| In article <1140469199.304595.10330@z14g2000cwz.googlegroups.com>,
"Blah" <cidster12@yahoo.com> wrote:
> hi I'm trying to move files up to a parent directory from a
> subdirectory using the cp or mv command. but when ever I go something
> like cp way.in home/ it just creates a new home/ subdirectory and puts
> the file in there instead of moving it up.
Why should it move it up? If you want to move a file up a level, do:
mv filename ..
If you don't already have a home/ subdirectory, it should report an
error. The cp command doesn't create directories automatically (unless
you use the -r option to copy a directory hierarchy -- but it still
won't create the target directory).
$ cp .profile nonexistent-dir/
cp: directory nonexistent-dir does not exist
> Also say you have two directories Run/ and exp1/ both at the same
> level. What syntax would you use to move a file directly from Run/ to
> exp1/?
From the common parent directory:
mv Run/filename exp1
From the Run directory:
mv filename ../exp1
or from the exp1 directory:
mv ../Run/filename .
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Chris F.A. Johnson 2006-02-20, 5:54 pm |
| On 2006-02-20, Blah wrote:
> hi I'm trying to move files up to a parent directory from a
> subdirectory using the cp or mv command. but when ever I go something
> like cp way.in home/ it just creates a new home/ subdirectory and puts
> the file in there instead of moving it up.
First, cp would not create a directory. If the directory 'home'
exists, it will copy the file into it, otherwise it will give you
an error message:
/bin/cp: cannot create regular file `home/way.in': No such file or directory
The parent directory is abbreviated as '..':
cp way.in ..
> Also say you have two directories Run/ and exp1/ both at the same
> level. What syntax would you use to move a file directly from Run/ to
> exp1/?
mv Run/FILENAME exp1
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| Michael Tosch 2006-02-20, 5:54 pm |
| Blah wrote:
> hi I'm trying to move files up to a parent directory from a
> subdirectory using the cp or mv command. but when ever I go something
> like cp way.in home/ it just creates a new home/ subdirectory and puts
> the file in there instead of moving it up.
>
You certainly want
cp way.in /home
or
cp way.in ..
Note that a trailing / does not have any effect (ignored).
Only the ls command has an option to append a / when presenting directories.
>
> Also say you have two directories Run/ and exp1/ both at the same
> level. What syntax would you use to move a file directly from Run/ to
> exp1/?
>
>
mv Run/file exp1/file
or
mv Run/file exp1
The latter is less safe because the file would be renamed exp1 if
a directory with this name does not exist.
--
Michael Tosch @ hp : com
|
|
|
|
|