LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-12-2008, 09:20 PM   #1
keith2045
Member
 
Registered: Feb 2005
Location: Missour, USA
Posts: 83

Rep: Reputation: 15
Copy folder with !


This is probably really easy to do but i cant seem to figure it out. I'm trying to copy a folder via the command line that has an ! in it, when i put it in quotes i get this error
bash: !": event not found

Any suggestions?
 
Old 09-12-2008, 09:23 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613Reputation: 613
Code:
alucard@karrde:~$ mkdir hi!
alucard@karrde:~$ ls | grep hi
hi!
alucard@karrde:~$ mv hi! hi.
alucard@karrde:~$ ls | grep hi
hi.
works for me?

Code:
alucard@karrde:~$ echo $SHELL
/bin/bash
can try escaping it:

Code:
alucard@karrde:~$ mv hi. hi!
alucard@karrde:~$ mv hi\! hi.
alucard@karrde:~$ ls | grep hi
hi.
 
Old 09-12-2008, 09:27 PM   #3
keith2045
Member
 
Registered: Feb 2005
Location: Missour, USA
Posts: 83

Original Poster
Rep: Reputation: 15
Weird, i tried escaping and got an error. How about a folder with spaces, ex Hello World!
 
Old 09-12-2008, 09:33 PM   #4
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Did you quote all of the file/folder name?
 
Old 09-12-2008, 09:40 PM   #5
keith2045
Member
 
Registered: Feb 2005
Location: Missour, USA
Posts: 83

Original Poster
Rep: Reputation: 15
Yes, here is an example

cp "Ubnutu Image - Dont Use!" "Ubuntu Image"
bash: !": event not found

and

cp "Ubnutu Image - Dont Use\!" "Ubuntu Image"
cp: cannot stat `Ubnutu Image - Dont Use\\!': No such file or directory
 
Old 09-12-2008, 09:58 PM   #6
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 130Reputation: 130
Quote:
jurgen@Selena:~$ ls u*
ubuntu image - don't use!
jurgen@Selena:~$ cp ubuntu\ image\ -\ don\'t\ use\! "buntu image"
jurgen@Selena:~$ ls bun*
buntu image
No problem here? It inserted those backslashes automatically so - unless you are simply making a typo - those could make a difference.
 
Old 09-12-2008, 11:04 PM   #7
keith2045
Member
 
Registered: Feb 2005
Location: Missour, USA
Posts: 83

Original Poster
Rep: Reputation: 15
Weird, i just opened nautilus and renamed it via gui

Thanks
 
Old 09-12-2008, 11:37 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 61
Some details. The ! character is the history character by default in csh, tcsh and bash. You have to escape it, as you do with other meta-characters, to ensure the shell does not think you mean to match something from the history list. You can escape with single quotes or backslash:

echo '! foo !'
echo \! foo \!

Whitespace is special in that it is used for word splitting in the word splitting phase. To prevent this, escape with any quoting mechanism (single or double quotes, backslash).

Bash will automatically escape white space when performing filename completion.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy folder problem zerocool22 Linux - Newbie 1 06-04-2008 04:53 AM
how to copy folder between machines deepika5 Linux - Newbie 5 04-17-2008 02:34 PM
copy content of the folder ashley75 Linux - General 6 04-16-2007 11:50 AM
Copy a folder to USB Aerolinux Linux - Hardware 3 02-22-2007 11:00 AM
Copy Home Folder seashell11 Ubuntu 3 08-11-2006 01:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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