Skip to content

Instantly share code, notes, and snippets.

@mgcon
Created August 17, 2015 02:18
Show Gist options
  • Save mgcon/9d6300dd55817f2a5283 to your computer and use it in GitHub Desktop.
Save mgcon/9d6300dd55817f2a5283 to your computer and use it in GitHub Desktop.
replace spaces in file names with underscores
#!/usr/bin/perl
# replace spaces in all filenames with underscores
$dir = ".";
opendir(DIR, $dir) || die "Can't open $dir\n";
for (readdir(DIR)) {
next if $_ eq '.';
next if $_ eq '..';
next if $_ eq 'lost+found';
$newfile = $_;
$newfile =~ s/ /_/g;
rename $_, $newfile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment