0

I often want to reuse a terminal command that I already used in the past. I know two ways how to do this:

  • Use the "up" arrow to browse through old commands.
  • Copy a bunch of commands into a script.

Now I'm looking for something like an archiving tool, where I could comfortably collect useful terminal inputs. Is there something more comfortable than the "up" key or copying into scripts?

1

Maybe not quite what you're asking for, but an elegant solution: Press CTRL-R and it will invoke a search through your entire history. Pressing CTRL-R again will display the next search result.

Another solution would be to use something like TextExpander etc. You define your commands there and call them by shortcuts. Unfortunately it doesn't work with the built in OS X shortcuts from the System Preferences - I did not get it working.

  • BTW: A very useful replacement for the Terminal app... iterm2.com It has a powerful shortcut section in the preferences! – awado Jun 16 '15 at 23:54
1

It's not totally clear to me what you want, but if I understand correctly you want:

  1. to comfortably look through the history of used terminal commands
  2. selectively save them to a script for re-use

To achieve 1 this answer already has an explanation. Objective 2 can be achieved by simply copy pasting the desired commands from the ~/.bash_history file. Or, if you have some commands that you use often you could create an alias. That is a sort of short cut to a certain command. A permanent alias can be created in the ~/.profile file. The ~/.profile must then be loaded at every startup of Terminal.app. To achieve that go to the Terminal preferences and fill in source ~/.profile in run command at startup field:

enter image description here

An example of aliases I have in my ~/.profile file are shown below

alias showinvisibles="defaults write com.apple.finder AppleShowAllFiles YES"
alias hideinvisibles="defaults write com.apple.finder AppleShowAllFiles NO"

Now, whenever I type showinvisibles actually the command defaults write com.apple.finder AppleShowAllFiles YES is executed.

0
 cp ~/.bash_history ~/Documents/bash_history_`date \"+%Y-%m-%d-%H%M%S\"`.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .