.bashrc is the primary configuration file for the bash shell.

learn more… | top users | synonyms

69
votes
4answers
110k views

How to correctly add a path to PATH?

I'm wondering where a new path has to be added to PATH environment variable. I know this is accomplished editing .bash_rc (for example), but it's not clear how to do this. This way: export ...
24
votes
3answers
482 views

Multicolored Grep

I'm trying to get each grep command to highlight it's results in a different color. I can do it manually with a line like this: ls -l GREP_COLORS='mt=01;32' grep c | GREP_COLORS='mt=01;31' grep o | ...
14
votes
2answers
282 views

bash_history: comment out dangerous commands: `#`

To prevent logging "dangerous" commands in bash history, I have added following line to my .bashrc file: HISTIGNORE='rm *:mv *:cp *:cat*>*:pv*>*' this works well, but it has a side effect: I ...
14
votes
2answers
893 views

.bashrc overwritten but still sourced — how can it be recovered?

Usually when I find a command I want to alias, I echo it to my .bashrc like so: [up button pressed to last command, then line edited so that it reads] $echo "command-i-just-did" >> ~/.bashrc ...
13
votes
2answers
6k views

What is the difference between ~/.profile, ~/.bashrc, ~/.bash_profile, ~/.gnomerc, /etc/bash_bashrc, /etc/screenrc …?

Answers to the questions on SO and askubuntu, along with poking through (and reading headers of) $HOME and /etc/, indicate a number of files that can be used to set environment variables, including: ...
11
votes
4answers
748 views

How can I source the bashrc file every time I 'clear'

This might be a bad idea. The more I think about it the more I come to the realization that I probably shouldn't do it... but I've been trying and failing so I REALLY want to know how to do it, even ...
11
votes
3answers
4k views

How do I get rid of Cygwin's /cygdrive prefix in all paths?

I'm switching to Cygwin from the bash shell that ships with Git for Windows, and encountering a strange problem. Someone thought it would be a good idea to add /cygdrive/ to all paths, while I think ...
10
votes
5answers
451 views

How to test for possible conflicts while using alias in bashrc?

Is there a simple way to list all the command conflicts that have occurred in the system due to the bashrc update involving alias commands? For example, someone writes alias ...
9
votes
3answers
894 views

How can I find a rogue alias declaration?

I'm trying to find where a specific alias has been declared. I've searched all the usual places I know to look for aliases: ~/.bashrc ~/.bash_profile /etc/bashrc /etc/profile With no luck. I know ...
8
votes
2answers
167 views

using export in .bashrc

I have noticed in my .bashrc, that some lines have export in front, such as export HISTTIMEFORMAT="%b-%d %H:%M " ... export MYSQL_HISTFILE="/root/.mysql_history" whereas other have not, such as ...
8
votes
1answer
1k views

How can I change screen's hardstatus color based on the logged in user?

I haven't edited/created a .screenrc file in a while, but this is what I'm currently using: # Turn off the screen startup message startup_message off # Define format of bottom ...
7
votes
7answers
3k views

Doing simple math on the command line using bash functions: $1 divided by $2 (using bc perhaps)

Sometimes I need to divide one number by another. It would be great if I could just define a bash function for this. So far, I am forced to use expressions like echo 'scale=25;65320/670' | bc but ...
7
votes
2answers
116 views

How can I create a local function in my bashrc?

My .bashrc had some code that was repetitive so I used a function to simplify it do_stuff() { local version=$1 export FOO_${version}_X="17" export FOO_${version}_Y="42" } do_stuff '5.1' ...
7
votes
3answers
96 views

In shell config scripts, how can I account for differences between coreutils on BSD compared to GNU?

Up until this month, my shell configs have been pretty simple (just a .bashrc or .bash_profile with some aliases mainly), but I have been refactoring it so I can get different behavior depending on ...
7
votes
1answer
902 views

How to detect when a shell is owned by a remote SSH session?

My question is similar to this one, but I'm looking for something slightly different. I have a notebook PC that I use to access Linux machines on a network in two different scenarios: I have a ...
6
votes
3answers
504 views

How to tell if terminal session is running within screen

