How to rename multiple file extensions in ubuntu 20.04 terminal?
I have hundreds of files without extension that I'd like to add a ".py" extension to all of them. As you can see manually renaming them one by one is a time consuming process. I think there might be any way of adding it all at once. Besides this I want to change extensions of many files from .mkv to .mp4.
1 Answer
These are two questions in one .... for renaming files without extension to .py, try the following dry-run from within the directory containing the files:
find -type f ! -name "*.*" -exec echo {} "--->" {}.py \;If you like what you see in the output, you can rename by running the following command from within the directory containing the files:
find -type f ! -name "*.*" -exec mv -- {} {}.py \;MKV and MP4 are two different formats and you need to convert them into each other using a media converter and renaming alone is not the right way to do it. For renaming .mkv to .mp4 anyway try the following dry-run command from within the same directory containing the files:
find -type f -name "*.mkv" -exec sh -c 'echo "$1" "--->" "${1%.mkv}.mp4"' _ {} \;And rename when satisfied with the output by running the following command from within the same directory:
find -type f -name "*.mkv" -exec sh -c 'mv -- "$1" "${1%.mkv}.mp4"' _ {} \;Notice:
You can make use of find's option -maxdepth to limit how deep find will look into sub-directories under the current working directory if there are any sub-directories.