Write Output of Bash Command to Log File - Example
Write Output of Bash Command to Log File ? Example
Write Output of Bash Command to Log File
To write output of Bash Command to Log File, you may use right angle bracket symbol (>) or double right angle symbol (>>).
Right angle braketsymbol (>) : is used to write output of a bash command to a disk file. If the file is not already present, it creates one with the name specified. If the file is already present, the content of the file would be overwritten.
Double right angle symbol (>>) : is used to append data to an existing file. If the file is not already present, a new one would be created.
When you are writing to the file for the first time, and want no previous data to be in the file if it is already present, use (>) to make sure that it overwrites the content. And in the later script, you may use (>>) to append to the log file.
Example
Following is an example to demonstrate writing output of Bash Commands to Log File.
Bash Script File
#!/bin/bash log=log_file.txt # create log file or overrite if already present printf "Log File - " > $log # append date to log file date >> $log x=$(( 3 + 1 )) # append some data to log file echo value of x is $x >> $log
When you run the above bash script, following file would be created with the content specified.
log_file.txt
Log File - Fri Dec 15 11:47:03 IST 2017 value of x is 4
Conclusion
In this Bash Tutorial, we learned how to write the output of a Bash command to a file.
Bash Shell Scripting Bash Tutorial Bash Script Example Bash File Extension Bash Echo Bash Comments Bash Variable Bash Command Line Arguments Bash Read User Input Bash Read Password Bash Date Format Bash Sleep
Operators Bash Arithmetic Operators
Conditional Statements Bash If Bash If Else Bash Else If Bash Case
Loops Bash For Loop
Bash For Loop Bash While Loop Bash Until Loop
Strings Bash String Manipulation Examples Bash String Length Bash If String Equals Bash Split String Bash SubString Bash Concatenate String Bash Concatenate Variables to Strings
Functions Bash Function Bash Override Buitlin Commands
Arrays Bash Array
Files Bash Write to File Bash Read File Bash Read File line by line Bash If File Exists Bash If File is Directory Bash If File is Readable
Bash Others Bash Check if variable is set
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- bash reference manual
- bash redirections cheat sheet
- linux redirect output
- redir ection no starch press
- shell redirect output to file
- write output of bash command to log file example
- introduction to linux part 1
- bash data handling iaria
- introduction to linux boston university
- csci 4061 input output with files pipes university of minnesota
Related searches
- powershell command to verify file exists
- command to open file explorer
- bash command output to file
- write to log file powershell
- system command to open file explorer
- bash command output to variable
- bash output command to variable
- write output to a file python
- write output to file python
- write output to txt file python
- write output to csv file powershell
- write output to file cmd