6

I was taking a look at my .bash_history, and I found a blank line. I thought that I could have pressed "enter" while I was taking a look in the file.

Is that normal? Or maybe I really pressed enter while looking the file on gedit?

EDIT: Just found today that I have more than one line break. That's strange, I never edit the .bash_history file.

terdon
  • 100,812
Nori-chan
  • 845
  • i just had a look at my .bash_history file. It has around 700 commands but not a single line break. it sure seems like a mispress of the enter key, but cannot completely vouch on it.. – astrob0t Nov 08 '14 at 23:14
  • In my file, I have aprox 1000 lines, and only 1 line break. – Nori-chan Nov 08 '14 at 23:18
  • 1
    i have noticed that when i edit a file in gedit, a backup file with the name as <original file name>~ is created in the same directory. so can you check and report if you find .bash_history~ file and if yes, do you see the blank line there too? – astrob0t Nov 08 '14 at 23:23
  • I used the command 'gedit .bash_history~', but it created a new file. Also, strangely, now everytime that I open a folder, I can always see a hidden file or folder (like if I pressed Ctrl + h) – Nori-chan Nov 08 '14 at 23:31
  • @astrobOt Right now, I fixed the bugs that I could always see hidden files (no idea how it activated). – Nori-chan Nov 09 '14 at 00:14
  • its not strange that 'gedit .bash_history~' created a new file. It was just a thing that i had noticed and thought that might help us debug.Nothing to worry about that. But i am not sure if one should be bothered about a line break in the .bash_history file. i intentionally inserted multiple blank lines and played around with cli and didn't experience anything weird. – astrob0t Nov 09 '14 at 00:36
  • @astrob0t Besides the "auto showing hidden files", nothing wrong happened. – Nori-chan Nov 09 '14 at 00:45
  • @astrob0t Sorry for this update, but I just noticed that I have multiple blank lines in my file. Should I still be worried about it? – Nori-chan Nov 20 '14 at 09:38
  • i am not aware of any security implications in this situation. you should try to seek help at chat. maybe someone can. – astrob0t Nov 20 '14 at 14:53

3 Answers3

4

This is not a problem, it is not dangerous and is entirely normal. You can get such lines if you hit space a few times and then hit enter. This will be saved in your history (since it is a non-blank line, spaces are characters just invisible ones).

To test this, we can use a command that prints the blank lines in bash's history For example, this grep will match all lines that start with numbers and then have 0 or more whitespace (spaces or tabs or whatever) and nothing else until the end of the line:

history | grep -P '^\s*\d+\s*$'

That should show you a list of empty commands you have run. Now, run ( the first line means hit space a few times, then enter)

$ echo foo
foo
$       
$ history  | tail -n 3
$ history | tail -n 3
80  echo foo
81               ## this is the blank line
82  history | tail -n 3

You will notice that you have a new blank line. In conclusion, don't worry. everything is fine and this is normal.

terdon
  • 100,812
1

As mentioned by terdon, those are likely whitespace only lines.

There are two environment variables options that control whether whitespace lines are stored in the history or not:

  • HISTCONTROL: if it contains ignorespace, then any line that starts with a whitespace is ignored.

  • HISTIGNORE: colon separated list of pattens to ignore. For example, if it contains:

    HISTIGNORE=' *'
    

    then lines that start with a single space will be ignored.

I was not able to make bash store truly empty lines without whitespace.

0

Here is an explanation about how blank lines can occur in the .bash_history file.

In brief:

If you call from the history a command line that you have actually typed earlier in that same current terminal session and then edit it (maybe deleting it) but then interrupt your edit by leaving that (history-)command line using for instance the Down arrow to come back to the prompt of the actual current command line, then when later on you exit the terminal the edits get recorded in the .bash_history file.

The Quark
  • 283