17

I made an echo command to my .bash_aliases file and erased all of my aliases, except the test alias. However, I still have a session open that has the aliases loaded (into the tcl?). Can I retrieve them from this session?

4
  • 9
    What if you just type alias? It will show what you have defined. Commented Jul 23, 2014 at 15:04
  • 3
    Your next question is now required to be about setting up a backup system. :-/ Commented Jul 23, 2014 at 16:06
  • 2
    Your next task, as soon as you've recreated your .bash_aliases, is to set up version control for your dot files. Commented Jul 23, 2014 at 23:02
  • @Gilles even better: unix.blogoverflow.com/2014/04/… Commented Jul 24, 2014 at 5:26

2 Answers 2

15

Easy trick

for alias in $(compgen -a); do type $alias; done 
3
  • 4
    You, sir or madame, are a life saver. Commented Jul 23, 2014 at 13:06
  • 1
    Combine this with redirection to a file ($alias > .bash_aliases, maybe with some file regexes to get it to the right place in the file) and you don't have to type it back into the original file yourself. (That is, if you haven't already typed it in.) Commented Jul 23, 2014 at 18:12
  • 1
    While this works, I don't see the benefit over just using 'alias'. The format isn't particularly useful by comparison. Commented Jul 24, 2014 at 8:01
10

You can almost definitely just do:

alias >>./bash_aliases 
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.