Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-05-2005, 01:37 PM   #1
Registered: Dec 2004
Posts: 245

Rep: Reputation: 30
Renaming files

Hello - This is a possibly tricky question.

I have downloaded a bunch of files with d4x into a folder. The files are not there! Actually they are all there, but instead of being foo.mpg they are .foo.mpg, and therefore hidden from konqueror. Now, how can I rename all of these at once?
Old 12-05-2005, 02:08 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Normally, you could use ls $dir but, you need to use ls -a $dir to get the hidden files.
Try it first and if it looks good, remove the echo from this line...
echo mv -v "$dir/$i" "$dir/$j"

Edit: I may as well beat everyone to shortening the sed.


   echo "Usage: $0 Directory_Name"
   exit 1;

test -d "$1" || usage

ls -a $dir | \
while read i; do
j=`echo -e "$i" | sed -e 's/^.//g'`
echo mv -v "$dir/$i" "$dir/$j"

Last edited by homey; 12-05-2005 at 02:19 PM.
Old 12-05-2005, 04:13 PM   #3
Registered: Dec 2004
Posts: 245

Original Poster
Rep: Reputation: 30
I got the part about ls -la to see the files, but it really takes all that code to rename a bunch of files from .foo.mpg to foo.mpg?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming multple files.... maginotjr Slackware 4 06-04-2006 10:09 AM
Renaming lots of files Tuttle Linux - General 4 11-18-2004 11:15 AM
renaming files script. xushi Programming 4 10-10-2004 08:06 AM
Renaming files as they are uploaded Cr4wford Linux - Software 1 04-26-2004 03:41 PM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 01:16 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:28 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration