LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-09-2008, 01:57 AM   #1
atari05
LQ Newbie
 
Registered: Jan 2003
Location: Michigan
Distribution: Linux Mint
Posts: 10

Rep: Reputation: 0
Question Finding a grave character (~)


Greetings all,

Quick question. I have been ripping cds and such and some of the tracks have questions marks in them and other "not so good in a file name" characters. Because of this, during the encoding process, instead of having a nice file name I have something like

M98765~v.ogg

Does anyone know of a way to actually run a find and have it pick up the grave (~) character?

I would like to rename these files (and directories) to something a more...how would you say....human readable :P.
 
Old 01-09-2008, 02:44 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
In bash, the '~' character is a shortcut for your home directory. If you need a literal '~' character, then you have to escape it with a backslash: '/~'. The same goes for most other "illegal" filename characters, such as parentheses, quote marks, exclamation points, and especially spaces.

Also, don't forget tab-completion. Hitting the tab key when typing a filename will autofill whatever names it sees that match what you've already typed. It can often help when matching those oddball characters.

When using a file with illegal characters in a command, you can either use the backslash-escape as above, or enclose the whole filename in quotation marks so that bash will see the thing as single unit.

I suggest you get in the habit of keeping your filenames clean. Use underscores or hyphens instead of spaces, and leave out illegal characters as much as possible. It will save you some frustration. I also personally keep most of my filenames in lowercase letters only, since Linux is case-sensitive, but that's not strictly necessary.
 
Old 01-09-2008, 02:50 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
in bash
Code:
for files in *~*.ogg
do
 mv "$files" "${files/\~/}"
done
See my sig for resources to learn bash
 
Old 01-09-2008, 02:54 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Oh, and there's a nice perl rename command (it should be available if you have perl installed) that's handy for cleaning up file names. It uses the same substitution syntax as sed. I've been having fun learning how to use it recently.

rename "s/~/-/g" *

...will replace all the tildes in filenames with simple hyphens in the current directory.
 
  


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
Grave hardware problems Gins Linux - General 13 01-06-2008 09:29 AM
LXer: URGENT! You, your relatives, and friends are in grave danger! LXer Syndicated Linux News 3 10-12-2007 06:28 PM
Any grave security issues with Xen? Peufelon Linux - Security 3 04-11-2006 08:19 AM
accent grave ague in kde suse 10!! how??? Randall Slack SUSE / openSUSE 6 01-19-2006 01:47 PM
grave locale problems with mandriva 10.2 exa Mandriva 1 10-04-2005 02:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:08 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