LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-18-2004, 02:24 PM   #1
TroelsSmit
Member
 
Registered: Feb 2004
Location: Denmark
Distribution: Debian / Suse
Posts: 223

Rep: Reputation: 30
script finding files, placing them and naming the


Hi,
I would like to create a script which will do the following:

1. Find all files following a regular expression finging following names: *.img *.IMG *.jpg *.JPG *.eps *.EPS

2. Move these files to a specified directory naming them:
1filename
2filename
3filename
etc.
etc.

If this can be easily done (tcsh,bash,perl) please help :-)
 
Old 11-18-2004, 02:57 PM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Here's a little bash diddy which may help.

#!/bin/bash
for i in *.jpg *.gif *.img
do
n=$(( $n + 1 ))
echo mv "$i" "/home/$n$i"
done
 
Old 11-18-2004, 09:14 PM   #3
TroelsSmit
Member
 
Registered: Feb 2004
Location: Denmark
Distribution: Debian / Suse
Posts: 223

Original Poster
Rep: Reputation: 30
Perfect, but I would like it to search my entire structure from / and so forth ... can that be done ?
 
Old 11-18-2004, 09:45 PM   #4
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
I would use:

find / \( -name "*.jpg" -o -name "*.img" -o - name "*.eps \) -print

to find the files, and then use xargs to pipe them to a shell script like homey gave you to do the moving. So the final result is:

find / \( -name "*.jpg" -o -name "*.img" -o - name "*.eps \) -print | xargs move_script

Then change the for loop in the script to "for i in $@" ($@ is all the arguments in bash).
 
Old 11-18-2004, 09:50 PM   #5
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
Perfect, but I would like it to search my entire structure from / and so forth ... can that be done ?
You can do this from the / if you want but normally something like that would be for renaming a bunch of pics in your images directory. If you want to run this from the root directory, I would not try to move ( mv ) all of those files but use copy ( cp ) instead.

#!/bin/bash
for i in *.jpg *.gif *.img
do
n=$(( $n + 1 ))
echo cp "$i" "/home/$n$i"
done
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script finding files, placing them and naming the TroelsSmit Linux - Networking 0 11-18-2004 02:21 PM
crontab not finding script michaeln *BSD 4 08-22-2004 10:07 PM
mail server the naming naming convention problem kashan Linux - Newbie 0 07-16-2004 02:08 PM
sysV firewall script naming arkamir Debian 2 02-25-2004 05:27 PM
What is the naming convention for files in rcX.d? roshko Linux - Newbie 2 09-01-2003 04:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration