Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
03-12-2008, 05:23 PM
|
#1
|
|
Member
Registered: Jun 2007
Distribution: Debian Squeeze
Posts: 445
Rep:
|
Can I cp hidden files?
Is there a way to copy hidden (.) files with cp?
I tried to tried quoting ''
and backslash \
It just says: omitting directory
Thanks
|
|
|
|
03-12-2008, 05:46 PM
|
#2
|
|
Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
I don't follow.
cp /home/user/.hidden /home/user/subdirectory/
or similar should work.
Can you paste the exact command and error message please?
|
|
|
|
03-12-2008, 05:52 PM
|
#3
|
|
Senior Member
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,843
Rep: 
|
To copy directories, you need to use the -R flag;
Code:
cp -R .your_dir /your/destination
|
|
|
|
03-12-2008, 06:17 PM
|
#4
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
The . at the start of a file does not affect your ability to copy it. . confers no special permissions - it is a convention by which some programs (e.g. ls, or file managers / file selectors) will omit files named starting with a . from "normal" listing, that is all. Note that the names "." and ".." are special - they mean the current directory and the parent to the current directory respectively.
If you cannot copy a file, it is probably for one of these reasons: - The file is not readable by user user (according to file permissions)
- The destination directory is not writable/readbale/executable by your user
- The decide to which you are trying to copy the file has insufficient space left
Less likely: - The extended file attributes of the destination directory are such that you cannot modify it
- The device to which you are trying to copy the file is mounted read-only. Note that Linux will often re-mount devices as read-only when a hardware problem is detected (.g. bad blocks on the device), so you might find a device is suddenly mounted read-only unexpectedly.
- The device to which you are trying to copy the file does not support the file name length or characters in the file name.
|
|
|
|
03-12-2008, 07:59 PM
|
#5
|
|
Member
Registered: Jun 2007
Distribution: Debian Squeeze
Posts: 445
Original Poster
Rep:
|
I added the -r option which I had forgot. That solved one of my problems.
I'm also trying to make a copy of all my . files and directories, but not having success:
bash-3.1$ cp -r '.*' backup
cp: cannot stat `.*': No such file or directory
bash-3.1$ cp -r \.* backup
cp: cannot copy a directory, `.', into itself, `backup/.'
cp: cannot copy a directory, `.', into itself, `backup/.'
cp: cannot copy a directory, `.', into itself, `backup/.'
cp: cannot copy a directory, `.', into itself, `backup/.'
It copies a lot of files and directories as well as backup into backup
Thanks.
|
|
|
|
03-12-2008, 08:02 PM
|
#6
|
|
Guru
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Rep: 
|
Did you try straight
cp -r .* backup
?
|
|
|
|
03-12-2008, 08:13 PM
|
#7
|
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
Usually, the pattern * will omit files and directories with a . at the start. However, you can set a shell option to change this. For example:
Code:
bash$ mkdir test
bash$ cd test
bash$ touch .hidden visible
bash$ echo *
visible
bash$ shopt -s dotglob
bash$ echo *
.hidden visible
This might be useful for what you are trying to do.
|
|
|
|
01-02-2009, 04:48 PM
|
#8
|
|
LQ Newbie
Registered: Dec 2008
Distribution: Ubuntu
Posts: 7
Rep:
|
If you're copying all files and directories from one directory to another, and want to include hidden files and directories, do:
Alternatively, you could do:
Code:
find /from -maxdepth 1 -execdir cp -r '{}' /to \;
To copy just the hidden files, do:
Code:
find /from -maxdepth 1 -name ".?*" -execdir cp -r '{}' /to \;
Last edited by Flimm; 01-02-2009 at 04:53 PM.
|
|
|
1 members found this post helpful.
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:12 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|