Using cp to copy hidden files
Viewed k times. 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. What flag do I need to use? Improve this question. Cfinley 1, 3 3 gold badges 14 14 silver badges 20 20 bronze badges. More answers here, though they do not look as good; serverfault. Please, Eleven81, consider changing the accepted answer to that given by bruno pereira, because it avoids creating a new folder.
If not, let this comment be a warning to new readers to check also the other most voted answer. Add a comment. Active Oldest Votes. Improve this answer. Randy Orrison Randy Orrison 6, 2 2 gold badges 25 25 silver badges 24 24 bronze badges. This solution didn't work for me. It did not copy hidden files. I'm using CentOS release 6. Bruno's solution did the trick. Use -T no target per below for proper use. Answering a 7. Show 4 more comments.
Bruno Pereira Bruno Pereira 7, 1 1 gold badge 14 14 silver badges 16 16 bronze badges. Works well for me. Note that the '. It works, but, why? Can't find a reference to this in the manual. I think it works because normally, this would create a new folder with the name of the last folder in the first argument. However, since that name is. Technext The default globbing in bash does not include filenames starting with a. While on the other end with.
Show 13 more comments. TechnocratiK TechnocratiK 2, 1 1 gold badge 8 8 silver badges 2 2 bronze badges. Correct answer. Love it when you use the correct cmd flag for the one case. Not supported on all versions of cp , alas, but great when it is there. Doesn't work on mac : — Hariom Balhara. Show 2 more comments. PersianGulf PersianGulf 8 8 silver badges 10 10 bronze badges.
That's usefull when you want to copy just content without creating new directory inside destination. Especially when destination dir is mount point. It's setopt for zsh, in case anyone else is wondering.
Best option for me, although I use --progress to have more feedback on the whole process. Excellll Wink Saville Wink Saville 77 1 1 silver badge 1 1 bronze badge. This answer is incorrect in terms of the original question asked include hidden files : both cp -r as well as cp -a copy hidden files when cp It may be that this changed overtime.
DJCrashdummy unfortunately, I do not understand why you wrote your attention. After all, my solution takes into account the cases you write about. Regards — simhumileco. You could use rsync. In some circumstances it is more desirable to keep partially transferred files.
One more thing to note is that you need to remove the trailing slash behind the directory name. Copying file means you must have some space on the storage to store the copied files. To do this, we can use -l option.
It marked by the same inode, But please note, hardlinks cannot be created into directories. Same with its original file. There is another type of links called softlinks or symbolic links.
We use -s option to do this. Creating symlinks only can be done in current directory. Once I manage to be there, I can run cp -s command above. Its marked with arrow sign after the file name.
To do this, we can use -P option. When cp command found a file with symbolic links, it will copy the as is. Take a look at the sample below. The file type still a symbolic link.
Now we can do this with -L option. Basically, this is an opposite of -P option above. This is known from the file size. When we are going to copy a directory, we will use -r or -R option. But we can also use -a option to archive file. This will create an exact copy of files and directories including symbolic links if any.
By default, when copying activity is success, we will see a command prompt again. If you want to know what happen during the copying file, we can use -v option. This additional information will make us more sure about the copying activity. Then we edit it using vi, add some content and save it. Next, we see the file size has changed into 36 bytes. When we use -u option, combined with -v option to see what is being done, cp command will only copy a file s which is newer from destination directory.
Interactive mode will ask if the destination folder has already the file.
0コメント