LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 12-05-2005, 01:37 PM   #1
TomalakBORG
Member
 
Registered: Dec 2004
Location: Maryland
Distribution: SuSE / Gentoo
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
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
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.

Code:
#!/bin/bash

usage()
{
   echo "Usage: $0 Directory_Name"
   exit 1;
}

test -d "$1" || usage
dir="$1"

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

Last edited by homey; 12-05-2005 at 02:19 PM.
 
Old 12-05-2005, 04:13 PM   #3
TomalakBORG
Member
 
Registered: Dec 2004
Location: Maryland
Distribution: SuSE / Gentoo
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?
 
  


Reply


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


All times are GMT -5. The time now is 03:53 AM.

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