How would I rename all -m.css files to .css with the shell utility mv?
Type the following command to replace part of file name and press Enter: ls | Rename-Item -NewName {$_.name -replace "OLD-FILE-NAME-PART","NEW-FILE-NAME-PART"} In the command, replace "OLD-FILE-NAME-PART" and "NEW-FILE-NAME-PART" with the old and new part of the file name.
Browse to the folder with the offending file, hit Shift + Right Click, and select Open a command window here. Now, input dir /x to see a list of shortened file names rather than the full-length version. From the same Command Prompt window, you can now delete the files using the short name.
How do I remove or access a file with the name '-something' or containing another strange character ? If your file starts with a minus, use the -- flag to rm; if your file is named -g, then your rm command would look like rm -- -g.
Use a for loop:
for file in *-m.css ; do mv "$file" "${file%-m.css}.css" ; done
Using rename
might be less verbose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With