I am a novice in BASH coding. Is there any way I can print last modified time of a file (say photos) to a text file named last-modified.txt
I tried searching around a bit and could accomplish the task using the following code
stat -c %y photos >> last-modified.txt
However, I want to use |
to accomplish the task
EDIT: The aforementioned command (involving >>
or append) works well but I was curious to know if I can accomplish the same result by something like stat -c %y photos | cat last-modified.txt
(Although I know this won't work but you get the idea what I am trying to achieve here).
Use
tee
:Append to file:
or overwrite file:
This is especially useful if you (1) want to keep the output on the screen or (2) need to write to a file using
sudo
, then you can use... | sudo tee ...