4

This question already has an answer here:

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!

marked as duplicate by muru, heemayl command-line Feb 5 '18 at 9:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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 5 '18 at 7:08
  • Or askubuntu.com/questions/624848/…, depending on what you mean by log – muru Feb 5 '18 at 8:55
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
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.