The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX command: mv - Objective: move files based on timestamp HLee1981 UNIX for Dummies Questions & Answers 4 07-11-2008 10:02 AM
Find and store files based on FileName and Modified Time edisonantus UNIX for Advanced & Expert Users 2 02-19-2008 11:25 AM
Report of duplicate files based on part of the filename sudheshnaiyer UNIX for Dummies Questions & Answers 1 12-18-2007 01:31 PM
If based on filename? kshelluser Shell Programming and Scripting 13 04-27-2007 07:46 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-22-2006
Registered User
 

Join Date: Aug 2006
Posts: 4
how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier.

Thanks for any help you can provide.
Reply With Quote
Forum Sponsor
  #2  
Old 08-22-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
Can you pls post here a sample of filenames and foldernames which you want to movie to a specific folder?
Reply With Quote
  #3  
Old 08-22-2006
Registered User
 

Join Date: Aug 2006
Posts: 4
For example several files could be: file1.pdf, file2.pdf, file3.pdf
Several folders could be file1, file2, file3

The destination folder for the files has the same name so file1.pdf goes to the folder, file1, file2.pdf to file2 and so on.
Reply With Quote
  #4  
Old 08-22-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,298
Code:
#!/bin/ksh
find . -name '*.pdf' | \
while read filename
do
      directory=${filename%.pdf}
      mv "$filename" "$directory"/"$filename"
done
Reply With Quote
  #5  
Old 08-22-2006
Registered User
 

Join Date: Aug 2006
Posts: 4
Thanks for the information.
Reply With Quote
  #6  
Old 08-22-2006
tayyabq8's Avatar
Moderator
 

Join Date: Nov 2004
Location: Bahrain
Posts: 555
One other way:
Code:
# /bin/ksh

for i in `ls -l | grep -v "^d" | awk '{print $9}'`; do
dir=${i%.*}
mv "$i" "$dir"/"$i"
done
Reply With Quote
  #7  
Old 08-23-2006
Registered User
 

Join Date: Aug 2006
Posts: 4
I Don't Know
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0