[SOLVED] Anything with a '!' as part of the name, "breaks" the terminal (how do I linux?)
Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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):
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 !photosbash: !photos: event not found
Satellite /var/www $
Last edited by Master_CAPS; 03-13-2012 at 05:32 PM.
Reason: Visual elements
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.
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.)