4

Im in need of help. New learner to linux, and for school, they want me to create a log file of all the commands I executed for a project. I can't figure it out at all. Please help!

muru
  • 197,895
  • 55
  • 485
  • 740
jbarry
  • 41
  • Can you please specify more precisely, what you mean by "log file" (should it include the input? The output? The exit code? What format should the log file have?), what you mean by "commands" (executable files? Shell builtins? Shell functions? Shell aliases? Should aliases be expanded or not?) and what you mean by "executed" (Commands you typed in? Commands that were executed by scripts?) Please, provide a precise and unambiguous specification of the behavior and result you expect, including corner cases and special cases, etc. – Jörg W Mittag Feb 05 '18 at 07:08
  • Or https://askubuntu.com/questions/624848/view-history-of-commands-ran-in-terminal, depending on what you mean by log – muru Feb 05 '18 at 08:55

2 Answers2

8

Bash keeps a log of commands you've run. You can access the log from the current session with the command:

history

After your session finishes it is written out to the file:

~/.bash_history
thomasrutter
  • 36,774
4

Your question is a little unclear whether you are wanting the output as well since “log of all commands” could be interpreted either way.

In that case, you can use script:

script(1) - Linux man page

Name

script - make typescript of terminal session

Synopsis

script [-a] [-c COMMAND] [-f] [-q] [-t] [file]

Description

Script makes a typescript of everything printed on your 
terminal. It is useful for students who need a hardcopy record 
of an interactive session as proof of an assignment, as the 
typescript file can be printed out later with lpr(1).

If the argument file is given, script saves all dialogue in file. 
If no file name is given, the typescript is saved in the file 
typescript.

This is usually the tool we were asked to use when showing the commands we used on an assignments as it also provides the output, which is sometimes important to the instructor.

rrauenza
  • 301