The text that is displayed in the terminal comes from the stderr
stream (2). If you do just make > build_log.txt
, only the stdout
(1) stream is redirected to the build_log.txt
file.
stdout
is the standard output stream and has file descriptor number 1. This is the default stream being redirected in shells.
stderr
is the standard error stream and has file descriptor number 2
To redirect the stderr
stream to that build_log.txt
file too, use:
make > build_log.txt 2>&1
make
is executed and
- the
stdout
stream is redirected (>
) to build_log.txt
- the
stderr
stream is redirected (2>
) to the stdout
stream (&1
), which was redirected to build_log.txt
The order is important, you cannot switch switch the redirection operators like make 2>&1 > build_log.txt
.
Alternative command:
make 2>&1 | tee build_log.txt > /dev/null
The redirection to /dev/null
is needed to hide output, tee
writes its input to build_log.txt
and outputs it too.
It can be done with a python script, with one sidenote: I took the modification date instead of the creation date, since the creation date will almost certainly not match the real creation date: it is the date the file was copied to the computer, while the modification date seems unchanged during copying (see discussion at @cOrps answer). You will have to see if it works in your situation.
If that is acceptable for you, you can use the script below to create a combined file with your notes. It reads the notes, sorts them and appends them to a text file (creates it if it doesn't exist).
The good news is that you can append your new notes to the same file without overwriting the old ones.
Example output:
Mon Sep 29 08:48:31 2014
This is my first note.
As you can read, I am not really awake yet.
----------
Mon Sep 29 09:04:06 2014
It is really time I am going to eat something.
I am a bit hungry.
Making it a bit longer.
----------
How to use:
The script:
#!/usr/bin/env python3
import os
import time
import subprocess
# --------------------------------------------------------
files_dir = "/path/to/your/textfiles"
combined_file = "/path/to/your/combined/file.txt"
# ---------------------------------------------------------
notes = []
if not os.path.exists(combined_file):
subprocess.Popen(["touch", combined_file])
def read_file(file):
with open(file) as note:
return note.read()
def append_file(combined_file, text):
with open(combined_file, "a") as notes:
notes.write(text)
for root, dirs, files in os.walk(files_dir):
for name in files:
subject = root+"/"+name
cr_date_text = time.ctime(os.path.getmtime(subject))
cr_date_n = os.stat(subject).st_mtime
notes.append((cr_date_n, cr_date_text, subject))
notes.sort(key=lambda x: x[0])
for note in notes:
text = note[1]+"\n"+read_file(note[2])+"\n"+"-"*10+"\n"
append_file(combined_file, text)
Best Answer
Try the following
The
-b
is for batch mode, which should prevent the strange characters. The-n1
tells it to only print one iteration.