LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-19-2014, 01:30 PM   #1
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Rep: Reputation: Disabled
Question Outputting all history


Hi guys. http://www.tldp.org/LDP/GNU-Linux-To...html/x1712.htm says

Quote:
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.
 
Old 04-19-2014, 01:51 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,478

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
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).

Hope this helps some.
 
Old 04-19-2014, 02:10 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
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.
 
Old 04-20-2014, 07:11 AM   #4
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
tronayne, I use zsh.

Code:
$ cat ~/.zshrc | head -n 3
export HISTFILE=~/.zsh_history
export HISTSIZE=1000
export SAVEHIST=1000
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.
 
Old 04-20-2014, 09:01 AM   #5
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,478

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
Quote:
Originally Posted by Mr. Alex View Post
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.

Hope this helps some.

Last edited by tronayne; 04-21-2014 at 10:30 AM.
 
1 members found this post helpful.
Old 04-21-2014, 10:02 AM   #6
Mr. Alex
Senior Member
 
Registered: May 2010
Distribution: No more Linux. Done with it.
Posts: 1,238

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-21-2014, 10:28 AM   #7
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,478

Rep: Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020Reputation: 1020
That's normal behavior.

On my system (KornShell)
Code:
hisotry 1
displays all 1,000 lines in ~/.sh_history; however
Code:
history -50
produces the last 50 history entries. Not especially intuitive.

The "trick" is the - in front of the 50.

There is a manual page for history, it's a GNU utility (and, of course, has a gazillion options). You might find it interesting.

Hope this helps some.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] History utility error in Linux Mint 14; cannot delete history mintyninja41 Linux - Newbie 3 03-22-2013 07:36 AM
LXer: HISTORY Those that fail to learn from history are doomed to repeat it LXer Syndicated Linux News 0 04-11-2012 04:11 PM
Getting history back after typing history -c in the terminal in Ubuntu rajiucsc Linux - General 1 02-11-2012 01:48 PM
history clearance for a particular history number in linux sangupari Linux - Software 3 03-03-2010 04:08 AM
tcsh: can you save the history from multiple shells to one history file? BrianK General 2 04-23-2009 06:19 AM


All times are GMT -5. The time now is 04:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration