Where to place my command aliases?

All Gurus once were Newbies
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Please stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions prefer the other forums within the support section.
Before you post please read this

Where to place my command aliases?

Postby userzero on Fri Jul 13, 2012 11:43 pm

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
userzero
Level 1
Level 1
 
Posts: 21
Joined: Sun Apr 08, 2012 6:49 pm

Linux Mint is funded by ads and donations.
 

Re: Where to place my command aliases?

Postby xircon on Sat Jul 14, 2012 4:39 am

Put them in .bashrc or put:
Code: Select all
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi


In .bashrc to use .bash_aliases.

Steve
Dell Inspiron N5010 / Core I5 / ATI Mobility Radeon HD5400, LMDE Tracking Sid & Cinnamon Desktop
"Ubuntu is an African word meaning 'I can't configure Debian'"
User avatar
xircon
Level 5
Level 5
 
Posts: 775
Joined: Sun Aug 01, 2010 7:59 am
Location: Sheffield, UK

Re: Where to place my command aliases?

Postby userzero on Sat Jul 14, 2012 2:21 pm

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
userzero
Level 1
Level 1
 
Posts: 21
Joined: Sun Apr 08, 2012 6:49 pm

Re: Where to place my command aliases?

Postby xircon on Sat Jul 14, 2012 4:45 pm

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

Then reload with:
Code: Select all
source ~/.bashrc

from a terminal
Dell Inspiron N5010 / Core I5 / ATI Mobility Radeon HD5400, LMDE Tracking Sid & Cinnamon Desktop
"Ubuntu is an African word meaning 'I can't configure Debian'"
User avatar
xircon
Level 5
Level 5
 
Posts: 775
Joined: Sun Aug 01, 2010 7:59 am
Location: Sheffield, UK

Re: Where to place my command aliases?

Postby veggen on Sat Jul 14, 2012 5:21 pm

You can simply create the files if they don't already exist. Then, do as xircon explained in his first response.
User avatar
veggen
Level 4
Level 4
 
Posts: 401
Joined: Mon May 09, 2011 4:54 am

Re: Where to place my command aliases?

Postby userzero on Sat Jul 14, 2012 9:37 pm

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
userzero
Level 1
Level 1
 
Posts: 21
Joined: Sun Apr 08, 2012 6:49 pm

Re: Where to place my command aliases?

Postby aes2011 on Sat Jul 14, 2012 10:20 pm

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?
aes2011
Level 4
Level 4
 
Posts: 255
Joined: Wed Jul 06, 2011 10:39 pm

Re: Where to place my command aliases?

Postby widget on Sun Jul 15, 2012 11:41 am

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.
Dell XPS 420 Core2 Quad Q 6600, audigy5.1, Radeon HD 6450 - currently 4 320Gb HDD, Debian Squeeze for secure use, Debian testing for daily use, Debian Sid for fun.
widget
Level 3
Level 3
 
Posts: 167
Joined: Thu May 14, 2009 2:49 am
Location: S.E. Montana

Re: Where to place my command aliases?

Postby userzero on Tue Jul 17, 2012 10:02 am

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
userzero
Level 1
Level 1
 
Posts: 21
Joined: Sun Apr 08, 2012 6:49 pm

Linux Mint is funded by ads and donations.
 

Return to Newbie Questions

Who is online

Users browsing this forum: No registered users and 4 guests