Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 652

Answer by Kamil Maciorowski for How to delete a file as long as another file with the same name but a different extension of it exists?

$
0
0

This portable snippet of shell code will process files in the current working directory (but not in subdirectories):

for f in ./*.mkv; do   [ -f "${f%.mkv}.mp4" ] && echo rm "$f"done

Just in case, the above is a dry run, it only prints what it would do. If this looks fine, remove exactly the string echo to "arm" the snippet, then run the altered version.

Note the standard is ./*.mkv does not match dotfiles. In Bash, if you want our snippet to match also dotfiles, invoke shopt -s dotglob beforehand. For completeness: shopt -u dotglob sets the standard behavior.


Viewing all articles
Browse latest Browse all 652

Trending Articles