![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| runnning a shell script in multiple folders | melearlin | Shell Programming and Scripting | 2 | 05-19-2009 02:36 AM |
| Shell script to move certain files on scheduled time | abhishek27 | Shell Programming and Scripting | 7 | 05-07-2009 12:09 AM |
| Move folders containing certain files | xavix | UNIX for Dummies Questions & Answers | 3 | 02-21-2009 06:43 AM |
| how to move files into different folders based on filename | italia5 | UNIX for Dummies Questions & Answers | 7 | 08-23-2006 10:04 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Shell script to move files to 3 different folders
Hi guys:
I've got this problem, I want to move a bunch of files to 3 different folders, without any specific order, and I'm trying to automatize it with a shell script. I'm a newbie at shell scripting so this is my first try: Code:
#!/bin/bash
COUNTER=`ls -1 | wc -l`
while [ "$COUNTER" != "0" ]
do
ARRAY=( $(ls | head -n 3) )
mv ${ARRAY[0]} folder1/
mv ${ARRAY[1]} folder2/
mv ${ARRAY[2]} folder3/
done
As you can see, I'm trying to do this by reading the first 3 files inside the folder where the script is executed and then putting them inside an array to make the 3 mv statements. I'm sure it's all messed up. I'll really appreciate your help with this one. |
| Bits Awarded / Charged to wretchedmike for this Post | |||
| Date | User | Comment | Amount |
| 07-14-2009 | Neo | Added code tags | -3,000 |
| Bookmarks |
| Tags |
| file, folder, move, script, shell |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|