- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using * doesn't copy all files.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 08:41 AM
11-15-2005 08:41 AM
cp /home/user/*
I get:
cp: cannot access /home/user/*: No such file or directory
Even though I know the files are there. I have tried substituting *.* and .* to no avail, they both give the same message. Is there any way to pick up all of these files using a single command?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 09:01 AM
11-15-2005 09:01 AM
Solutioncp /home/user/.[A-Za-z]* destination_path
If you only put .*, it will try to grab . and .. also and give you error s about needing the -R option. Of course, if you have directory names that are hidden (named .something) that you want copied too, you need the -R option anyway.
Jeff Traigle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 09:38 AM
11-15-2005 09:38 AM
Re: Using * doesn't copy all files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 11:02 AM
11-15-2005 11:02 AM
Re: Using * doesn't copy all files.
Now be VERY careful about using various incantations of the . and the * as these filename matching options can have unexpected consequences. Whenever I am in doubt about using filename matching characters, I will put the word "echo" in front of the command to see what will actually happen. Something like this:
echo cp /home/user/*.
This is especially important if you are removing files (rm). You might be tempted to use .* which will match filenames that start with a dot followed by zero or more characters. This is very important: there are two files that sysadmins often forget about: these are . and .. which are special files called directories. These are the current directory and the parent directory. To see what .* matches, just do this:
echo /home/user/.*
You'll see a huge number of files and directories because .. was matched and you are seeing /home contents. You can imagine the disaster that would happen if you typed: rm -rf /home/user/.* (every file and directory in /home will be removed).
cp (and commands like rm mv ls) do not know anything special about *. This (and other special characters) are pattern matching characters used by the shell to expand into matching filenames. That's why using the echo command in front of a command line with filename patterns is so useful. To see this at work:
echo '*'
echo *
The first returns a * because the single quotes remove the special meaning of * while the second line asks the shell to replace * with a set of matching filenames.
An easy to remember incantation to pickup the . files (without picking the parent directories with .*) is to use .??* which means: matching filenames must start with a dot, followed by at least 2 additional characters. This prevents .. from matching (it's only 2 chars and the mask requires 3 or more). But this mask will miss files like .1 .2 .a .b and so on.
After all this, you can use the -r option for cp and eliminate any filename matching problems:
cp -r /home/user /someplace_else
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 08:50 PM
11-15-2005 08:50 PM
Re: Using * doesn't copy all files.
you can try with tar:
cd fromdir ; tar cf - . | ( cd todir ; tar xf - )
Regards,
Borislav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 08:57 PM
11-15-2005 08:57 PM
Re: Using * doesn't copy all files.
fistly, You have to login root user
#cp -rp /home/user/. {/destnation dir}
good luck~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2005 09:16 PM
11-15-2005 09:16 PM
Re: Using * doesn't copy all files.
find /home/user -type f -exec cp {}
It will do.
cp /home/user/[A-Za-z]* will also require -R when you are having directory there in /home/user/
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 06:07 AM
11-16-2005 06:07 AM
Re: Using * doesn't copy all files.
for f in $(ls -a /home/user/)
do
cp $f Destination
done
I probably would have forgotten the -a but for this thread, and in trying it out, it looks like you also need -R if there are subdirectories.
If there's a really large number of files, is there a limit to the number of characters that * can expand into?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2005 06:45 AM
11-16-2005 06:45 AM
Re: Using * doesn't copy all files.
find /home/user -print | cpio -pvmud /target_dir
To get just the ones that start with "."
find /home/user -name ".*" -print | cpio -pvmud /target_dir
This method includes subdirectories and will create said subdirectory structure under the target dir.
wayne
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2005 12:03 AM
11-21-2005 12:03 AM
Re: Using * doesn't copy all files.
so instead of '/home/user/*' you use '/home/user', at least with GNU-cp this works.