Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Help with remembering UNIX commands UNIX
This is a "Mini-hint." I tend to use the terminal a lot, and sometimes I'll run a line or two from a hint I find on here. What I did was to write a short shell script to help me find old commands that I have run. Bash keeps a history of commands you run in terminal, so you just need to search it to find what you're looking for. Make a new plain text document in the editor of your choice, with these contents:
more ~/.bash_history | grep $1
Save it as /usr/bin/remember or some other name that's easy to keep track of (and in your PATH). Make it executable in the Terminal by typing:
chmod +x /usr/bin/remember
Now you can remember an old command by typing:
remember command-fragment-here
This may or may not be useful for you, but I use it from time to time.

[robg adds: I would strongly not recommend saving the script to /usr/bin. Instead, create a local bin directory in your user's home folder, or place it in /usr/local/bin. Both of these are preferable to adding your own code to the system's bin directory. As an alternative, I believe you could just create this as an alias, thereby not even requiring the shell script...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[3,454 views]  

Help with remembering UNIX commands | 5 comments | Create New Account
Click here to return to the 'Help with remembering UNIX commands' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Help with remembering UNIX commands
Authored by: mkhaw on Mar 19, '04 12:12:31PM
You could also define a bash alias in your .bashrc such as: alias remember='history | grep $1'

[ Reply to This | # ]
Help with remembering UNIX commands
Authored by: cteselle on Mar 19, '04 12:23:20PM
The history could help you too.

history will return a list like:

106 9:20 ls -l
107 9:20 pwd
108 9:20 du -sk

let's say you want to run command # 107 again, you would simply enter !107 hit return and that command is run again.

hope this helps someone...

[ Reply to This | # ]

Help with remembering UNIX commands
Authored by: midan23 on Mar 19, '04 12:26:31PM

Why not simply using the history search feature of bash : CTRL-R



[ Reply to This | # ]
Well that would be far too simple
Authored by: rootpoot on Mar 19, '04 03:05:29PM

I also wonder why more is used here. I've seen plenty of useless uses of cat, but never a useless use of more.

grep $1 ~/.bash_history will do the same thing.



[ Reply to This | # ]
Help with remembering UNIX commands
Authored by: ahunter on Mar 19, '04 07:43:36PM

!start-of-command works best for me (ie !ls will run the last ls command you used). It's slightly more focused than using command+R, although it works much better in zsh than bash (as you can use tab-completion to see the command before it runs).



[ Reply to This | # ]