PDA

View Full Version : [SOLVED] .hidden files persistenly refuse to be copied



minigilani
August 27th, 2011, 11:32 PM
Here's the deal, LAMP server running Natty on Amazon EC2. An hour or so of bumping around and i finally manage to migrate my client's old shared-hosting-powered, cPanel-controlled, Joomla! Website to the instance.

Only, the site's broken. Joomla! requires that its .htaccess file in place before it can rewrite URL's properly. I checked my copied files .htaccess wasn't there. I went back to the original file, .htaccess was there, along with .smileys and a few other files, but i can't seem to cp or rsync them. I googled, but couldn't find much help.

I know .hiddenfiles should be copied with cp, yes, i did "ls -A", and no it's my ftp client being set to hide .hiddenfiles because i'm using ssh.

I just wanna sleep.

SeijiSensei
August 28th, 2011, 02:13 PM
rsync -a copies hidden files. For best results, run it as root with sudo unless you're certain about your permissions on both source and target.

CharlesA
August 28th, 2011, 04:20 PM
Also keep in mind how you are copying the files - I've found that if you use /path/to/files/* it won't copy hidden files since they start with a "."

Using /path/to/files/ works fine tho.

sisco311
August 28th, 2011, 04:38 PM
In bash you can enable the dotglob option.


[sisco@acme xtmp]$ mkdir foo
[sisco@acme xtmp]$ cd foo
[sisco@acme foo]$ echo *
*
[sisco@acme foo]$ shopt -s failglob
[sisco@acme foo]$ echo *
bash: no match: *
[sisco@acme foo]$ > file
[sisco@acme foo]$ > .hidden
[sisco@acme foo]$ echo *
file
[sisco@acme foo]$ shopt -s dotglob
[sisco@acme foo]$ echo *
file .hidden

CharlesA
August 28th, 2011, 05:04 PM
Oh cool, I didn't know that. Thanks!

SeijiSensei
August 28th, 2011, 10:22 PM
Also keep in mind how you are copying the files - I've found that if you use /path/to/files/* it won't copy hidden files since they start with a "."

Using /path/to/files/ works fine tho.

I find using the dot rather than the star generally avoids these problems. I don't think * matches .something.

I find something like



cd /path/to/source
rsync -av . /path/to/target


copies all the files.

CharlesA
August 28th, 2011, 10:43 PM
I find using the dot rather than the star generally avoids these problems. I don't think * matches .something.

I find something like



cd /path/to/source
rsync -av . /path/to/target


copies all the files.

Yeah, the * only matches files that don't begin with a dot. The . in the above command copies the current directory, doesn't it?

SeijiSensei
August 29th, 2011, 01:21 PM
Yeah, the * only matches files that don't begin with a dot. The . in the above command copies the current directory, doesn't it?

Yes, it matches all files and subdirectories in the current directory including dot files.

sisco311
August 29th, 2011, 04:11 PM
Yes, it matches all files and subdirectories in the current directory including dot files.

No, it does not match anything. It is a hard link to the current directory.

Every directory contains at least two hard links. .. is a hard link to the parent directory and . is hard link to the directory itself.

For example: /home/user/. is a hard link to /home/user and /home/user/.. is a hard link to /home.

SeijiSensei
August 30th, 2011, 01:34 AM
No, it does not match anything. It is a hard link to the current directory.

Okay, but when listing and copying directories, the dot functions as if it matches everything. Commands like "ls .", "cp .", and "rsync -av . /path to target" result in all files being listed or copied regardless of whether they are hidden. That may be because it's a hard link to the directory itself, but in the context of the question raised here, it answers the OP's request for a method to copy all files, both hidden and non-hidden, in a directory.

sisco311
August 30th, 2011, 01:51 AM
"On a UNIX/LINUX system, everything is a file; if something is not a file, it is a process." :)

In this context, . is not a special character, it's a filename or more precisely a directory name.

By default, rsync operates recursively. In case of ls you have to use its -a option to list the hidden files, in case of cp you have to use its -r option to copy the content of a directory recursively.

minigilani
September 5th, 2011, 02:37 AM
cd /path/to/source
rsync -av . /path/to/target



This worked awesomely for me, thanks SeijiSensei!


Every directory contains at least two hard links. .. is a hard link to the parent directory and . is hard link to the directory itself.

For example: /home/user/. is a hard link to /home/user and /home/user/.. is a hard link to /home.

sisco311 thanks for clearing that up! I'll keep this in mind from now on!

Problem solved!8-)