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
-
ashis not Bash. Do not assume Bash-specific features such as~/.bashrcwill be loaded. -
/etc/profileis system-wide. Changes affect login shells for all users. -
OpenWrt configuration persistence: Files stored in
/etcnormally 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/binare 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.

浙公网安备 33010602011771号