0

I am looking to write the output of

cat /var/log/dpkg.log

to a file rather than viewing on the screen.

I have tried

cat /var/log/dpkg.log | file.txt

without any success.

Ultimately I want this command and

dmesg -T

to run automatically from a batch from a usb.

The usb has the "ID" of 0782:5551. Is it possible to get the "file.txt" (with the date and time included in filename) to be written to that same USB drive via it's "ID" since it could any "device' depending on its order?

The purpose of this is for a project to ultimately compare the file based on dates.

рüффп
  • 1,677
  • 4
  • 27
  • 35
  • You seem to have 3 questions here: how to re-direct stdout, how to address a usb storage device, howe to put a date in a file-name. (We have a one question per question policy. But as many questions as you like.) – ctrl-alt-delor Nov 10 '18 at 13:45
  • The first question is a duplicate of [What are the shell's control and redirection operators?](https://unix.stackexchange.com/q/159513/80216) The third question is a duplicate of [How can I assign the output of a command to a shell variable?](https://unix.stackexchange.com/q/16024/80216) – G-Man Says 'Reinstate Monica' Mar 31 '19 at 22:55

1 Answers1

1

| is used to pass the output to another command. > re-directs it to a file.

You need >.

ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
  • 2
    Indeed. Also, one usually writes files to the mounted filesystem, not to the device file itself. So it would be `dmesg -T > /media/mounpoint/$(date +%Y%m%d%a%H%M).log`. Auto-generated mount-points rely on partition IDs or labels and thus are usually stable. – Hermann Nov 10 '18 at 13:48