Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-28-2005, 02:34 PM   #1
Registered: Apr 2003
Location: USA
Distribution: Gentoo
Posts: 55

Rep: Reputation: 15
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?
Old 02-28-2005, 03:32 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
You can try this:
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.
Old 02-28-2005, 03:35 PM   #3
Registered: Feb 2005
Posts: 42

Rep: Reputation: 15
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

Note that the quote marks are required if your filenames have spaces in them.
Old 02-28-2005, 03:36 PM   #4
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
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.
Old 02-28-2005, 03:42 PM   #5
Registered: Feb 2005
Posts: 42

Rep: Reputation: 15
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
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
Use of wildcards and -R switch in ls and grep robgee1964 Linux - Newbie 7 12-04-2005 05:20 PM
copy problem using wildcards plisken Linux - General 11 11-16-2005 08:34 AM
Handling wildcards... artificialGekko Linux - General 5 03-24-2005 08:29 PM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 05:33 AM
Wildcards in kernel Squall Linux - General 1 04-20-2004 05:22 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:34 PM.

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