next code doesnt work because of spaces in file names, How to fix?
IFS = '\n' for name in `ls ` do number=`echo "$name" | grep -o "[0-9]\{1,2\}"` if [[ ! -z "$number" ]]; then mv "$name" "./$number" fi done
Use quotation marks when specifying long filenames or paths with spaces. For example, typing the copy c:\my file name d:\my new file name command at the command prompt results in the following error message: The system cannot find the file specified.
It's not very common in Linux to handle filename with spaces but sometimes files copied or mounted from windows would end up with spaces. While it is not recommended to have file names with spaces, let's discuss how to manage filename with spaces in a Linux system.
It's allowed but it's really, really annoying. There is no reason for it. Don't do it. You can also create a files named -rf ~ (use touch -- "-rf ~" ), but I wouldn't recommend it.
Just don't use command substitution: use for name in *
.
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