Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a directory with about 2,000 files that have various differn't file extensions. I need to get these all these files to have the same extension of .bin or .txt something other then what is there now
Can anyone help a scripting newb, or can this be done with ls and sed?
Just a warning: mjrich's script will work, but it assumes there's only one '.' in the filename. For example, if there was a tarball named "my_backup.tar.bz2", the script would rename it to "my_backup.txt".
Another alternative would be to just slap the extension on the end:
Code:
#!/bin/bash
for filename in *
do
echo "mv -v ${filename} ${filename}.txt"
# mv -v ${filename} ${filename}.txt
done
Run the script and scan the output to make sure it looks like it's doing what it should. When you're ready, remove the comment marker '#' from the mv command, and run again. It's not extremely elegant, but it preserves the original filename so you can go back later if need be.
Interesting -- must be a different version of Bash or cut perhaps... my ones plow right on through and rename all *.*, including the double dotted files.
for file in $(find /the path/myrep/*) # This work with files in sub directories (absolute path)
do
# Moove only regular files and change the last .something with .txt
[ -f $file ] && mv $file $(echo $file|sed 's/.[a-zAZ-09]*$/.txt/')
done
I think that's ok.
Last edited by lampeasouder; 07-21-2005 at 04:54 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.