- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- command difference
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
03-20-2001 05:37 AM
03-20-2001 05:37 AM
command difference
Just wondering what is the different to reset a file to zero with the following commands.
1. cat /dev/null > file
2. > file
3. touch file
All of the above seems to achieve the same purpose however for some log it is recommended to use > file instead of cat/dev/null what is the reason for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 05:49 AM
03-20-2001 05:49 AM
Re: command difference
The cat /dev/null does precisely nothing and so can be omittred.
touch file doesn't truncate the file or change the file contents at all. It just (by default) changes the time it was last modified. However it will create an empty file if it didn't already exist.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 06:17 AM
03-20-2001 06:17 AM
Re: command difference
cp /dev/null file1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 06:59 AM
03-20-2001 06:59 AM
Re: command difference
# echo "Testing">test
# ll test
-rw-r--r-- 1 root sys 8 Mar 20 06:57 test
# cat /dev/null >test
# ll test
-rw-r--r-- 1 root sys 0 Mar 20 06:57 test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 07:13 AM
03-20-2001 07:13 AM
Re: command difference
mv file file.old
touch file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 07:14 AM
03-20-2001 07:14 AM
Re: command difference
It isn't the 'cat /dev/null' that truncates the file. It's the '> file' which is actioned by the shell that does the truncating before the cat process is forked.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 07:25 AM
03-20-2001 07:25 AM
Re: command difference
If you did something like 'cat /dev/null >> file' then you wouldn't see any change in the file because >> says to append. So John is correct when he says the /dev/null doesn't do anything. If you want, just think of it as a place holder in the command so that you always use the command syntax you are used to (ie. 'cat filename > another_file') which is probably what most of us are used to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2001 07:49 AM
03-20-2001 07:49 AM
Re: command difference
thanks for clearing that up for me, i never really gave much thought to it before...to think, i've been typing all those extra characters for years now...my poor carpal-tunneled hands. :-)