LinuxQuestions.org
Help answer threads with 0 replies.
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 01-28-2011, 10:02 AM   #1
cwajin
LQ Newbie
 
Registered: Jan 2011
Posts: 1

Rep: Reputation: 0
Unhappy How to remove dot from file name


I have an issue with file names i.e. A..png
I want rename these to normal A.png

Files are under directory to directory almost 300+ directories & inside
these dir. files are located. Can anyone tell me how to resolve this.
tried many commands, not working no change
 
Old 01-28-2011, 10:16 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
You can try the find command to search for files recursively and apply a command using the -exec option, e.g.
Code:
find . -name \*..\* -exec rename "s/\.\././" '{}' +
The syntax of the rename command is that of debian/ubuntu systems, where rename is a perl script. For RedHat like systems the syntax is different, but based on the icon in your post, I assume you're running Ubuntu.

The statement above runs the rename command only once, with all the found files as arguments. If you get an 'argument list too long' error, change it to:
Code:
find . -name \*..\* -exec rename "s/\.\././" '{}' \;
that will run a rename command on one file at a time. Please, first try the rename command on a single file (without the find statement) to be sure it is the correct syntax for your system:
Code:
rename "s/\.\././" A..png
 
Old 01-28-2011, 10:20 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Generically, you use mv to rename files (move source filename to destination filename). To find all of the files of interest, you can use find. Algorithmically, you can change all instances of '..' to '.' in filenames. Putting all of that together into a bash script:
Code:
#! /bin/bash

for SOURCEFILE in $(find . -type f -name "*..png"); do
    DESTFILE=${SOURCFILE//../.}
    echo mv $SOURCEFILE $DESTFILE
done
Try this out, running from the top level directory containing the files you want to rename. When you are satisfied that it does what you want, remove the echo from the last command in the loop, and then re-run it to do the actual renaming.

--- rod.
 
  


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
How to remove all (dot) files without removing toplevel dir? mattengland Linux - Software 8 07-19-2011 03:57 PM
how to hide a file using file permissions in linux without using dot davender84 Linux - General 4 03-26-2009 01:13 AM
How to get file extension (without the dot) scls19fr Linux - General 11 08-21-2008 12:48 PM
Remove page advance when printing to a Oki ML 390 dot matrix OOsorio Linux - Newbie 0 05-19-2008 05:02 PM
useradd not accepting dot so i am not able to use dot in mail id hanu_raob Linux - General 5 05-13-2004 08:04 AM


All times are GMT -5. The time now is 01:56 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration