File extension and upper and lower case in .text files
Hello there,
I am very new to Linux and I would like to know how do I change file extensions from .txt to .text. Once I have done that I would like to change all uppercase to lowercase in all files that have a .text extension. If anyone could help I would be really grateful and it is great to find such a helpful site like this. |
Hi,
For files renaming you cat use rename command . Code:
rename .txt .text *.txt You can use find command to change and rename all files content . Ex : Code:
find . -name *.text exec sed -i 's/\(.*\)/\L\1/' {} \; |
Thanks you so much goodhombre that is such a great help.
|
I'm just interested as to why you want to rename .txt to .text?
|
It is just personal preference really as I like the sameness of things, it relates to my OCD.
|
Hi goodhombre would you mind explain the code
-name *.text exec sed -i 's/\(.*\)/\L\1/' {} \; as im only new at linux and i don't understand what im trying to do |
alternate you can use move command too....
Quote:
|
Quote:
Incidentally, see tr http://linux.die.net/man/1/tr |
Quote:
...Or at least it would, were it not for a few problems. First of all, the "find" command name has clearly been cut off from the beginning. Second, exec should be -exec. Third, "*.text" needs to be quoted, because "*" indicates a shell globbing pattern that will expand to a list of all matching files in the current directory if not protected. find is also recursive into subdirectories by default, which may or may not be desirable. But most importantly, sed, particularly with the -i option, modifies the contents of files, so all this command would do is make all the text in every matched file lowercase! While I admit that the wording of the initial request could be interpreted this way, I highly doubt it's what he really wants. Most likely he was referring to lowercasing the file names. Here are a couple of links about using find: http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html Here are a few useful sed references. http://www.grymoire.com/Unix/Sed.html http://sed.sourceforge.net/grabbag/ http://sed.sourceforge.net/sedfaq.html http://sed.sourceforge.net/sed1line.txt Now to give my answer to the OP. First of all, the batch renaming of files is a question that has been asked and answered repeatedly. There are hundreds of threads here and on the web dealing with it, as well as half-a-dozen programs specifically designed just for the task. A quick search or two would have likely answered the question before it was even asked. But at the very core of the problem, all you really need is a loop, some parameter substitution, and the mv command. Code:
for name in *.txt; do See here for more on renaming files: http://mywiki.wooledge.org/BashFAQ/030 |
Thanks David the H. .
|
All times are GMT -5. The time now is 06:08 PM. |