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.
This log is called the “history”. To access it type:
history n
This will only list the last n commands. Type “history” (without options) to see the the entire history list.
But it doesn't work for me. When I type in "history" I get just a small part of ~/.zsh_history file. I can't find how to output all history. Must be easy, but it doesn't work for me for some reason. Help please.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Are you using BASH, KornShell or the Z Shell? There is an environment variable you can set for either of those, HISTSIZE; e.g., in your ~/.profile file add
Code:
export HISTSIZE=1000
(the default value is 500 in BASH and KornShell, don't know what it is in Z Shell).
Don't have a .profile in your home directory? Create one; it's a text file, it should not be executable, just a plain old text file.
It is executed once when you log in to set the environment variable (so, you need to log out and log back in again to have it take effect).
The history log file is a rotating buffer of commands. It doesn't hold every command - only the N commands specified by HISTSIZE. I believe the default is 500.
Also note - on login the contents are whatever was in there earlier, so that could include yesterdays entries as well.
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
Quote:
Originally Posted by Mr. Alex
So if follow your logic I should get list of 1000 commands when I type in "history". But I get only a portion of what I have in ~/.zsh_history.
OK, you can alias the history command to, say, the size of the screen you're working in.
There are two environment variables, COLUMNS and LINES that may or may not be set; those two variables can be used by a number of terminal-type utilities and it doesn't hurt to set them (in .profile or .zsh, which I am not familiar with, at log in:
Code:
# Use a common screen size to start
export COLUMNS=80
export LINES=40
# Screen is probably larger, so make COLUMNS and LINES the screen size
eval `resize`
The resize is used to "set environment and terminal settings to current xterm window size" (see the manual page).
Now, we're part way there; set up an alias that will show you a screen-size list of history:
Code:
alias hi='history -${LINES}'
Then, just type hi and get a screen-full.
Want more?
Code:
history -250 | pg (or more or less).
Now, that presupposes that your history file is not wiped out when you exit the terminal window (some shell programs do that, you only get current session history, I think C-Shell does that, maybe BASH, too, but I don't use BASH and don't know). If that is happening the is probably a way to shut it off and I'd look at the manual page to find out how. KornShell does not wipe it out and I always have 1,000 lines of history available over multiple sessions; YMMV.
Tronayne, thanks for your advices. One more strange thing. "history n" doesn't actually output last n commands. The n here means "since what command to output the list to the last command" as I can understand from the behaviour of my shell. If I type in "history 20" it outputs all commands starting from 20'th command. "history 1", as it turned out, outputs all. Is it normal? Web manuals didn't mention it.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.