- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: cp -p not working
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
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
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
07-08-2016 12:49 AM
07-08-2016 12:49 AM
cp -p not working
Hello,
currently, I'm using HP-UX 11.31.
I would like to copy some of the files, which was generated from 1st Apr to 31st Apr from root user.
I tried with below command but it gives me usage of cp command,
cp -p `ls -lrt |egrep -i "Apr ( [1-9]|1[0-9]|2[0-9]|3[0-1] )"|egrep -v "2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2010 | 2011 | 2012 | 2013 | 2014 | 2015" | grep root | awk '{print $9}'` /tmp/logs/root/
output,
Usage: cp [-f|-i] [-p] [-S] [-A] [-e warn|force|ignore] source_file target_file
cp [-f|-i] [-p] [-S] [-A] [-e warn|force|ignore] source_file ... target_directory
cp [-f|-i] [-p] [-S] -R|-r [-A] [-e warn|force|ignore] source_directory ... target_directory
cp -R[-H | -L | -P] [-f|-i] [-p] [-S] [-A] [-e warn|force|ignore] source_file ... target
cp -r[-H | -L | -P] [-f|-i] [-p] [-S] [-A] [-e warn|force|ignore] source_file ... target
I think I'm doing something wrong with command.
Anyone please help me where I went wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 04:46 AM
07-08-2016 04:46 AM
Re: cp -p not working
> I think I'm doing something wrong with command.
"cp" apparently thinks so, too.
> Anyone please help me where I went wrong.
With my weak psychic powers, I can't see the output of your complex
"ls" + "egrep" + "awk" pipeline, so I can't see what you're feeding into
"cp".
> [...] ls -lrt [...]
"rt"? Why do you care about the order?
> I would like to copy some of the files, which was generated from 1st
> Apr to 31st Apr [...]
There are "find" options which are useful for this kind of thing
which don't require you to parse output from "ls -l". Note that parsing
the output of "ls -l" is probably more difficult than you think.
man find
A forum or Web search should find many examples of "find" used this
way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2016 10:53 PM
07-08-2016 10:53 PM
Re: cp files in a date range
>it gives me usage of cp
Typically pipelines suffer ultraviolet catastrophe then they produce an empty result.
You may want to assign to a variable and see if empty.
(Either that or it doesn't like you trying to access Apr 31. :-)
Also it may be easier to understand a procedural language like awk doing the filtering, rather than your nested greps.
awk allows you to easily look at columns and your grep for root, won't find it in a filename or a substring of fooroot.
As Steven mentioned, there are plenty of examples of find(1) in the Language forum, using reference files to bracket the start and end dates.
>Note that parsing the output of "ls -l" is probably more difficult than you think.
If you modify ls.cat, you can make it simpler. :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2016 10:55 PM
07-11-2016 10:55 PM
Re: cp -p not working
you could try systematically debugging your command line by making sure each piece in the pipeline is actually printing its output in the format you expect it to (e.g. first do the ls|egrep part by hand, then pass to grep, etc).
you could give a quick try to using $NF instead of $9 in the awk command.
--
ranga
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2016 08:19 AM
07-12-2016 08:19 AM
Re: cp -p not working
> you could try [...]
True. Seeing any of the actual data along the pipeline would be
better than seeing none of them.
> you could give a quick try to using $NF instead of $9 in the awk
> command.
Such techniques may work in some cases, but any file name which
contains a shell-special character can be expected to cause trouble.
"find" avoids these problems, too.