Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am often saving documents from my Windows-using coworkers, and the filenames usually contain spaces.

For example, I'm always renaming

Important CEO Spreadsheet v2.xls

to...

Important_CEO_Spreadsheet_v2.xls

Is there a way to script the Save As dialog box to automatically detect whitespace and replace it with underscores?

share|improve this question
    
If this is something that can't be addressed at the operating-system level, and must instead be addressed at the application-level, then this might not be answerable. –  CEMcFarland Feb 16 '12 at 21:15

1 Answer 1

I can't think of anything that would change that in the box but you could run:

rename 's/ /_/g' *.xls

... in the directory that these are being saved to. You could save that as an alias in ~/.bash_aliases like: alias underscore="rename 's/ /_/g' *.xls" and then just run underscore.

Or you could create a new shortcut/link on your desktop that did something similar. It would probably need to run through Bash so you'd have a command like:

bash -c "cd yourXlsDir; rename 's/ /_/g' *.xls"
share|improve this answer
    
This would be helpful in the Downloads folder, since many documents are downloaded from web-based tools like the company wiki. However, I'm hoping for a solution that addresses the dialog box. –  CEMcFarland Feb 16 '12 at 21:14
    
@Oli: Instead of rename 's/ /_/' *.xls one could consider rename 's/ /_/g' *.txt because the g would take care of more than one space in the filename. Using -n with rename would do a dry run to see what the result will be without actually modifying anything. –  user25656 Feb 17 '12 at 4:46
    
rename 's/ +/_/g' *.xls in case there are some files with more than one space between words. –  Sylwester Jun 21 '13 at 0:31
    
@Sylwester That's not needed as it's a global replace (it'll find it in the next scan) but it will replace each space with an underscore. Multiple concurrent underscores might be undesirable. –  Oli Jun 21 '13 at 1:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.