Whats the difference between these
Python abcd.py > abcd.logs
and
Python abcd.py >> abcd.logs
In either case, the output of the program is stored in the file whose name is provided after the redirection operator.
Whats the difference between these
Python abcd.py > abcd.logs
and
Python abcd.py >> abcd.logs
In either case, the output of the program is stored in the file whose name is provided after the redirection operator.
It might depend on the shell you are using but the common behaviour is that >
will overwrite the target file, while >>
will append to it. If the target file does not exist it will be created in both cases.
If you use >
:
if you use >>
:
However you often can change this default behavior. And there's also >|
which you can encounter in script files.
The most common alteration to these rules are usually known as the "clobber"-option.
In bash you can achieve this with:
set -o noclobber # This will set the noclobber option
set +o noclobber # This will unset the noclobber option
In Zsh you can achieve this with:
setopt CLOBBER # This will set the CLOBBER option
unsetopt CLOBBER # This will unset the CLOBBER option
If the "clobber"-option is set (or the "noclobber"-option unset), it will work like the following:
If you use >
with clobber-option:
if you use >>
with clobber-option:
if you use >|
with clobber-option: