I just switched to using Ubuntu full time (coming from Windows 10), and I’ve read that it’s not a good idea to have spaces in file names on Linux. So I found a script online (see below) to replace spaces in file names with underscores, and I was planning on using it to change the names of some of my files that I transfer over from Windows, many of which currently have spaces.
I created a test folder with some files in it just to make sure the script does what I want it to do. However, rather than running the script to change the names inside my test folder, I accidentally ran it on my whole home directory, which also changed some of the names inside my .config folder and other directories I didn't want renamed. Here is the script I used:
!/bin/bash
find -name "* *" -print0 | sort -rz | \
while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f// /_}")"; done
and here is some of the sample output:
renamed './.config/google-chrome/Default/Managed Extension Settings' -> './.config/google-chrome/Default/Managed_Extension_Settings'
renamed './.config/google-chrome/Default/Secure Preferences' -> './.config/google-chrome/Default/Secure_Preferences'
renamed './vmware/windows_10_x64/Windows 10.vmxf' -> './vmware/windows_10_x64/Windows_10.vmxf'
I’m fairly new to Linux (I’m sure you can tell), and I was wondering if someone more experienced could help me restore the filenames to what they were before I ran the script – just undo all the changes the script made. Thanks.