Moving Files from one directory to another directory | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

Moving Files from one directory to another directory

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-09-2009
ss3944 ss3944 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 19 January 2010, 4:08 PM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Tools Moving Files from one directory to another directory

Please do help me out with this. I have to write the following script.

There is a directory named "storage_directory" and it has hundreds of files in it. My script has to move each file from the storage_directory to "temp_directory" After moving each file, it has to create a log of the File name, that is moved into a text file.

Once I run the script, it should be able to move the first file from the "storage_directory" to the "temp_directory" and then create a text file with the name of the files transfered. Then, it has to move the next file in the "storage_directory" to the "temp_directory" and so on... It has to loop through the directory and move the files to "temp_directory"..
Sponsored Links
    #2  
Old 12-09-2009
erice erice is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 9 January 2013, 5:09 PM EST
Location: Houston, TX
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
mv is destructive, it will delete the original copy after the move, are you sure you don't want to cp first? then rm after you verify the integrity of the file?



Code:
#!/bin/ksh

for file in `ls storage_directory`
do
     mv storage_directory/$file temp_directory/$file
     echo "$file has been moved to temp_directory" >> somelogfile.txt
done


Last edited by pludi; 12-09-2009 at 05:21 PM.. Reason: code tags, please...
Sponsored Links
    #3  
Old 12-09-2009
ss3944 ss3944 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 19 January 2010, 4:08 PM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Thank You very much...
It works for me..
and yeah, I dont need to copy the files.. I just need to move them!
    #4  
Old 12-09-2009
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 24 October 2014, 9:49 AM EDT
Posts: 2,662
Thanks: 0
Thanked 17 Times in 17 Posts
Quote:
Originally Posted by erice View Post
mv is destructive, it will delete the original copy after the move, are you sure you don't want to cp first? then rm after you verify the integrity of the file?



Code:
#!/bin/ksh

for file in `ls storage_directory`
do
     mv storage_directory/$file temp_directory/$file
     echo "$file has been moved to temp_directory" >> somelogfile.txt
done

no need to use ls

Code:
for file in storage_directory/*

Sponsored Links
    #5  
Old 12-10-2009
ss3944 ss3944 is offline
Registered User
 
Join Date: Nov 2009
Last Activity: 19 January 2010, 4:08 PM EST
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
@ ghostdog74

Thanks so much!!!
Tried this one too.. it did work for me..

---------- Post updated at 11:29 AM ---------- Previous update was at 11:15 AM ----------

I have another Question:

I tried to run the following script: (I actually wanted to print out the second field in the text field.)

#!/usr/bin/ksh
set -x
readfile=/dir1/data.txt

cat $readfile | while read line
do
x = `echo $line|awk '{print $2}'`
echo $x
done

But, it shows the following error. It is unable to read the 'x' value.

# ./readData
+ readfile=/dir1/data.txt
+ cat /dir1/data.txt
+ read line
+ awk {print $2}
+ echo skhfkjshf 24343
+ x = 24343
./readData[7]: x: not found
+ echo

+ read line
+ awk {print $2}
+ echo jsdhfklhd 94890
+ x = 94890
./readData[7]: x: not found
+ echo


I have given all the permissions.. chmod 777 readData

Please help me out in solving this issue.

Thanks in advance.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Moving all files from 1 directory to another cryogen Shell Programming and Scripting 1 05-17-2009 02:12 PM
Moving files to specified directory. Jodi Shell Programming and Scripting 2 01-23-2009 06:41 AM
Creating date directory and moving files into that directory ravi030 Shell Programming and Scripting 3 12-05-2008 03:18 AM
Moving files not directory. senthil_is Shell Programming and Scripting 1 05-09-2008 01:21 AM
moving files from a unix directory to a windows directory gleads UNIX for Dummies Questions & Answers 2 08-29-2002 08:42 PM



All times are GMT -4. The time now is 05:09 PM.