With all the splintered discussions about Linux around here, I thought perhaps we could have a thread dedicated to all things Linux. Whether you're a new Linux user, or someone considering installing Linux, or have specific questions or solutions about a Linux feature or program, how about posting here? I'll start by pasting in some code I posted in a totally non-computer related thread!
The following bash code will replace spaces in file names with underscores:
My advice is that you try it first in a temporary directory with copies of files, just to verify for yourself that it works as expected. Also, if you're unsure what any part of it does, feel free to ask.
Edited to change how new forum software displays code blocks.
The following bash code will replace spaces in file names with underscores:
Code:
#!/bin/bash
ls > /tmp/current_files
mv /tmp/current_files ./current_files
cat current_files | tr ' ' '_' > current_files_new
FileCount=$(wc -l current_files | awk '{print $1}')
count=1
while [ "$count" -le "$FileCount" ]
do ReadAwk="FNR=="$count
OldName=$(awk $ReadAwk current_files)
NewName=$(awk $ReadAwk current_files_new)
mv "$OldName" "$NewName" > /dev/null 2>&1
count=$(($count+1))
done
rm current_files
rm current_files_new
exit 0
My advice is that you try it first in a temporary directory with copies of files, just to verify for yourself that it works as expected. Also, if you're unsure what any part of it does, feel free to ask.
Edited to change how new forum software displays code blocks.
Last edited: