Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 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?
If you're using tcsh, then you're not going to want to put these aliases in .bashrc or .bash_profile. For tcsh, the user-specific settings can be added to ~/.tcshrc or ~/.cshrc; global settings are made in /etc/csh.cshrc. See man tcsh:
Quote:
Originally Posted by man tcsh
Startup and shutdown
A login shell begins by executing commands from the system files
/etc/csh.cshrc and /etc/csh.login. It then executes commands from
files in the user's home directory: first ~/.tcshrc (+) or, if
~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of the
histfile shell variable), then ~/.login, and finally ~/.cshdirs (or
the value of the dirsfile shell variable) (+). The shell may read
/etc/csh.login before instead of after /etc/csh.cshrc, and ~/.login
before instead of after ~/.tcshrc or ~/.cshrc and ~/.history, if so
compiled; see the version shell variable. (+)
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?
Not in CentOS specifically, but in bash in general, this feature is controlled by CDPATH variable.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.