With CTRL + R we can search in previous commands (in the terminal of Debian). I always assumed it was searching my .bash_history, but that doesn't seem to be the case -- right now my .bash_history is entirely blanked out, yet ctrl+r is still working fine. Is it searching a file somewhere I haven't considered, or where is it getting the data from?
Asked
Active
Viewed 187 times
2 Answers
1
Ctrl+R is not searching a file. It's searching the history kept in memory by your current shell.
u1686_grawity
- 426,297
- 64
- 894
- 966
-
Weird, I thought "everything in linux is a file." College unix courses are so useless.. – some1 Mar 28 '13 at 18:25
-
@some1: It's only correct for some values of "everything", and for some values of "file". For example, Linux exposes a lot of variables and information through `/dev`, `/proc` and `/sys` filesystems. There are functions that allow reading signals or other events through an open *file descriptor* as if reading a file. (Linux got the inspiration for /proc from Plan9, an Unix derivative which took this to a much higher level.) But overall, "everything is a file" is much too broad; for example, you cannot access DBus or TCP as files; you cannot even open *Unix sockets* using file functions. – u1686_grawity Mar 28 '13 at 18:37
0
According to the answer to my question here, The system stores this information in an unnamed file. The files is opened then deleted immediately but can apparently still be searched as long as it is kept open.
-
The other answer is correct when talking about the *terminal's* scrollback, but it has no relation to the search performed by Ctrl+R in your *shell*. – u1686_grawity Mar 28 '13 at 18:29
-
@grawity huh? Really? I would have thought that what the shell "keeps in memory" would be kept with a similar mechanism. Is that wrong? Ctrl+R looks through my bash history, it works even if I open a new terminal, so I guess it must be stored somewhere, probably as an unnamed file. – terdon Mar 28 '13 at 18:31
-
When you open *bash*, it loads the history from `~/.bash_history`, and saves it again when the shell is closed. But in the mean time, the history is just stored in an array someplace in the RAM. Think about setting variables in any programming language – they don't touch the filesystem, real or virtual. – u1686_grawity Mar 28 '13 at 18:36
-
This even applies to terminal scrollback. Terminals based on libVTE write their scrollback to files (if you enable "infinite scrollback"), in order to make certain things easier, but most other terminals (such as Xterm) simply keep all scrollback contents in an array variable. – u1686_grawity Mar 28 '13 at 18:41