How to Create a System-Wide Alias for “ls -l” in Ubuntu


2 views

When working in a Unix-like environment, aliases are powerful shortcuts that can save time and reduce repetitive typing. While user-specific aliases are commonly defined in ~/.bashrc or ~/.bash_aliases, creating system-wide aliases requires a different approach.

In Ubuntu, the best place to define system-wide aliases is in /etc/bash.bashrc. This file is sourced for all users' interactive shells, making it ideal for global alias definitions.

# Open the file with sudo privileges
sudo nano /etc/bash.bashrc

Scroll to the bottom of the file and add your alias definition:

# System-wide aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'

Another clean method is to create a separate file in /etc/profile.d/:

sudo nano /etc/profile.d/aliases.sh

Add your aliases:

#!/bin/sh
alias ll='ls -l'
alias lh='ls -lh'

Make it executable:

sudo chmod +x /etc/profile.d/aliases.sh

After making changes, either:

# Source the changes for current session
source /etc/bash.bashrc

# Or log out and back in

1. System-wide changes affect all users - consider if this is truly needed
2. Some applications may not source these files in non-interactive shells
3. For root user, check if /root/.bashrc needs separate configuration

Here's a more complete set of useful aliases you might consider:

# File listing
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Safety nets
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Quick navigation
alias ..='cd ..'
alias ...='cd ../..'

Shell aliases are essentially shortcuts for longer commands. When you want to make ll work as ls -l across your entire Ubuntu system, you need to understand where these aliases are typically defined:

# Temporary alias (only lasts for current session)
alias ll="ls -l"

To make aliases available to all users, you have several configuration file options:

  • /etc/bash.bashrc - Affects all users using bash
  • /etc/profile.d/ directory - Preferred method for system-wide changes
  • /etc/environment - For environment variables (not recommended for aliases)

The cleanest method is to create a custom file in /etc/profile.d/:

sudo nano /etc/profile.d/custom_aliases.sh

Add your alias definition:

# System-wide aliases
alias ll="ls -l"
alias la="ls -la"

After creating the file, ensure it's executable and readable by all users:

sudo chmod +x /etc/profile.d/custom_aliases.sh
sudo chown root:root /etc/profile.d/custom_aliases.sh

The changes will take effect after:

  • Starting a new shell session
  • Running source /etc/profile

Verify with:

type ll
# Should output: ll is aliased to 'ls -l'

For bash-specific systems, you can also modify /etc/bash.bashrc directly:

echo 'alias ll="ls -l"' | sudo tee -a /etc/bash.bashrc
  • System-wide changes affect all users - use responsibly
  • Some applications (like cron jobs) might not source these files
  • For zsh users, you'll need to modify /etc/zsh/zshrc instead