Where to place my command aliases?

Archived topics about LMDE 1 and LMDE 2
Locked
userzero

Where to place my command aliases?

Post by userzero »

Hello,

I've been trying to locate the bash files for placing command aliases, both for root and user accounts. Most of the help online says to place the alias lines (I know the syntax for these) in .bashrc and .bash_aliases, but I see neither in user or root home directories. Can anyone please give me a tip here?

Thanks
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
xircon

Re: Where to place my command aliases?

Post by xircon »

Put them in .bashrc or put:

Code: Select all

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
In .bashrc to use .bash_aliases.

Steve
userzero

Re: Where to place my command aliases?

Post by userzero »

Hmm...

I don't have either files in root or user directories. Here is what my default install has in my root directory:

olaris ~ # ls -la
total 40
drwx------ 8 root root 4096 Jul 14 09:28 .
drwxr-xr-x 23 root root 4096 Jul 14 09:17 ..
drwx------ 2 root root 4096 Jul 14 11:03 .aptitude
-rw------- 1 root root 333 Jul 14 11:16 .bash_history
drwx------ 3 root root 4096 Jul 14 11:18 .gconf
drwx------ 2 root root 4096 Apr 18 11:15 .mateconf
-rw-r--r-- 1 root root 140 Nov 19 2007 .profile
drwx------ 3 root root 4096 Jul 14 09:29 .synaptic
drwxr-xr-x 2 root root 4096 Nov 26 2010 .ure
drwxr-xr-x 2 root root 4096 Nov 26 2010 .wapi

If I create those 2 files, what exactly should be in them?

Thanks,

u0
xircon

Re: Where to place my command aliases?

Post by xircon »

In your users home - mine is /home/molly3/.bashrc

Then reload with:

Code: Select all

source ~/.bashrc
from a terminal
veggen

Re: Where to place my command aliases?

Post by veggen »

You can simply create the files if they don't already exist. Then, do as xircon explained in his first response.
userzero

Re: Where to place my command aliases?

Post by userzero »

veggen wrote:You can simply create the files if they don't already exist. Then, do as xircon explained in his first response.
Okay... so I created a blank file called ".bashrc" in both root's home directory and my user's home directory. Both chmod to 755 with the aliases placed in the files for example: alias lsx='ls -la | more'

I rebooted the computer and voila, none of the aliases work for any account. My knee-jerk reaction is that the .bashrc file needs something in it besides just command aliases and if this is true,
I wonder what those things are. There are plenty of sample .bashrc files on the Web but they differ slightly, leaving me confused as to what to do next.

-cj
aes2011
Level 4
Level 4
Posts: 498
Joined: Wed Jul 06, 2011 10:39 pm

Re: Where to place my command aliases?

Post by aes2011 »

userzero wrote:Hello,

I've been trying to locate the bash files for placing command aliases, both for root and user accounts. Most of the help online says to place the alias lines (I know the syntax for these) in .bashrc and .bash_aliases, but I see neither in user or root home directories. Can anyone please give me a tip here?

Thanks
Could you explain why you want to do stuff for the root account?
widget

Re: Where to place my command aliases?

Post by widget »

I am having a major problem with the concept of not having a ~/.bashrc file in the first place.

This is mine from my Debian testing install that I use all the time. This is the default ~/.bashrc file.

Code: Select all

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
#[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
Are you sure you have bash installed? Are you sure it is your default shell? You should have dash installed also, are you sure you have not been using it?

I would put the ~/.bashrc that you created somewhere else or rename it.

I would then try;

Code: Select all

sudo dpkg-reconfigure bash
If this doesn't get you a ~/.bashrc file I would go to Sysnaptic, being nervous of doing this in a teerminal with this condition of yours, and mark bash for "complete removal" and remove it.

Reinstall the thing making sure that you have removed it from /var/cache/apt/archives. This will make sure that a new package is downloaded and installed instead of the package that is not correctly installed being reinstalled.

Reboot after doing that if you do not have the ~/.bashrc file and see if that gets it. If not you have a real problem with your shell.
userzero

Re: Where to place my command aliases?

Post by userzero »

Alright, found this bash tutorial and it pretty much explains the situation. Nothing wrong with the Bash install.

u0

http://www.hypexr.org/bash_tutorial.php#config
Locked

Return to “LMDE Archive”