When running a bash script, I would like to be able to tell if it is running within a screen. Is this possible? I want this so that .bashrc can set the colour of the command prompt depending on ...
5
votes
2answers
479 views

Can a home directory have both .cshrc and .bashrc files?

Or are they both not allowed at the same time?
5
votes
2answers
178 views

l, ls & la — what are the differences, and are there more of these commands?

So, through typing several commands I've found that there's not only ls, but l and la too. There doesn't appear to be any man entries on Ubuntu 12.14. They all appear to do similar things with minor ...
5
votes
2answers
4k views

What is the difference between interactive shells, login shells, non-login shell and their use cases? [duplicate]

Possible Duplicate: Difference between Login Shell and Non-Login Shell? I have been looking at /etc/profile. bash.bashrc to see how they are run, and notice that some are executed by ...
5
votes
3answers
435 views

Run ssh login command without modifying remote .bashrc

We have a bunch of servers set up with set -o vi in their ~/.bashrc. It would be nice to be able to ssh into these boxes and automagically run set -o emacs as a timesave. I've seen a solution ...
5
votes
1answer
106 views

Is there a Bash file that will be always sourced in interactive mode no matter if it is login or non-login?

As far as I know the interactive shells may be login or not login and the start up files for them are different. If interactive + login shell → /etc/profile then the first readable of ...
5
votes
2answers
104 views

how to add command line calculator to bash that uses comma as decimal mark?

How can I add a command line calculator to my bash? I have found some, but all of them use the full stop as decimal mark, but I want to have it to use the comma as decimal mark as most of the world ...
5
votes
3answers
45 views

How can I make my .bashrc call to shopt -s autocd depend on the bash version?

In Ubuntu I like having shopt -s autocd in my .bashrc file for automatic CD'ing with typing 'cd', i.e. just type the directory name (and probably use tab completion too) and press return and be ...
5
votes
2answers
89 views

How to report time and other information on all bash commands? [duplicate]

Most of the things I run in the terminal take a long time to compute and I would like to have bash output a time report at the end of every command entered into the terminal. Is there something I can ...
4
votes
2answers
210 views

How do I execute a command on login for a system user with no home folder and no personal .bashrc file?

I set these users' home folders through the /etc/passwd file, but when they log in I would like them to activate a python virtualenv. If they had a personal .bashrc file, I'd just include the activate ...
4
votes
1answer
177 views

View shell function's current definition

So I am editing bashrc constantly, and I have a terminal open with a working function definition, although bashrc has been updated with a wrong function definition. (Because the definition do not ...
4
votes
1answer
1k views

Problems with automatically starting screen on SSH login

I'm looking at http://taint.org/wk/RemoteLoginAutoScreen to setup my server so it autostarts a screen session when I login via SSH. I have added the following to my .bashrc: # Auto-screen ...
4
votes
3answers
945 views

Added bin directory to my path, can't execute commands in it with 'sudo command'

I made a bin directory in my home folder where I place all my scripts. Then in my .bashrc I added the following: export PATH=$PATH:/home/myusername/bin So I could access files I placed in there ...
4
votes
2answers
3k views

Global bash_profile

I realize there are /etc/profile and /etc/bashrc files for setting global environment variables and maybe I'm just misunderstanding their purposes, but... Is their a global bash_profile file? This ...
3
votes
4answers
316 views

Why no shebang in .bashrc/.bash_profile?

Simple inquiry: I have just realized that I have never seen a shebang on top of a .bashrc script, which leads me to think the system uses the default shell to source it upon login (${SHELL}). I am ...
3
votes
2answers
215 views

Bash doesn't read .bashrc unless manually started

bash won't source .bashrc from an interactive terminal unless I manually run bash from a terminal: $ bash or manually source it: $ source ./.bashrc or running: $ st -e bash Here's some useful ...
3
votes
2answers
110 views

How to make .bashrc call dependant on tmux program being installed?

I have a section in my .bashrc that fires up the tmux program (terminal multiplexor). However if the tmux program isn't installed (say I'm setting up a new computer) then having this in my .bashrc ...
3
votes
1answer
87 views

Keep two bash history files, one with ignoredups, one with everything

For the purposes of looking at which commands I am using the most, I'd like to keep a record of command I type in my bash history (even duplicates). But, for sanity and ease of use, I still want to ...
3
votes
1answer
85 views

