alias on OpenWRT

 

On OpenWrt, your shell is ash (BusyBox Almquist shell), not Bash. You can configure aliases in /etc/profile for persistent use, or define them in your current session for temporary use.

1. Define an alias temporarily

For example:

alias ll='ls -lh'
alias la='ls -A'
alias l='ls -CF'
alias c='clear'

Test it:

ll
alias

These aliases disappear when you exit the shell.

2. Configure persistent aliases

I recommend putting your aliases in /etc/profile, which is the system-wide shell initialization file.

Step 1. Back up the original file.

cp /etc/profile /etc/profile.bak

Step 2. Edit it using vi.

vi /etc/profile

Append these lines at the end:

# User-defined aliases
alias ll='ls -lh'
alias la='ls -A'
alias l='ls -CF'
alias c='clear'
alias grep='grep --color=auto'

Save and exit with :wq.

Step 3. Reload the profile.

. /etc/profile

Now test:

alias
ll

Alternatively, log out and log back in.

3. A cleaner alternative: use a separate aliases file

If you want to keep /etc/profile tidy, create /etc/profile.d/aliases.sh:

mkdir -p /etc/profile.d
vi /etc/profile.d/aliases.sh

Put your aliases in that file, then ensure /etc/profile sources the directory:

[ -d /etc/profile.d ] && {
    for f in /etc/profile.d/*.sh; do
        [ -r "$f" ] && . "$f"
    done
}

Important: Check /etc/profile first; if it already loads /etc/profile.d/*.sh, do not add the loading code a second time.

4. Important OpenWrt considerations

  • ash is not Bash. Do not assume Bash-specific features such as ~/.bashrc will be loaded.

  • /etc/profile is system-wide. Changes affect login shells for all users.

  • OpenWrt configuration persistence: Files stored in /etc normally survive reboots and standard configuration reloads. A firmware upgrade may overwrite customizations, depending on the upgrade process and whether settings are preserved.

  • Aliases are interactive conveniences. For commands you want to use in scripts, standalone shell scripts in /usr/bin are generally a better choice.

My recommendation for your OpenWrt router is to use /etc/profile.d/aliases.sh if your installation supports it, or simply append a few aliases to /etc/profile. Keep it simple; a router does not need an elaborate shell configuration.

 

 

posted @ 2026-10-14 00:33  profesor  阅读(15)  评论(0)    收藏  举报