Where are aliases set in CentOS?

4

There is a typo which causes an error message upon logon (someone typed lias instead of alias). I have checked /etc/bashrc as well as ~/.bashrc and /etc/profile as well as ~/.bash_profile for individual users, but none of these files contain the custom aliases for the system. What alternate files can contain system-wide aliases?

Shouvik Sayef

Posted 2013-05-03T21:11:18.827

Reputation: 111

Answers

6

Glad you found it, but here's a way to see all login files figure in the general sense:

# run strace, see every syscall
strace -o /tmp/bash.out bash --login

(Exit from bash shell)

# filter out opens that returned a descriptor, then use sed to get the file
< /tmp/bash.out grep -o 'open("[^,]*,[^)]*)[ \t]=[ \t][0-9]' | sed -e 's/^[^"]*"//' -e  's/".*$//' | sort -u > /tmp/openedfiles.txt

# grep for the broken alias, or whatever
< /tmp/openedfiles.txt xargs grep '^[ \t]*lias'

strace is one of those commands that can be magic if you know how to use it.

Rich Homolka

Posted 2013-05-03T21:11:18.827

Reputation: 27 121

@ShouvikSayef this "run something under strace, see all the open files" works in a tremendous number of contexts. It's not a bad tool to have around. I have the filter (grep/sed) as a shell script to make it easier to invoke this pattern. – Rich Homolka – 2013-05-06T02:54:03.053

0

found it: /etc/profile.d/useralias.sh

Shouvik Sayef

Posted 2013-05-03T21:11:18.827

Reputation: 111

0

And for the quick and dirty crowd, I would have...

grep ^lias ~/.* ; grep ^lias /etc/* /etc/*/*

and if that didn't point me the right way, I'd have resorted to...

grep alias ~/.* > /tmp/alias.txt ; grep alias /etc/* /etc/*/* >> /tmp/alias.txt ; less /tmp/alias.txt and proofread all alias lines.

Nevin Williams

Posted 2013-05-03T21:11:18.827

Reputation: 3 725