Change the location of .bashrc

Is it possible to change the location of .bashrc from /home/orhanc/.bashrc to some other directory?
3
votes
4answers
294 views

Bash aliases/functions and command line options

I want to set an alias to start nedit together with command line option -noautosave (due to text files up to 500MB). What seemed to be easy: alias nn="nedit -noautosave $1 &" just raises some ...
3
votes
2answers
110 views

Preventing accidental directory deletion. Making an alias that contains options?

I use an alias to prevent me from accidentally deleting files, and I would like to do something similar for directories. For files, I have the following added to my .bashrc: alias rm="rm -i" I ...
3
votes
2answers
229 views

How can I use aliases in commands?

I have created aliases in my .bashrc for various frequently used long paths but I can not seem to be able to use them inside vim or with commands such as find or grep. E.g the following: db in cli ...
3
votes
1answer
38 views

Why did my “d” break when I screwed up a bind?

I was swapping some readline settings in my .bashrc earlier today and mistyped the following (bind since it's not in .inputrc): bind "mark-symlinked-directories on" I forgot to put a set in there ...
2
votes
1answer
212 views

How to make a permanent variable

In terminal: VAR="Extremely long and often used command" echo $VAR Output: Extremely long and often used command So far it works fine, but after restarting a terminal my variable doesn't ...
2
votes
3answers
222 views

What is the difference between ./script and . ./script? [duplicate]

Possible Duplicate: Using ‘.’ to execute files in bash I was trying to figure out how to export my environmental via script instead of changing my .bashrc file. I found this old useful ...
2
votes
2answers
3k views

Where is the system profile that gets sourced at login on CentOS 5.8?

In CentOS release 5.8 (Final), where is the bash system profile? Is it /etc/profile ? I've added the following to source my ~/.bashrc file but haven't had any luck as it fails. I know it fails ...
2
votes
3answers
181 views

SSH parameter to ignore .bashrc script

I have a server which when it starts, a line in .bashrc executes the following command /bin/watch ~/checker.bash which as expected watches that command upon server start. I also have a client which ...
2
votes
3answers
130 views

sudo command after long sleep call without re-prompting sudo password

I'm trying to write a simple bash function that sleeps X-number of mins and then runs a system sleep command (for me it's sudo pm-suspend since I'm on Ubuntu) right now the function looks like this: ...
2
votes
2answers
119 views

Is there any way I can fit this into my ~/.bashrc as a function?

I just discovered this useful bit of code on this useful-looking website. #!/bin/sh exec tclsh "$0" ${1+"$@"} proc main {} { set lines [lrange [split [read stdin] \n] 0 end-1] set count ...
2
votes
3answers
300 views

When the lines of a file or directory get too long, upgrade to ls list format?

Is there a way I can do this? For example if a gets a long name like: i-have-names-that-are-too-long-to-describe/ i-have-names-that-are-too-long-to-describe-2/ ...
2
votes
1answer
201 views

Alias in .bashrc doesn't seem to accept an argument [duplicate]

Possible Duplicate: In Bash, when to alias, when to script, and when to write a function? I'm trying to setup an alias in my .bashrc file, but it's not working as expected. I have this ...
2
votes
1answer
48 views

Where can I find a good boilerplate bashrc?

I've used unix/linux at work in the past, and recently started developing on a Mac. I'd always (lovingly) borrow co-workers' bashrc's for a good starting point, such as common aliasing and commands, ...
2
votes
2answers
28 views

Setting tabstop for bash output

Is it possible to set a tabstop (number of spaces per tab) for the more and less commands? In vi, I've added this line to .vimrc set tabstop=4 However when I read through a file with more it still ...
2
votes
4answers
70 views

Defining aliases for a certain directory

Is there a way to have an alias set for a particular directory and its subdirectories? I know I can put it in my .bashrc file, but I would like it only for a certain directory. Edit: what i mean is ...
2
votes
1answer
61 views

How to make an alias active in both current session and in .bashrc at same time?

I just found frequently I decide to add an alias for longer time use at the same time use it now. So I have to type the same thing twice, first in current bash session then .bashrc.