In case of renaming multiple file extensions to another, they suggested to type this command in cmd promt or powershell: ren *.(current extension name) *.(new extension name)
But what about to renaming multiple file extensions to nil or no file extension? How to replace this command *.(new extension name) ?
You must log in or register to comment.
- Set up WSL
- for file in * ; do mv “$file” $(basename “$file”) ; done
Edit: the other commenter is right, I fucked up the usage of basename.
newfile=$(echo $file|sed ‘s/..*//‘)
That’s a bit dangerous for a few reasons:
cat
is the wrong command, because it outputs the file’s content, not the file’s name.my.awesome.file.txt
would become an empty string, leading to errors. (The regex is not anchored to the end of the string (), the
.
is not escaped, so it becomes a wild card, …)My awesome file.txt
would trip up the loop and lead to unwanted results.
I’d suggest this:
for file in * ; do mv “$file” $(echo “$file” | sed -r 's/(\.tar)?\.[^.]*$//') ; done