Visit Jeremy's Blog.
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-24-2011, 05:54 PM   #1
LQ Newbie
Registered: Dec 2011
Posts: 4

Rep: Reputation: Disabled
Removing # from file names

So I would like to remove the '#' symbol from all my file names. I tried the following but that didn't work. I think I might be using the wrong escape character.
Old 12-24-2011, 06:14 PM   #2
LQ Newbie
Registered: Dec 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
Figured it out. Thank you.

rename 's/\#//' *
Old 12-25-2011, 05:59 AM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
Glad you worked it out. Please mark the thread as solved.

But for a bit of clarification, the command you used is actually the perl-based prename script, which is linked to rename in many debian-based distributions through /etc/alternatives. It's very handy, but not every system has it installed.

Since the perl syntax uses regular expressions, targeting individual characters is probably better done using character classes:
rename 's/[#]//g' *
Adding "g" (for "global") at the end tells it to replace all instances of that character (or characters; class brackets can hold lists or ranges) in the line, otherwise it only replaces the first one found.

And two more polite suggestions:

The topic of renaming files comes up regularly. Please try to do a few searches of the archives and/or web before posting common questions like this.

Finally, please use [code][/code] tags around your code and data, to preserve formatting and to improve readability.

Last edited by David the H.; 12-25-2011 at 06:02 AM.


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
Bash: bash file names are different than openbox trash file names whatthefunk Programming 4 02-15-2011 01:52 AM
[SOLVED] How to changing same file names by their directory names? bayaraa_u Linux - General 3 04-09-2010 08:26 AM
/bin/tar: Removing leading `/' from member names guarriman Linux - General 16 02-09-2010 08:19 PM
/bin/tar: Removing leading `/' from member names IFeelYourPain Linux - General 11 12-01-2007 02:32 PM
RHEL3 - removing disks shifts LVM dev names downward? QuantSuff Linux - Server 2 06-04-2007 11:58 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 AM.

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