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 |
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
02-28-2005, 02:34 PM
|
#1
|
|
Member
Registered: Apr 2003
Location: USA
Distribution: Gentoo
Posts: 55
Rep:
|
CLI wildcards
Having a hard time finding the answer to this one.
As an example, say I have a directory of document files. They all end in .doc and I wanted to change them all to .txt. What would be the appropriate wildcard arguement to preserve the filenames but change the extension?
|
|
|
|
02-28-2005, 03:32 PM
|
#2
|
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
You can try this:
Code:
rename ".doc" ".txt" *.doc
I'd read the man page beforehand just to make sure you understand what it'll do... or copy your stuff into a test directory and try it out.
|
|
|
|
02-28-2005, 03:35 PM
|
#3
|
|
Member
Registered: Feb 2005
Posts: 42
Rep:
|
Simply put, "*.doc". However, many Windows types of files have spaces in them, so you need to be careful.
You can't just do: mv *.doc *.txt, as that doesn't make sense. What you want to do is a little shell command like:
for i in *.doc ; do
n=`basename "$i" .doc`
mv "$i" "$n".txt
done
Note that the quote marks are required if your filenames have spaces in them.
|
|
|
|
02-28-2005, 03:36 PM
|
#4
|
|
Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
I'm sure you can use sed. Unfortunately I am not very good at shell scripting so can't post a script. However, take a look here, there could be an answer for you.
|
|
|
|
02-28-2005, 03:42 PM
|
#5
|
|
Member
Registered: Feb 2005
Posts: 42
Rep:
|
rename is the easiest. Just make certain you use "*.doc" as the last argument, to make certain you get the files with spaces in their names.
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:42 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
|
|