1819882 Members
2629 Online
109607 Solutions
New Discussion юеВ

cat /dev/null

 
SOLVED
Go to solution
Randy_9
Regular Advisor

cat /dev/null

How do I get the following to work without
blowing up, I just trying to zero out a file.

remsh hostsystem "cat /dev/null > /directory/file"

I've tried "\>" but it still blows up?
I've tried '>' but it still blows up?

Help

Thanks
Randy


10 REPLIES 10
Patrick Wallek
Honored Contributor

Re: cat /dev/null

How does it "blow up"? What error do you get?
Randy_9
Regular Advisor

Re: cat /dev/null

I get what looks like the output of the "cat"
command to the screen. It isn't working in
a script either using the same syntax :(

Randy

S.K. Chan
Honored Contributor
Solution

Re: cat /dev/null

Is there an alias for your "cat" command by any chance ?
$ alias
Another way to zero it is by doing "cp" of /dev/null like so ..
$ remsh system "cp /dev/null /directory/file"

Bill Hassell
Honored Contributor

Re: cat /dev/null

Change the "..." to '...'
The problem is the > character which has special meaning to the shell. The apostrophe (single quotes) turns off the special meaning of all characters in the string. Although you wanted the > redirection to take place on the remote system, the shell steps in first to evaluate any special characters. Another way to escape the > character is:

remsh hostsystem "cat /dev/null \> /directory/file"



Bill Hassell, sysadmin
Vincent Fleming
Honored Contributor

Re: cat /dev/null

In most unixes, you can't cat /dev/null because you can't read it - it's write only. Sorry to say, but I haven't ever tried it on HP-UX, and haven't got a HP-UX system handy.

Try cat /dev/zero instead. It produces a constant stream of zeros, and works on nearly all unixes.

Also, try using single quotes instead of double quotes. ie: remsh remotesys 'cat /dev/zero > /tmp/fred'
The single-quoted string will not be interpreted by the shell at all, where double-quoted strings will ($VAR's are expanded, among other things).

Good luck!
No matter where you go, there you are.
Patrick Wallek
Honored Contributor

Re: cat /dev/null



Actually a better syntax for zeroing out a file is:

# > /dir/filename

It will accomplish the same thing as 'cat /dev/null > /dir/filename'

While /dev/zero is useful for some things, I don't know how usefule it would be for zeroing out a file.
Steven Sim Kok Leong
Honored Contributor

Re: cat /dev/null

Hi,

Do NOT use cat /dev/zero to a file because this will cause a "blank" zero'ed-out file to be created to the maximum size your filesystem can contain. In otherwises, the "zero'ing" won't stop until your filesystem is full. This applies to the cp (copy) as well.

/dev/zero should not be used to create an empty file (which is often used as a lock file) because it doesn't. /dev/zero's purpose is for wiping out disks and media using the dd command (for security reasons) i.e.

# dd if=/dev/zero of=/dev/rdsk/c3t4d0

If you want to create a zero-size file, then you can use one of the following methods (not exhaustive):

# cp /dev/null /tmp/empty_file
# cat /dev/null > /tmp/empty_file
# touch /tmp/empty_file
# > /tmp/empty_file

Hope this helps. Regards.

Steven Sim Kok Leong
Stefan Schulz
Honored Contributor

Re: cat /dev/null

Hi Randy,

this works: remsh hostsystem '> /directory/file'

Note the single quotes, they do the trick.

Also there is no need to use cat /dev/null. As cat reads exactly nothing (/dev/null) the result of the cat command is also exactly nothing. So nothing is redirected and not null like expected.

Hope this helps

Regards Stefan
No Mouse found. System halted. Press Mousebutton to continue.
Vincent Fleming
Honored Contributor

Re: cat /dev/null

Sorry - I missed the part about just wanting to zero the file...

I agree with the others here that '> filename' is the best way to zero a file.

Good luck!
No matter where you go, there you are.
Randy_9
Regular Advisor

Re: cat /dev/null

Wow,

Lots of good stuff. And I've learned about
/dev/zero also. Points to be assigned!

Thanks and have a great day.

Randy