LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   CLI wildcards (https://www.linuxquestions.org/questions/linux-newbie-8/cli-wildcards-295945/)

ShakyJake 02-28-2005 02:34 PM

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?

Dark_Helmet 02-28-2005 03:32 PM

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.

dwight1 02-28-2005 03:35 PM

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.

reddazz 02-28-2005 03:36 PM

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.

dwight1 02-28-2005 03:42 PM

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.


All times are GMT -5. The time now is 01:00 PM.