- Basic Linux tutorials for beginner
- Linux basic concepts, installation and troubleshooting
- Linux administration
- Linux commands
- Linux network tutorials
- Linux security tutorials
- Linux software configuration
- Linux desktop tutorials for beginner
- Collection of Linux tips
- Windows basic tutorials
- Introduction to windows
- Windows pre-installation
- Windows Installation
- Windows xp desktop
- Log on for the first time
- Windows XP control panel
- Managing Folders in Windows XP
- Outlook Express Setup
- How to import address book in Outlook Express
- Import Ms Exchange inbox file(.pst) into Ms Outlook 2003
- Import Outlook Express email messages into Ms Outlook 2003
- How to mount and unmount usb drive (thumb drive) in Windows
- House keeping - Keep your Windows clean and tidy
- Windows basic tutorials
Linux history command - Bash history tutorial for beginner
Submitted by jinlusuh on Fri, 11/14/2008 - 02:08
Linux bash history keeps every command a user typed in the command line terminal into a file named .bash_history. What good about this is that user can re-used the command in case they are lazy to type a very long argument presented with the command. It also faster to use bash command history rather than typing the same command all over again. That makes working in Linux command line virtual terminal a bit fun.
Here is a description from the bash history manual page:
Linux bash history command examples
Linux bash history command available in all Linux distributions including Slackware Linux and Ubuntu server. What you need to do to view previously typed commands is just invoke history from Linux command prompt. Here is an example of Linux history command with no option running in Ubuntu server system command line terminal:
In the example above, number 1 is the oldest command and number 10 is the latest command that a current user has typed. If you never clear the history file, you might see hundreds of commands that you typed including the latest 'history'. The bash history command would print only the latest page of the command history. However you can view bash commands history from the first page with pipe, like an example below:
Let's see another example of bash history options. You can also use event designators to run command in the history using the ! key. See an example below:
The example above run number 8 command in the history file, which is the man route command. Here is a complete options available with event designators:
There are many options available if you want to create a script using bash history. You can check other history options in the info page. Just type info history to open it.
You can clear Linux bash history if it is too large or you don't want other people see what you were doing in the command line terminal. If you want to clear the bash history, use history command with -c option. See example below:
Linux history command can be really helpful when we are working in command line terminal. We can save a lot of times not typing regularly used command such as ls, cd and many more. However, keeping all bash history commands also might cause security threat to the system. For example, consider the root bash history file was read by unauthorised person. What you can do is always clear history after root session.
You can also delete line in history file. Let's look at the example Linux history file below:
If I want to delete the history line number 4, what I have to do is to use history command with '-d 4' option. The -d option deletes history entry while the 4 argument is history entry line 4. See the example below:
Now let's look at the Linux history file again:
The history entry number 4 has been deleted and the previous number 5 entry is now at number 4.
Here are other history command options that you can try:
- -a — Appends to history file.
- -n — Loads from history file.
- -p — Performs history lookup/substitution.
- -r — Reads history from a file.
- -s — Adds new history entries.
That is all the Linux history command options regularly used in Linux administration.
Back to Linux basic commands main page.