LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 02-28-2005, 03:34 PM   #1
ShakyJake
Member
 
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, 04:32 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.
 
Old 02-28-2005, 04:35 PM   #3
dwight1
Member
 
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
done

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

Rep: Reputation: 74
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, 04:42 PM   #5
dwight1
Member
 
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.
 
  


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


All times are GMT -5. The time now is 12:20 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration