The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Moving files not directory. senthil_is Shell Programming and Scripting 1 05-09-2008 01:21 AM
Moving specific files Stud33 Shell Programming and Scripting 4 03-31-2007 09:50 PM
moving between vi files aya_r Shell Programming and Scripting 2 08-23-2005 04:36 AM
moving files ?? rocker40 UNIX for Dummies Questions & Answers 9 11-09-2003 08:36 PM
moving only files... sskb UNIX for Dummies Questions & Answers 12 11-19-2001 03:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-21-2007
iAm4Free iAm4Free is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 18
Moving Files

Hi There,

I am trying to move files, the file is present in this location:

/iAm4Free/test/generate/txt/information.txt

I need to move it to:

/iAm4Free/test1/generate/txt/information.txt

The only difference is the "test" is replaced with "test1". But the constraint is. The parent location the file exists in the same path specified but in the second location only /iAm4Free/test1/ exists but the remaining part "generate/txt/information.txt" dosen't exist. How can I create those directories automatically and move.

I know that mkdir -p creates directories, but is there something shorter in the mv command which does this automatically for you or any other simple way... any help i'll appreciate...

regards,
iAm4Free
  #2 (permalink)  
Old 03-22-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try this:
cd /iAm4Free
mkdir test1
cd test
cp -R * ../test1
# make the copy looks good
rm -rf *
  #3 (permalink)  
Old 03-23-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by iAm4Free
Hi There,

I am trying to move files, the file is present in this location:

/iAm4Free/test/generate/txt/information.txt

I need to move it to:

/iAm4Free/test1/generate/txt/information.txt

The only difference is the "test" is replaced with "test1". But the constraint is. The parent location the file exists in the same path specified but in the second location only /iAm4Free/test1/ exists but the remaining part "generate/txt/information.txt" dosen't exist. How can I create those directories automatically and move.

I know that mkdir -p creates directories, but is there something shorter in the mv command which does this automatically for you or any other simple way... any help i'll appreciate...

The beauty of a Unix system is the ability to create new commands from existing tools. If there isn't a command that does exactly what you want, write one.
Code:
## NAME: mvd -- Move file[s] to a (possibly none-existent) directory
## USAGE: mvd FILE ... DIR
## EXAMPLE: mvd /iAm4Free/test/generate/txt/information.txt /iAm4Free/test1/generate/txt

eval "destination=\$$#"
case $destination in
    */*) [ -d "$destination" ] || mkdir -p "$destination" || exit 1 ;;
esac
mv "$@"
  #4 (permalink)  
Old 03-26-2007
iAm4Free iAm4Free is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 18
Quote:
Originally Posted by cfajohnson

The beauty of a Unix system is the ability to create new commands from existing tools. If there isn't a command that does exactly what you want, write one.
Code:
## NAME: mvd -- Move file[s] to a (possibly none-existent) directory
## USAGE: mvd FILE ... DIR
## EXAMPLE: mvd /iAm4Free/test/generate/txt/information.txt /iAm4Free/test1/generate/txt

eval "destination=\$$#"
case $destination in
    */*) [ -d "$destination" ] || mkdir -p "$destination" || exit 1 ;;
esac
mv "$@"
Hey Johnson thanks... But I already submitted what I was supposed to do in a long way. I did a mv -f the filename from src and dest directories using the mkdir -p command to see if a directory dosen't exist. I did it in a longer way but I did like your logic of creating new commands But I didn't quite understand what you have written... it looks Fundoo to me Thanks..
  #5 (permalink)  
Old 03-26-2007
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
Nicely done. Chris.

iAm4Free,
there's no better time than now to start learning from the best!
  #6 (permalink)  
Old 03-28-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
Quote:
The beauty of a Unix system is the ability to create new commands from existing tools. If there isn't a command that does exactly what you want, write one.
aah, but there is!
cpio

Code:
cd   /iAm4Free/test
find . | cpio -pd ../test1
Closed Thread

Bookmarks

Tags
cpio

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:43 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0