To show previously executed commands use the history command
history
history865find/-name'file1.txt'2>errors.txt866caterrors.txt867ll868lserrors.txt869llerrors.txt870source.bashrc871llerrors.txt872ls-laherrors.txt# It includes the executed commands and the history number associated to themhistory|less# To execute one of the previous commands use !HISTORY_NUMBER!868# To execute the last command use these shortcuts!-1!!# Up & Down arrow keys can be used to scroll through history# To execute the last "command" command - cat for example!cat
The configuration options of the history are located in the .bashrc file
cat~/.bashrc# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000 HISTFILESIZE=2000
Command Substitution
Redirecting doesn't always work.
With command substitution a command can be replaced with its output before the entire command is executed by the shell.
Backticks `` or $() are used:
ls-l`catfile.txt`ls-l $(catfile.txt)# Example with a file listcatfile-list.txtfile1.txtfile2.txtfile3.txtls-l`catfile-list.txt`-rw-rw-r--1rootroot6set300:16file1.txt-rw-rw-r--1useruser7set300:16file2.txt-rw-rw-r--1useruser8set300:16file3.txt