Linux - GeneralThis 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
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.
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
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
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
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.