Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am fairly new to Linux and still coming to know the shell.
I have a Music folder that has album folders in it. Inside of each folder are the songs and a .jpg that is sometimes named folder.jpg and sometimes named .folder.jpg.
I would like to use the shell to issue a command to go through all the folders in the Music folder and rename anything named .folder.jpg to folder.jpg.
I am sure I must be able to do this with the shell.
it would be great help if you could give me complete command for clearing/removing , (commas) ' (single quotes) and () (braces) from filenames & foldernames in current folder and all its sub folders.
it would be great help if you could give me complete command for clearing/removing , (commas) ' (single quotes) and () (braces) from filenames & foldernames in current folder and all its sub folders.
thanks a lot.
e.g.
for i in `find . -name "*,*"`; do mv $i ${i/,/}; done
you can replace the two commas with the special character.
The following perl script descents all folders and renames the files that contain illegal characters accordingly.
enter the following in 'rename.pl', make it executable 'chmod u+x rename.pl' and execute it
Code:
#!/usr/bin/perl
use strict;
sub processDir
{
my $dir=shift;
opendir(DIR, $dir);
my @files=grep {! /^\.\.?$/} readdir(DIR);
closedir(DIR);
foreach my $file(@files)
{
if(-d $file)
{
processDir("$dir/$file");
}
my $newfile=$file;
$newfile=~ s/[,& '\(\)]/_/g; #Search for ',', '&', ' ', "'", '(', ')' in filenames and replace them with underscores.
if( $newfile ne $file )
{
print "Renaming \"$dir/$file\" to \"$dir/$newfile\"\n";
system("mv \"$dir/$file\" \"$dir/$newfile\"");
}
}
}
my $dir=shift;
if(!defined($dir))
{
$dir=".";
}
processDir($dir);
next call it with './rename.pl <directory>' and it should run through..
hi rahulk, i guess i need to run your command as many times as there are directories? ~ and there are many hundreds.
thanks rhoekstra, your perl script worked nicely, it would only go 2 levels down in directory structure, but my deep directories, sometimes as much as 10 levels deep.
and it give me this error if there are too many files in a directory:
Quote:
-bash: ./renamer.pl: /usr/bin/perl: bad interpreter: Argument list too long
To make it go deeper.
The last error I don't understand quite well..
And to call the program, don't enter '*' on the command line. Just call renamer.pl with the directory to process. It'll find all the files within.
If it needs to process all the files in the current directory, pass along '.' as parameter, or nothing at all (it'll default to process the current directory.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.