Timeline for How to replace spaces in file names using a bash script
Current License: CC BY-SA 4.0
30 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 6, 2023 at 10:26 | history | edited | Rune Kaagaard | CC BY-SA 4.0 |
It seems safer and more consistent to use "." as the example dir instead of "/tmp/".
|
Apr 1, 2021 at 8:35 | history | edited | Somasundaram Sekar | CC BY-SA 4.0 |
added 4 characters in body
|
Jul 11, 2019 at 16:08 | comment | added | phantom-99w |
@CpnCrunch, as the answer says, the utility is sometimes named prename . I found "prename" using Yum and it works as advertised. Now, writing a portable script, that is a whole different matter...
|
|
Mar 14, 2018 at 18:32 | comment | added | Dennis Williamson | The question is tagged linux and the issue of OS X installation has been addressed in previous comments. | |
Mar 14, 2018 at 8:12 | comment | added | Sergiu |
you cannot use rename on macOS unless you explicitly install it
|
|
Sep 4, 2017 at 10:39 | comment | added | Mohamed El-Nakeep | On OS X, first do this: stackoverflow.com/a/15003450/2008463 $brew install findutils rename $ alias find=gfind | |
Jan 18, 2017 at 14:52 | comment | added | Wilf |
rename seems to be the most incompatible script (fedora don't work, custom ubuntu half does) - could someone please include a list of working rename versions....
|
|
Jan 6, 2017 at 21:05 | history | edited | the Tin Man | CC BY-SA 3.0 |
edited for readability
|
Dec 14, 2016 at 11:32 | comment | added | golimar |
@CpnCrunch Same in RHEL 6.2 and Cygwin (rename --version says rename from util-linux 2.x.x , but a good tool for mass renaming anyway
|
|
Nov 4, 2015 at 20:07 | comment | added | Dennis Williamson | @CpnCrunch: The Perl script is very short and various versions are available on CPAN and elsewhere. | |
Nov 4, 2015 at 3:03 | comment | added | CpnCrunch | This doesn't work on Centos 7, as the rename command is completely different (it's a binary, not a perl script), and it doesn't accept data from stdin. | |
Mar 7, 2015 at 23:06 | comment | added | Dennis Williamson |
@FredConcklin: In GNU find . (the current directory) is the default search root.
|
|
Mar 7, 2015 at 17:31 | comment | added | user284244 | You forgot to specify . in the find command so there is no directory root to search. | |
Sep 24, 2014 at 16:49 | comment | added | Dennis Williamson |
@PhysicalChemist: You have single quotes inside your alias. Try alias space_to_under='find . -depth -name "* *" -execdir rename "s/ /_/g" "{}" \;' or alias space_to_under='find . -depth -name "* *" -execdir rename '\''s/ /_/g'\'' "{}" \;'
|
|
Sep 24, 2014 at 16:42 | comment | added | PhysicalChemist |
Sure. Bash Profile Alias: alias space_to_under='find . -depth -name "* *" -execdir rename 's/ /_/g' "{}" \;' and the Terminal Output after sourcing -bash: alias: /_/g "{}" \;: not found
|
|
Sep 24, 2014 at 16:28 | comment | added | Dennis Williamson | @PhysicalChemist: Can you be more specific? | |
Sep 24, 2014 at 16:18 | comment | added | PhysicalChemist |
Note that the command has a trailing ; issue when aliased in a bash profile. But it is totally fine in a bash profile function.
|
|
Sep 16, 2014 at 17:47 | review | Suggested edits | |||
Sep 16, 2014 at 18:55 | |||||
Aug 8, 2014 at 17:54 | comment | added | loeschg |
If you're running this on OS X, you'll need to brew install rename
|
|
Jul 24, 2014 at 11:45 | history | rollback | Dennis Williamson |
Rollback to Revision 2
|
|
S Jul 23, 2014 at 20:46 | history | suggested | CommunityBot | CC BY-SA 3.0 |
use sed to remove spaces from filenames
|
Jul 23, 2014 at 20:41 | review | Suggested edits | |||
S Jul 23, 2014 at 20:46 | |||||
Apr 26, 2010 at 18:33 | comment | added | Michael Krelin - hacker | Of course you're not going to get a performance boost from it. It's more about using the right tool. And this whole question is about micro-optimizing more or less. Isn't it fun, after all? ;-) | |
Apr 26, 2010 at 15:51 | comment | added | Dennis Williamson |
Micro-optimization. In my tests there was negligible difference in speed. time for i in {1..2000}; do echo "a b c d [repeated to a length of 320 characters]" | perl -pe 'y/ abcdefghi/_ABCDEFGHI/' >/dev/null; done compared to 's/ /_/g; s/a/A/g; s/b/B/g; s/c/C/g; s/d/D/g; s/e/E/g; s/f/F/g; s/g/G/g; s/h/H/g; s/i/I/g' . Of course, the transliteration command has its advantages, but so does the substitute command.
|
|
Apr 26, 2010 at 14:45 | comment | added | Michael Krelin - hacker |
Oh, I've just read the rename manpage (I didn't know the tool) and I think you can optimize your code by changing s/ /_/g to y/ /_/ ;-)
|
|
Apr 25, 2010 at 22:25 | history | edited | Dennis Williamson | CC BY-SA 2.5 |
added another version
|
Apr 25, 2010 at 20:53 | comment | added | Michael Krelin - hacker | hmm.. Dennis, what would happen if you have "a a", "a a/b b" directories? Wouldn't it try to rename "a a" to "a_a" and then "a a/b b" (which doesn't exist anymore) to "a_a/b_b"? | |
Apr 25, 2010 at 20:01 | comment | added | Jürgen Hötzel | No need for two steps: Use Depth-first search: find dir -depth | |
Apr 25, 2010 at 19:56 | vote | accept | armandino | ||
Apr 25, 2010 at 19:37 | history | answered | Dennis Williamson | CC BY-SA 2.5 |