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 03-13-2012, 05:29 PM   #1
Master_CAPS
Member
 
Registered: Mar 2012
Location: I live at ::1 usually...
Distribution: Yes.
Posts: 55

Rep: Reputation: Disabled
Anything with a '!' as part of the name, "breaks" the terminal (how do I linux?)


In windows my webserver had a lot of files like (!photo, !uploads etc...) the ! infront of of the file names kept it at the top (my files in windows are listed in alphabetical order and ! is over numbers and letters)

So I cant do a "cd !photos" or "chmod !photos" or anything because I aassume the "!" in linux terminal acts as an operator or argument of some sort... So is there some escape character to use with my commands without renamning everything?

here is what I get (some things ommited):
Code:
Satellite /var/www $ dir
bg.png		       index.html	photos.php     style.ie7.css
Files.html	       index.html~	script.js      test.php~
images		       Iphonepage.html	style.css      uploader.php
index-for-iphone.html  !photos		style.ie6.css  uploads
Satellite /var/www $ cd !photos
bash: !photos: event not found
Satellite /var/www $

Last edited by Master_CAPS; 03-13-2012 at 05:32 PM. Reason: Visual elements
 
Old 03-13-2012, 05:36 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,978
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Try cd \!Photos

! to bash is a special character, and need to be escaped.
 
1 members found this post helpful.
Old 03-13-2012, 08:13 PM   #3
Master_CAPS
Member
 
Registered: Mar 2012
Location: I live at ::1 usually...
Distribution: Yes.
Posts: 55

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by Tinkster View Post
Try cd \!Photos

! to bash is a special character, and need to be escaped.
Works great, but this also works too.
Code:
cd '!photos'
 
Old 03-14-2012, 11:01 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
In interactive terminals in bash "!" is used for history substitution. When the line is executed it is replaced by the contents of the previous command.

To work around it, you need to hard-escape it with either a backslash or single quotes. Double quotes still allow it to expand, however.

You can also disable history expansion with "set +H". This might be the most convenient option if you don't ever use it. Since the modern shell now provides other ways to access history (starting with the up arrow), most modern users don't need it or even bother to learn how it works (I certainly never did). Add the line to your bashrc or other start-up file to make it permanent.

Check out the HISTORY and QUOTING sections of the bash man page for more details. There are also a handful of shell options/environment variables that affect how history expansion behaves.

Last edited by David the H.; 03-14-2012 at 11:02 AM.
 
Old 03-15-2012, 01:09 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,269

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Also, at the higher level, try using '_' instead of '!'.
 
Old 03-15-2012, 11:40 AM   #6
DavidMcCann
Senior Member
 
Registered: Jul 2006
Location: London
Distribution: CentOS, Salix
Posts: 3,075

Rep: Reputation: 789Reputation: 789Reputation: 789Reputation: 789Reputation: 789Reputation: 789Reputation: 789
More generally, the rules for Unix filenames are
1. Start with a letter, number, or under-score "_"
2. Only include letters, numbers, under-scores, hyphens, or full stops. (No spaces!)

The GUI will cope with most things, but CLI tools get confused by exotic names.
 
Old 03-15-2012, 01:34 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
To be fair, there aren't really any hard-and-fast "rules" for file naming; just recommended common practices.

Posix-based filesystems support everything except the null byte (ascii 000) and the forward slash (ascii 057); the latter being the directory separator. So there's no technical reason for avoiding any character.

But as this topic demonstrates, most shells treat various non-alphanumeric characters as special, so it's usually a good idea to limit your filenames to basic ascii, and generally avoid all whitespace and punctuation marks outside of the period, underscore, and dash. To keep you from having to worry about escaping everything all the time.

Another reason to avoid unusual names is that it can sometimes be difficult to input non-keyboard-supported characters. Have you ever tried manipulating filenames in Japanese, in a non-X console, meaning there's no IME access, for example? It's certainly not fun, I can tell you. That's why I always make sure my filenames stick to the above pattern. (Or partially, at least. As long as the filename contains at least one unique ascii substring, you can generally still use shell globbing to match it.)
 
  


Reply

Tags
command


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 set the font-size for "xterm" terminal-emulator (running "bash" shell) ajaygarg Linux - Desktop 1 03-09-2012 12:38 PM
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 08:36 AM
LXer: Fixing Linux, Part One: "The Space Between" LXer Syndicated Linux News 6 08-06-2008 08:19 AM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM


All times are GMT -5. The time now is 06:07 PM.

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