LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 03-12-2008, 05:23 PM   #1
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Rep: Reputation: 38
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
 
Old 03-12-2008, 05:46 PM   #2
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
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?
 
Old 03-12-2008, 05:52 PM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,847

Rep: Reputation: 128Reputation: 128
To copy directories, you need to use the -R flag;
Code:
cp -R .your_dir /your/destination
 
Old 03-12-2008, 06:17 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 67
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.
 
Old 03-12-2008, 07:59 PM   #5
JosephS
Member
 
Registered: Jun 2007
Distribution: Debian Jessie, Bunsenlabs
Posts: 586

Original Poster
Rep: Reputation: 38
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.
 
Old 03-12-2008, 08:02 PM   #6
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Did you try straight

cp -r .* backup

?
 
Old 03-12-2008, 08:13 PM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 67
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.
 
Old 01-02-2009, 04:48 PM   #8
Flimm
LQ Newbie
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 7

Rep: Reputation: 2
If you're copying all files and directories from one directory to another, and want to include hidden files and directories, do:

Code:
cp -rT /from /to
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.
  


Reply

Tags
cp, hidden


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make find exclude hidden files (.files) Rotwang Linux - General 2 08-08-2011 03:58 AM
hidden files Jeebizz Slackware 4 04-22-2005 07:18 PM
home directory files gone, hidden files remain Grasshopper Linux - Security 12 04-10-2005 08:23 PM
Hidden Files Alien18 Linux - Newbie 4 08-12-2004 09:38 PM
M$ CD w/ Hidden files???? trey85stang Linux - Newbie 3 05-04-2004 09:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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