LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 02-02-2005, 12:30 AM   #1
stefanlasiewski
Member
 
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Rep: Reputation: 16
SOLVED: 'cp -rv .*' recurses into the parent directory??? [In bash, not in zsh]


Hey all,

I'm testing out SuSE Pro 9.1 , and noticed some very odd behavior with 'cp'.

If I try to copy dotfiles, 'cp' recurses into '..' , which seems completely wrong. I can't replicate it on other Unixes (Trying on Solaris 8 with GNU ls, Redhat 9, etc).

Anyone else see this? I'm not quite sure how I can copy multiple dotfiles with this bug.

Here's an example:

linux:/tmp # cp -rv /etc/skel/.* /tmp/

##### First, it does the correct thing, and copies the dotfiles:
`/etc/skel/./Documents/.directory' -> `/tmp/./Documents/.directory'
`/etc/skel/./.exrc' -> `/tmp/./.exrc'

##### But then it starts to go into /etc/skel/../ , which it shouldn't do.
`/etc/skel/../X11/fs/config' -> `/tmp/X11/fs/config'
`/etc/skel/../X11/twm/system.twmrc' -> `/tmp/X11/twm/system.twmrc'
`/etc/skel/../X11/xdm/Xresources' -> `/tmp/X11/xdm/Xresources'
`/etc/skel/../X11/xdm/README.security' -> `/tmp/X11/xdm/README.security'
`/etc/skel/../X11/xdm/Xaccess' -> `/tmp/X11/xdm/Xaccess'

##### Needless to say, my drive fills up within a matter of minutes.

This is with the folllowing version of cp:
linux:/tmp # cp --version
cp (coreutils) 5.2.1

Thanks all,

-= Stefan

Last edited by stefanlasiewski; 07-25-2005 at 06:43 PM.
 
Old 02-02-2005, 02:14 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Well, unfortunately .* includes .. which means it will and should recurse into the parent directory. The "." and ".." are actually just like any named directory. That is why we should always take care in doing anything like chmod -R .* or rm -rf .* or anything else of that nature because the system is going to do exactly what you asked it to do, for better or worse.
 
Old 02-02-2005, 03:36 PM   #3
stefanlasiewski
Member
 
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Original Poster
Rep: Reputation: 16
I'll have to disagree with you there. This only seems to be a problem on SuSe, or with a newer version of cp. There needs to be some way of copying multiple dotfiles, and you when creating a new user there needs to be a way to populate the home directory with the appropriate dotfiles.

Here's the behavior on Solaris 8, with the default cp

# cp --version
cp (GNU fileutils) 3.16
# cp -rv /etc/skel/.* /tmp/
/etc/skel/.profile -> /tmp/.profile
/etc/skel/.zprofile -> /tmp/.zprofile
/etc/skel/.zshenv -> /tmp/.zshenv
/etc/skel/.zshrc -> /tmp/.zshrc
#

Here's the behavior on RedHat Enterprise 3 (WS):

# cp --version
cp (coreutils) 4.5.3
# cp -rv /etc/skel/.* /tmp/
`/etc/skel/.bash_logout' -> `/tmp/.bash_logout'
`/etc/skel/.bash_profile' -> `/tmp/.bash_profile'
`/etc/skel/.bashrc' -> `/tmp/.bashrc'
`/etc/skel/.emacs' -> `/tmp/.emacs'
`/etc/skel/.gtkrc' -> `/tmp/.gtkrc'
`/etc/skel/.kde' -> `/tmp/.kde'
`/etc/skel/.kde/Autostart' -> `/tmp/.kde/Autostart'
`/etc/skel/.kde/Autostart/.directory' -> `/tmp/.kde/Autostart/.directory'
`/etc/skel/.zshrc' -> `/tmp/.zshrc'
#

SuSE is the only flavor where I have seen this behavior.
 
Old 02-02-2005, 04:08 PM   #4
stefanlasiewski
Member
 
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Original Poster
Rep: Reputation: 16
SOLVED: It's a shell globbing issue!

Oh! This is a shell issue.

With bash and ksh, .* recurses into '..'. With zsh, the default behavior is to NOT recurse into '..'.

It's a trick with the globbing of wildcards...

God, how confusing. But zsh saves the day again.
 
Old 02-02-2005, 04:12 PM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Glad you figured it out, I was just about to say that I see that behavior on all my systems, but I'm a bash user and am quite used to that at this point.
 
Old 02-02-2005, 05:36 PM   #6
stefanlasiewski
Member
 
Registered: Aug 2003
Location: Berkeley, California, USA
Distribution: Red Hat Enterprise Linux, Debian & Ubuntu
Posts: 92

Original Poster
Rep: Reputation: 16
Now I remember a time in 1997 when I ran 'rm -r ~/.*' and it erased a huge chunk of my system. GNU utils weren't very common, and Solaris cp didn't have a '--verbose' option-- the rm job just took a long time. I always thought that was a nasty bug in 'cp', but
now I'm more clear on what happened way back then...

I think it's time to revise my habits with using '.*'.

Dang...

Last edited by stefanlasiewski; 02-02-2005 at 05:45 PM.
 
  


Reply



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 check if a parent directory is a symbolic link compnovice Linux - Newbie 11 10-06-2005 05:59 PM
.htaccess restricting parent directory Braytac Linux - Networking 2 05-26-2005 05:27 PM
java - parent directory problem ludeKing Programming 8 10-07-2004 07:25 PM
List only the parent directory scottrell Linux - General 6 11-07-2003 09:10 AM
mv the contents of one directory to the parent directory warkrime Linux - Newbie 4 07-14-2003 07:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 02:31 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
Open Source Consulting | Domain Registration