![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Can you pls post here a sample of filenames and foldernames which you want to movie to a specific folder?
|
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Code:
#!/bin/ksh
find . -name '*.pdf' | \
while read filename
do
directory=${filename%.pdf}
mv "$filename" "$directory"/"$filename"
done
|
|
#5
|
|||
|
|||
|
Thanks for the information.
|
|
#6
|
||||
|
||||
|
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
|
|
#7
|
|||
|
|||
|
I Don't Know
|
|||
| Google The UNIX and Linux Forums |