Wednesday 25 April 2018

unix - How to copy with cp to include hidden files and hidden directories and their contents?


How can I make cp -r copy absolutely all of the files and directories in a directory


Requirements:



  • Include hidden files and hidden directories.

  • Be one single command with an flag to include the above.

  • Not need to rely on pattern matching at all.


My ugly, but working, hack is:


cp -r /etc/skel/* /home/user
cp -r /etc/skel/.[^.]* /home/user

How can I do this all in one command without the pattern matching? What flag do I need to use?



Answer



Don't specify the files:



cp -r /etc/skel /home/user



(Note that /home/user must not exist already, or else it will create /home/user/skel.)


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...