Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want short way to access files, which i usually use in bash. For example, see logs. Now i use:

less /var/log/user/server.log
less /var/log/user/server2.log

I want shortcut, to do

less server.log
less server2.log

I try this variant in .bash_profile, but have mistake somewhere:

less() { if [[ $@ == "server.log" ]]; then command less /var/log/user/server.log; else command less "$@"; fi; }

Thanks in advice!

share|improve this question

migrated from May 13 '13 at 12:12

This question came from our site for professional and enthusiast programmers.

up vote 5 down vote accepted

you could symlink the files like so:

ln -s /var/log/user/server.log server.log
ln -s /var/log/user/server2.log server2.log

And then you can do whatever you want with these files as:

less server.log
tail -f server2.log
share|improve this answer

less $serverlog
share|improve this answer

I got bored so I wrote this bash shell function for you:

    OIFS="$IFS"; IFS=:
    lesspath=('' $LESSPATH)
    for arg ; do
            for path in "${lesspath[@]}" ; do
                    if [[ -e "${file}" ]] ; then
                            command less "${file}"
                            continue 2
            command less "${arg}"

Put this shell function into your .bashrc, set LESSPATH=/var/log/user and now you can run less as you want to.

You can add other paths to LESSPATH by separating them with colons, just like the other PATH environment variables. So, if you set LESSPATH=/var/log:/var/log/user, you could also easily run less syslog from anywhere to easily see /var/log/syslog.

share|improve this answer

To use aliases you could do something like this too..

add this to .bashrc

function lss { less "$1"; }
export lss
alias lf='echo /var/log/syslog'


. ~/.bashrc

Now you can do :

less $(lf)


lss $(lf)
share|improve this answer

You must log in to answer this question.