Linux Shell in the> and >> the similarities and differences and scenarios

Linux Shell in the> and >> the similarities and differences and scenarios 


 

> >> and the similarities and differences

Illustration ( start.sh as a service startup script , start.log  for a service log file ):

nohup sh start.sh >/var/log/start.log &
nohup sh start.sh >>/var/log/start.log &

 

1, the same point

Log contents of the above two way, all of these services, output to the specified file.

When start.log files in / var / log / directory does not exist, it will create start.log file.

 

2, different points

> : Each time the service startup command, start.log file content will be removed , re-write the latest log information.

>> : each execution of the command to start the service, content start.log file will not be cleared , the latest log information is appended to the history behind the log.


 

Scenarios

From the above simple explanation, the following conclusions can be drawn:

1, when do not need to retain the information in the file history of time, you can use the> way.

For example: nohup command did not want to produce nohup.out file.

We used the following command to start the service, the log information output to an empty file (/ dev / null) in which:

nohup sh start.sh >/dev/null 2>&1 &

 

2, when the need to preserve the historical information in the file time, you must use >> way.

For example: We (node1, node2, node3 three-node cluster) in a clustered deployment project, often encounter be password-free access to each other, or scp scene documentation requirements between servers.

If you require a master node node1, node1 files can be password-free scp to node2 and node3 in.

In the configuration password-free process, the need to node1 generated public key, added to node2 and node3 certification file. We need to use the following command:

cat authorized_keys2 >>authorized_keys

 

Guess you like

Origin www.cnblogs.com/miracle-luna/p/11809725.html