Upon running Screen with the -L flag, a file called 'screenlog.0' is created and all output written to it (which is great), but I will be running several Screen sessions and I need to identify the logs with a unique number. Is it possible to change the log file name?
Asked
Active
Viewed 5.1k times
38
-
see my answer here: http://stackoverflow.com/questions/14208001/save-screen-program-output-to-a-file/37559327#37559327 – lepe Jun 01 '16 at 04:18
3 Answers
59
Probably the easiest way is to use the following (starting from Screen version 4.06.02 and up):
screen -L -Logfile log_filename your_command

Peter Mortensen
- 30,738
- 21
- 105
- 131

Nan Wang
- 736
- 1
- 6
- 5
-
2Imho this one should be the approved answer, simplest, cleanest and the way the command itself provides this functionality – Pronte Jan 21 '19 at 12:56
-
11
-
3Same "Unkown option Logfile" on Amazon Linux 2 AMI 2.0.20190115 x86_64 HVM gp2 machines – sabau Mar 07 '19 at 18:05
-
14This will work only for screen version 4.06.02 and up. https://stackoverflow.com/a/48614247/852862 – HaReL Mar 12 '19 at 16:46
-
2The version number can be discovered by [`screen -v`](https://linux.die.net/man/1/screen). Sample output (on a [Ubuntu 19.10](https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_19.10_(Eoan_Ermine)) (Eoan Ermine) system): `Screen version 4.06.02 (GNU) 23-Oct-17` – Peter Mortensen Mar 25 '20 at 14:01
-
@HaReL: How do you know it is version 4.06.02 and up? That it works for 4.06.02 does not rule out it works for some slightly earlier versions. – Peter Mortensen Mar 25 '20 at 14:07
-
1@PeterMortensen I currently don't remember but you might be right... The main thing is that it's version dependent and might not always work. It didn't worked for me (and apparently for others) on older versions. – HaReL Apr 04 '20 at 19:56
-
On [Ubuntu 18.04](https://en.wikipedia.org/wiki/Ubuntu_version_history#Ubuntu_18.04_LTS_.28Bionic_Beaver.29) (Bionic Beaver), the output of screen -v is also *"Screen version 4.06.02 (GNU) 23-Oct-17"*. – Peter Mortensen Sep 13 '22 at 00:06
22
You can edit your .screenrc
file and add something like this:
logfile /tmp/myownlog
It is also answered at Specifying a log name for screen output without relying on .screenrc.

Peter Mortensen
- 30,738
- 21
- 105
- 131

Eun
- 4,146
- 5
- 30
- 51
-
3I'm looking for an 'on-the-fly' solution to name the generated log files as the screen sessions are created. Your solution isn't what I'm looking for, sorry! – Justin Feb 22 '13 at 14:20
-
2BTW, instead of replacing `.screenrc` you can just specify alternate `scrennrc` file name to `screen` with `-c` options. – Mikhail Vladimirov Feb 22 '13 at 14:32
-
1This works, but I believe the answer by Nan Wang is the simplest and cleanest.. shouldn't that one be the approved answer? – Pronte Jan 21 '19 at 12:47
-
On my Mac (Catalina) that does not work at all. I always have to use Ctrl-a-H. Annoying. Seems I need to write my own screen :-/ – qwerty_so May 17 '20 at 11:23
20
Alternatively, there's a way to do it interactively.
Enter command mode in Screen via Ctrl+a, : and use the logfile
command with the name of the file you want as argument, for example:
logfile whatevernameyoulike.log
Then enter Ctrl+a, H to start recording to the filename you just entered.
Source: Screen man page

DylanYoung
- 2,423
- 27
- 30

Juan Enciso
- 310
- 2
- 7
-
7And then enter `Ctrl`+`a`, `H` to start recording to the filename you just entered. – Luc May 07 '18 at 17:57
-
This exactly what I was after, perfect for logging when forgotten on startup – Develop Ideas Jun 22 '22 at 14:17