LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux > 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

Tags used in this thread
Popular LQ Tags ,

Reply
 
Thread Tools Search this Thread
Old 03-12-2008, 06:23 PM   #1
JosephS
Member
 
Registered: Jun 2007
Posts: 319
Thanked: 0
Can I cp hidden files?


[Log in to get rid of this advertisement]
Is there a way to copy hidden (.) files with cp?
I tried to tried quoting ''
and backslash \
It just says: omitting directory

Thanks
JosephS is offline  
Tag This Post ,
Reply With Quote
Old 03-12-2008, 06:46 PM   #2
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Thanked: 126
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?
billymayday is offline     Reply With Quote
Old 03-12-2008, 06:52 PM   #3
pwc101
Senior Member
 
Registered: Oct 2005
Location: UK
Distribution: Slackware
Posts: 1,709
Thanked: 99
To copy directories, you need to use the -R flag;
Code:
cp -R .your_dir /your/destination
pwc101 is offline     Reply With Quote
Old 03-12-2008, 07:17 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,495
Thanked: 6
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.
matthewg42 is offline     Reply With Quote
Old 03-12-2008, 08:59 PM   #5
JosephS
Member
 
Registered: Jun 2007
Posts: 319
Thanked: 0

Original Poster
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.
JosephS is offline     Reply With Quote
Old 03-12-2008, 09:02 PM   #6
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678
Thanked: 126
Did you try straight

cp -r .* backup

?
billymayday is offline     Reply With Quote
Old 03-12-2008, 09:13 PM   #7
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu (x86), Debian (PPC)
Posts: 3,495
Thanked: 6
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.
matthewg42 is offline     Reply With Quote
Old 01-02-2009, 05:48 PM   #8
Flimm
LQ Newbie
 
Registered: Dec 2008
Distribution: Ubuntu
Posts: 4
Thanked: 1
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 05:53 PM..
Flimm is offline     Reply With Quote

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 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 1 01-15-2008 04:42 PM
hidden files Jeebizz Slackware 4 04-22-2005 08:18 PM
home directory files gone, hidden files remain Grasshopper Linux - Security 12 04-10-2005 09:23 PM
Hidden Files Alien18 Linux - Newbie 4 08-12-2004 10:38 PM
M$ CD w/ Hidden files???? trey85stang Linux - Newbie 3 05-04-2004 10:00 PM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
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.
Advertisement
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Click Here to receive a complimentary subscription courtesy of LQ.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration