LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-12-2013, 01:56 PM   #1
Otto-1062
Member
 
Registered: Jul 2006
Posts: 36

Rep: Reputation: 0
Where are command line commands stored


From time to time I use the cli and use a command I want to use again but
can't exactly what it was. I know I can up-arrow to try to locate it but
are previous commands stored in a file user can access. Say a "command
stack file".
tia
otto-1062
 
Old 12-12-2013, 02:00 PM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i think the history command reads from the history file which mite be different in each system:
Code:
[schneidz@hyper clips]$ echo $HISTFILEecho $HISTFILE
/home/schneidz/.bash_history
 
Old 12-12-2013, 02:48 PM   #3
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
The .bash_history has your up arrow list of things up to a certain count. If you want to keep some oddities around you might want to make periodic backups of that file.

$ cp .bash_history bh_user_YYYYMMDD.txt

And various ways to cherry pick line items from a large history.

$ cat .bash_history | grep -i "something"


If you want to know where an actual command / application exists

$ which xterm

$ ls -l $(which xterm)

And other tricks of the trade.
 
Old 12-12-2013, 08:48 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I just use
Code:
history|grep <something>
 
Old 12-12-2013, 09:01 PM   #5
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,341
Blog Entries: 28

Rep: Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145
CTRL-R is a great tool for recycling commands from your history.

See item 2 at this link for an excellent explanation: http://www.thegeekstuff.com/2008/08/...tory/#more-130

Last edited by frankbell; 12-12-2013 at 09:02 PM.
 
3 members found this post helpful.
Old 01-13-2014, 05:13 AM   #6
suyashjain
LQ Newbie
 
Registered: Dec 2008
Location: Bangalore
Posts: 4

Rep: Reputation: 1
checkout more history tricks
 
Old 01-13-2014, 06:52 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member Response

Hi,

Quote:
Originally Posted by Otto-1062 View Post
From time to time I use the cli and use a command I want to use again but
can't exactly what it was. I know I can up-arrow to try to locate it but
are previous commands stored in a file user can access. Say a "command
stack file".
tia
otto-1062
Other than history, I setup my '.bash_profile' & '.bashrc' for frequently used commands as 'alias';
Code:
sample .bash_profile;   
~$ cat .bash_profile 
#-----------------cut-----------------   
# .bash_profile
#08-30-06 12:21

# Source .bashrc
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

#-----------------cut end--------------
Code:
 cat .bashrc
#-----------------cut-------------------

#.bashrc
#08-30-06 12:20 

# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize
#
#save bash history so as to share

shopt -s histappend
PROMPT_COMMAND='history -a'

# Custom prompt 
#PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 

#08-29-06 11:40 
if [ `id -un` = root ]; then 
PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] ' 
else
PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] ' 
fi 
# 
# Add color 
eval `dircolors -b` 
#Terminus is a very nice Unicode font for the Linux console

#
#if [ $TERM = "linux" ]; then
# setfont ter-v16n
#fi

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias lsp='ls -1 /var/log/packages/ > package-list'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:50

#To clean up and cover your tracks once you log off
#Depending on your version of BASH, you might have to use
# the other form of this command
 trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#trap 0 rm -f ~$LOGNAME/.bash_history


#-----------------cut end--------------
'history' is great but so is setting up alias for frequently used commands. I let users modify to suit their needs.
Hope this helps!

Last edited by onebuck; 01-13-2014 at 12:58 PM. Reason: font error
 
Old 01-13-2014, 09:17 AM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I use
Code:
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
in every .bashrc I have control over.
 
2 members found this post helpful.
Old 01-13-2014, 12:39 PM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
i used to do this to have to modify history commands with special characters on my old fone:
http://www.linuxquestions.org/questi...1/#post3698171
 
Old 03-02-2014, 07:09 AM   #10
Otto-1062
Member
 
Registered: Jul 2006
Posts: 36

Original Poster
Rep: Reputation: 0
With some further research I found that
typing:

$ history

will show all previous commands.
To execute your command type:

$ !item number # exclamation point item number

Thanks all,
otto-1062
 
Old 03-02-2014, 09:48 AM   #11
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Member Response

Hi,

If you have aliases setup in '~/.bashrc' then to remind you of the list you can type 'alias' at the 'cli' to see what has been setup.

A '~/.bashrc' with aliases is very useful and does provide useful actions along with history.

Hope this helps!

 
Old 03-02-2014, 08:24 PM   #12
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,129
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
You could use
Code:
history | grep <insert command here>

You could add or modify this in your ~/.bashrc file to control the history of commands.
Code:
# Number of commands to keep in memory while in your bash session.
# They will be written to the ~/.bash_history file when you end your session.
HISTSIZE=1000
# The max number of lines that ~/.my_bash_history file will contain.
HISTFILESIZE=2000
Default is 500 for both.


To make automatic backups of the commands you use, you could also put a small script or command at the end of your ~/.bashrc to run every time you open a terminal.
Code:
# This will read the history, append it to a file, then remove the duplicates.
cat ~/.bash_history >> ~/.my_bash_history && sort -u ~/.my_bash_history -o ~/.my_bash_history

# This will check if it's Sunday, if so, check if we've already made a backup today.
# If not, we'll copy the above mentioned file and append the date to the backup name.
if [ `date +%a` = "Sun" ]; then
  if [ ! -f ~/.my_bash_history_backup_`date +%F` ]; then
    cp ~/.my_bash_history ~/.my_bash_history_backup_`date +%F`
  fi
fi
 
Old 03-03-2014, 06:59 AM   #13
yooden
Member
 
Registered: Dec 2013
Distribution: Debian Wheezy/Jessie # XFCE
Posts: 53

Rep: Reputation: Disabled
One of the more useful features of modern shells is insert-last-word (bound to Alt-. by default). Example:
Code:
# ls
[lots of different files]
# ls *.deleteme
[only the files I want to delete]
# rm <insert-last-word>
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp command line client - run multiple ftp commands in one line dlugasx Linux - Server 1 09-13-2012 06:24 AM
Entering Command Line commands johnmtb Linux - Newbie 5 01-06-2009 01:26 AM
command line commands bcbotha Linux - Newbie 15 12-01-2008 08:05 AM
Java Commands for Command Line AceTech Programming 4 08-20-2006 02:55 AM
Time commands from command line ToothlessRebel Linux - Newbie 1 03-09-2005 10:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:00 AM.

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
Open Source Consulting | Domain Registration