- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: difference /dev/null
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
Forums
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
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
тАО08-06-2010 06:21 AM
тАО08-06-2010 06:21 AM
Can anyone help me to understand the difference between two commands below?
cp /dev/null /informix/xyx.log
cat /dev/null > informix/xyx.log
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 06:33 AM
тАО08-06-2010 06:33 AM
SolutionIf you want to add a 3rd command that also accomplished the exact same thing:
> /informix/xyx.log
Note that the '>' IS part of the command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 06:35 AM
тАО08-06-2010 06:35 AM
Re: difference /dev/null
There is no difference.
# cp /dev/null myfile
# cat /dev/null > myfile
# > myfile
...are all variations of creating or truncating 'myfile' to be empty.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 06:39 AM
тАО08-06-2010 06:39 AM
Re: difference /dev/null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 06:56 AM
тАО08-06-2010 06:56 AM
Re: difference /dev/null
The first one reads /dev/null as if it were a regular file, and places the content to /informix/xyx.log, overwriting what's already there. All the work is done by the /usr/bin/cp command binary.
In the second one, the "cat" command only outputs the contents of /dev/null into the standard output stream, and then the shell redirects that stream to the informix/xyx.log file (because of the ">" redirection operator). Again, the new content overwrites the old. A half of the work is done by /usr/bin/cat, half by the shell.
Neither of these commands are optimal for truncating a file to zero size: running a command that is not built-in to the shell requires a vfork() + exec() system call pair, which causes a new process to be created and eventually torn down. This is not a problem if you need to truncate a small number of files (say, less than a thousand), but the accumulation of extra work gets very noticeable if you're truncating a million files or so.
The optimal way to truncate a file to zero size would usually be:
> /informix/xyx.log
i.e. to redirect the output of [an empty command line] to the file.
This is done completely within the shell process, so the system won't have to spend any time creating and tearing down extra processes.
MK