Follow

I had to change all ".txt" files in a directory to ".md" so did this:

$ for txtFile in $(find . -type f -name '*.txt' -print); do mv "$txtFile" "${txtFile%.*}.md" ; done

· · Web · 3 · 0 · 3

@deshipu Ah, thanks for pointing that out. I was lucky this time but I would do this in the future to make it work with filenames with spaces. I had this in my notes but forgot about it and tried to reinvent the wheel 🤦‍♂️:

$ find . -type f -name '*.txt' -print0 | while IFS= read -r -d '' tfile; do mv "$tfile" "${tfile%.*}.md"; done

@dsoft Isn't there a way to do this with find? Something like `find . -type f -name '*.txt' -exec (don't remember the spec)`?

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!