The UNIX and Linux Forums  


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



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-15-2009
Registered User
 

Join Date: Nov 2009
Posts: 2
Red face Need assistance with simple shell script to organize files. [Code attached]

I need some help with this shell script for class. All it does is organize your files. It works, but in the log file, it needs to show the new filepaths of the moved files. Heres my log of my output:


Code:
Starting to organize...
movie2.wmv --> 
movie3.mov --> 
movie1.mpg --> 
song1.mp3 --> 
song2.mp3 --> 
file1.txt --> 
final.txt --> 
grades.txt --> 
secretfile.txt -->

Where the arrows are, I need to print the filepath of the new files. So it would look something like this:


Code:
movie2.wmv-->  movies/movie2.wmv

Thank You for any help!
-Ryan


Code:
#!/bin/sh

echo "Are you sure you want to reorganize your files?"
echo "Enter 'Y' or 'y' to continue, anything else to cancel:"

read ANSWER
echo "You answered $ANSWER"

if [ $ANSWER == "Y" ] || [ $ANSWER == "y" ]; then
echo "Organizing files!"

touch organize.log
echo "Starting to organize..." > organize.log

mkdir movies

for filename in *.wmv
do
  mv $filename movies
  echo "$filename --> " >> organize.log
done

for filename2 in *.mov
do
  mv $filename2 movies
  echo "$filename2 --> " >> organize.log
done
  
for filename3 in *.mpg
do  
  mv $filename3 movies
  echo "$filename3 --> " >> organize.log
done
  
mkdir songs

for filename4 in *.mp3
do
  mv $filename4 songs
  echo "$filename4 --> " >> organize.log
done
  
for filename5 in *.wma
do
  mv $filename5 songs
  echo "$filename5 --> " >> organize.log
done
   
mkdir textfiles
  
for filename6 in *.txt
do
  mv $filename6 textfiles
  echo "$filename6 --> " >> organize.log
done
  
echo "Finished organizing files!"
echo "Bye!"

else
  echo "User cancelled the process."
  exit
fi
  
exit

  #2 (permalink)  
Old 11-15-2009
Registered User
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 618

Code:
for filename in *.wmv
do
  mv $filename movies
  echo "$filename --> movies/$filename" >> organize.log
done

or let mv work in verbose mode, and redirect it.


Code:
mv -v $finame movies >> organize.log

Example:

Code:
mv -v testfile testdir/
`testfile' -> `testdir/testfile'

  #3 (permalink)  
Old 11-15-2009
Registered User
 

Join Date: Nov 2009
Posts: 2
Thank You sir!

I appreciate it, this is due Monday night for class and has stumped me. I was proud of it with having only a lousy powerpoint file to work with.

Thanks
  #4 (permalink)  
Old 11-15-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
 

Join Date: Dec 2008
Location: .at
Posts: 2,596
Posting Homework in the main forums is not allowed. Thread closed.
Sponsored Links
Closed Thread

Bookmarks

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script Assistance jaysunn Shell Programming and Scripting 2 05-08-2009 05:36 PM
looking for a simple way to organize envs on our unix box... mr_manny Shell Programming and Scripting 2 08-25-2008 03:26 PM
shell script assistance please xinoo Shell Programming and Scripting 5 08-05-2008 12:18 PM
Need a little assistance with a shell script rickou812 Shell Programming and Scripting 3 02-04-2008 04:18 AM
How do I organize a series of files in date order? hedgehog001 UNIX for Dummies Questions & Answers 1 08-23-2005 12:04 AM



All times are GMT -4. The time now is 02:57 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