Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The history command will list previous commands. You can also search within history if you know roughly what you're looking for. ie. If you want to find a list of all the cp commands you have executed then type history | grep cp. Previous commands are stored in bash_history, the number of commands that can be stored is controlled by the HISTSIZE variable. Type echo $HISTSIZE to see what this variable has been set to. You can change this from the commandline by typing HISTSIZE=500 for example.
from the bash manual page (yes, it's really really useful - you should read it!)
Code:
history [n]
history -c
history -d offset
history -anrw [filename]
history -p arg [arg ...]
history -s arg [arg ...]
With no options, display the command history list with line num‐
bers. Lines listed with a * have been modified. An argument of
n lists only the last n lines. If the shell variable HISTTIMEFORMAT
is set and not null, it is used as a format string for
strftime(3) to display the time stamp associated with each dis‐
played history entry. No intervening blank is printed between
the formatted time stamp and the history line. If filename is
supplied, it is used as the name of the history file; if not,
the value of HISTFILE is used. Options, if supplied, have the
following meanings:
-c Clear the history list by deleting all the entries.
-d offset
Delete the history entry at position offset.
-a Append the ‘‘new’’ history lines (history lines entered
since the beginning of the current bash session) to the
history file.
-n Read the history lines not already read from the history
file into the current history list. These are lines
appended to the history file since the beginning of the
current bash session.
-r Read the contents of the history file and use them as the
current history.
-w Write the current history to the history file, overwrit‐
ing the history file’s contents.
-p Perform history substitution on the following args and
display the result on the standard output. Does not
store the results in the history list. Each arg must be
quoted to disable normal history expansion.
-s Store the args in the history list as a single entry.
The last command in the history list is removed before
the args are added.
If the HISTTIMEFORMAT is set, the time stamp information associ‐
ated with each history entry is written to the history file.
The return value is 0 unless an invalid option is encountered,
an error occurs while reading or writing the history file, an
invalid offset is supplied as an argument to -d, or the history
expansion supplied as an argument to -p fails.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.