Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
11-26-2005, 01:44 PM
|
#1
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207
Rep:
|
renaming multiple files
I have 1191 html files in a directory that I can use fine on an ext3 file system. When I try to copy them onto a vfat USB drive, they will only copy if I remove the ? in each filename. Each file is named like this:
index.html?book_id=26&chapter=5&version=50
index.html?book_id=26&chapter=6&version=50
index.html?book_id=26&chapter=7&version=50
index.html?book_id=26&chapter=8&version=50
index.html?book_id=30&chapter=32&version=50
index.html?book_id=30&chapter=33&version=50
index.html?book_id=30&chapter=34&version=50
.....
I tried:
mv index.html?book_id* /home/huntz/NKJV2/book_id*
and got an error about moving multiple files must go into a specific directory.
So, does a script need to be written for this? If so, what would the script contain to rename files?
Marty
Last edited by linuxhippy; 11-26-2005 at 01:46 PM.
|
|
|
11-26-2005, 02:06 PM
|
#2
|
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,642
|
Try :
Code:
find . -name "*index.html*" | while read file; do
book_id=$(echo "$file" | cut -d= -f2 | cut -d'&' -f1)
chapter=$(echo "$file" | cut -d= -f3 | cut -d'&' -f1)
mv "$file" "/home/huntz/NKJV2/book_id${book_id}_chapter${chapter}"
done
|
|
1 members found this post helpful.
|
11-26-2005, 02:31 PM
|
#3
|
Senior Member
Registered: Jul 2004
Location: Netherlands
Distribution: Slackware
Posts: 2,721
Rep:
|
or :
rename index.html?book book *
btw: there's an error in rename manpage.
where to sent report ?
egag
|
|
1 members found this post helpful.
|
11-26-2005, 09:31 PM
|
#4
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207
Original Poster
Rep:
|
worked like a charm (rename and the script)-thanks!
Last edited by linuxhippy; 11-26-2005 at 10:15 PM.
|
|
|
11-26-2005, 09:46 PM
|
#5
|
Senior Member
Registered: Sep 2004
Location: Philadelphia, PA
Distribution: Xubuntu, Mythbuntu, Lubuntu, Picuntu, Mint 18.1, Debian Jessie
Posts: 1,207
Original Poster
Rep:
|
that rename command is nice-I see how the man page has an error, though. Since Win needes .html on files to open them in a web browser I'd like to add the .html extension on all the files. Currently I have 1191 files with these filenames:
book_id=7&chapter=19&book_id=10&chapter=10&version=50
book_id=7&chapter=1&book_id=10&chapter=10&version=50
book_id=7&chapter=20&book_id=10&chapter=10&version=50
book_id=7&chapter=21&book_id=10&chapter=10&version=50
book_id=7&chapter=2&book_id=10&chapter=10&version=50
book_id=7&chapter=3&book_id=10&chapter=10&version=50
.....
Can I use rename for this?
|
|
|
11-27-2005, 01:02 AM
|
#6
|
Senior Member
Registered: Aug 2005
Posts: 1,755
Rep:
|
There's also a program called "mmv" that can move or copy multiple files.
|
|
|
11-27-2005, 10:24 AM
|
#7
|
Senior Member
Registered: Jul 2004
Location: Netherlands
Distribution: Slackware
Posts: 2,721
Rep:
|
Quote:
Originally posted by linuxhippy
that rename command is nice-I see how the man page has an error, though. Since Win needes .html on files to open them in a web browser I'd like to add the .html extension on all the files. Currently I have 1191 files with these filenames:
book_id=7&chapter=19&book_id=10&chapter=10&version=50
book_id=7&chapter=1&book_id=10&chapter=10&version=50
book_id=7&chapter=20&book_id=10&chapter=10&version=50
book_id=7&chapter=21&book_id=10&chapter=10&version=50
book_id=7&chapter=2&book_id=10&chapter=10&version=50
book_id=7&chapter=3&book_id=10&chapter=10&version=50
.....
Can I use rename for this?
|
yip, but i thought you figured out howto
it's like search&replace:
rename <search -for> <replace-with> <target-files>
here that could be ( can be alot of ways ):
rename version=50 version=50.html *
( assumed the files are all " version=50 " )
egag
|
|
|
01-20-2011, 06:41 PM
|
#8
|
Member
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 531
Rep:
|
missing mmv
Quote:
Originally Posted by spooon
There's also a program called "mmv" that can move or copy multiple files.
|
A few minutes ago I was browsing the rename man page, and in the SEE ALSO section it listed mmv. Never heard of it before, and it isn't installed on Slackware 13.1. Should it be?
|
|
|
01-20-2011, 07:03 PM
|
#9
|
LQ Veteran
Registered: May 2008
Posts: 7,071
|
It's in a separate package on Fedora too which also isn't installed by default, so I guess the answer is 'no'. I hadn't heard of mmv either.
|
|
1 members found this post helpful.
|
01-21-2011, 02:28 AM
|
#10
|
Member
Registered: Jul 2004
Distribution: Slackware
Posts: 615
Rep:
|
Code:
al@P5Q:~/temp/tst$ ls
nam?me1 nam?me2 nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' ''
al@P5Q:~/temp/tst$ ls
namme1 namme2 namme3
al@P5Q:~/temp/tst$ find . -type f -name '*mm*' -print0 | xargs -0 rename 'mm' 'm?m' ''
al@P5Q:~/temp/tst$ ls
nam?me1 nam?me2 nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_' ''
al@P5Q:~/temp/tst$ ls
nam_me1 nam_me2 nam_me3
al@P5Q:~/temp/tst$
--
Alan
|
|
|
01-21-2011, 02:53 AM
|
#11
|
Member
Registered: Jul 2004
Distribution: Slackware
Posts: 615
Rep:
|
Oop, O onadvertently had an extra set of unneeded single quotes at the very RH end of the one liner.
Code:
al@P5Q:~/temp/tst$ ls
nam?me1 nam?me2 nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_' ''
al@P5Q:~/temp/tst$ ls
nam_me1 nam_me2 nam_me3
al@P5Q:~/temp/tst$
So, the corrected would be:
Code:
al@P5Q:~/temp/tst$ ls
nam?me1 nam?me2 nam?me3
al@P5Q:~/temp/tst$ find . -type f -name '*?*' -print0 | xargs -0 rename '?' '_'
al@P5Q:~/temp/tst$ ls
nam_me1 nam_me2 nam_me3
al@P5Q:~/temp/tst$
Only 2 args to the rename ie swap ? with _ in that above case
I found it from here:
http://linux.derkeiler.com/Mailing-L.../msg02549.html
It's powerful on my box and it worked even, despite that I had a mistake in the one liner.
--
Alan.
|
|
|
All times are GMT -5. The time now is 10:53 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|