Path shortcuts in CentOS
Is there a way to set a short cut so that you don't have to type out the full path to directories in CentOS? For example instead of typing out /var/log to get to log files, can you just type logs and have the OS know to cd to /var/log automatically?
Thanks |
In your .bashrc or .bash_profile (whichever you use at the moment), define an alias:
Code:
alias logs='cd /var/log' Code:
. ~/.bashrc |
Thanks pwc, which should be used, bash_profile or bashrc? And what is the way for all users to use this shortcut? Also, can you please provide a solutions for the tcsh equivelant?
Many thanks! |
tcsh? *shudder*
I think the syntax is similar for tcsh: Code:
alias logs 'cd /var/log' Quote:
|
Quote:
a CDPATH variable set as this: Code:
CDPATH=.:~:/export/main/fileserver:/var/lib/samba:/var/lib/samba/netlogon:/opt:/var/log so, "cd Documents" will change to "/export/main/fileserver/Documents" (or any directory bellow of /export/main/fileserver) "cd profiles/JohnDoe" will change directory to "/var/lib/samba/netlogon/profiles/JohnDoe" This is much better than creating several aliases, one for each directory, specially if you have many of then. PS: On tcsh the variable which has the same meaning is just "cdpath" |
Quote:
|
Thanks marozsas, but im a little lost about your helpful response. If i want to type cd logs and have it go to /var/log would be CDPATH look like this?
CDPATH=.:~:/logs:/var/log |
hi investmentbnker75,
For just a single (or a few) folder like /var/log, using CDPATH is not the better option. It is better to create an alias, just like pwc101 told you; Even so, for this single case, in bash: "CDPATH=/var" (in tcsh: "set cdpath=/var") would do the trick, and "cd log" will change to "/var/log" and "cd named" will change to "/var/named" and "cd spool" to "/var/spool". Things become more complicated as soon you start to create several aliases and at this point, CDPATH makes more sense. |
All times are GMT -5. The time now is 06:11 AM. |