Bash is a free shell for Unix-like operating systems from the GNU Project.

learn more… | top users | synonyms

240
votes
3answers
69k views

Difference between .bashrc and .bash_profile

What's the difference between .bashrc and .bash_profile and which one should I use?
69
votes
4answers
21k views

Forward SSH traffic through a middle machine

SSH tunneling is very confusing to me. I am wondering if I can do this in Linux. I have 3 machines.. A. My local machine at home. B. Machine at work that I can SSH into (middle man). C. My desktop ...
146
votes
13answers
123k views

How do I detach a process from Terminal, entirely?

I use Tilda (drop-down terminal) on Ubuntu as my "command central" - pretty much the way others might use GNOME Do, Quicksilver or Launchy. However, I'm struggling with how to completely detach a ...
112
votes
8answers
125k views

Where does $PATH get set in OS X 10.6 Snow Leopard?

I type echo $PATH on the command line and get ...
95
votes
16answers
63k views

How to delete all files in a directory except some?

I need to delete all files in a directory, but exclude some of them. For example, in a directory with the files a b c ... z, I need to delete all except for u and p. Is there an easy way to do this?
75
votes
7answers
27k views

What is the difference between executing a bash script and sourcing a bash script?

What is the difference between executing a bash script like A and sourcing a bash script like B? A >./myscript B >source myscript
10
votes
1answer
2k views

Leave bash script running on remote terminal while not logged in?

I have a bash script that takes several hours to run. While it's running, I would like to do other things, which may involve logging out or disconnecting from the internet (my script runs network ...
64
votes
5answers
19k views

Does bash have a hook that is run before executing a command?

In bash, can I arrange for a function to be executed just before running a command? There is $PROMPT_COMMAND, which is executed before showing a prompt, i.e., just after running a command. Bash's ...
24
votes
1answer
3k views

Is there a way to make bash more TAB friendly?

I use bash on both my Mac and as my cygwin shell. Overall, I'm quite pleased with it. My one complaint however is that its TAB completion isn't as good as Windows Command Line TAB completion. For ...
11
votes
3answers
2k views

Is it possible to change my terminal window prompt text?

My terminal window default prompt text takes up too much space (I guess my computer name is too long). Can I customize this?
14
votes
6answers
4k views

How can I move around the bash commandline efficiently?

So I use the up in my shell (Bash on OSX or Ubuntu, mostly) but some of the time I know that I want the stuff after the cursor's current location. Is there any way to have the line I'm on complete ...
18
votes
3answers
1k views

What does this cryptic Bash command mean?

I was reading Ubuntu Forum's warning about malicious commands and found this interesting gem: :(){ :|:& };: WARNING: The above code will crash your machine unless you have strict proc ...
53
votes
6answers
24k views

Set the title of the terminal window to the current directory

How can I get the Terminal.app in OS X to display the current directory in its window or tab title? I'm using the bash shell.
30
votes
10answers
25k views

Bash: Reset and Clear Commands

I have been using the command: reset to clear my terminal. Although I am pretty sure this is not what I should be doing. Reset, as the name suggests resets your entire terminal (changes lots of ...
173
votes
7answers
141k views

What does 'source' do?

$ whatis source source: nothing appropriate. $ man source No manual entry for source $ source bash: source: filename argument required source: usage: source filename [arguments] It exists, and it is ...
56
votes
7answers
51k views

How to configure PuTTY so that Home/End/PgUp/PgDn work properly in bash?

The keys Home, End, PageUp, PageDown all type a ~ in my bash session instead of moving the cursor / view around. Why does this happen and which settings do I need to change? GNU bash, version ...
34
votes
4answers
51k views

How do I make Bash my default shell on Ubuntu?

I have a .bash_profile in my home directory, but it isn't getting run on login. If I do the following, then things seem to be as I expect: ssh myhost bash source ~/.bash_profile But normally that ...
39
votes
3answers
6k views

Why is . not in the path by default?

On UNIX-like systems over the years (most relevantly to me, Linux), I've noticed that . (current dir) is never in the $PATH by default. Why is this? I recall reading years ago that it was a security ...
10
votes
3answers
2k views

Calling a script with ./bla.sh vs. . bla.sh

Can anybody explain to me what the shell does in the two examples A) and B) below? It obviously behaves differently, but I can't find out why the output is different. Example: Let's have a script in ...
4
votes
3answers
4k views

Add folder to PATH

How to add something to PATH ? I have added like PATH=$PATH:/home/example export PATH and it works until I restart , after that when I type env in PATH there is no /home/example.
58
votes
3answers
20k views

Git Bash Here in ConEmu

How do I create a right-click context menu entry to open Git Bash at a given folder within ConEmu? See Git Bash Here in Console2 for the equivalent question for Console2.
74
votes
12answers
46k views

How to get git-completion.bash to work on Mac OS X?

I have followed http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without to add git-completion.bash to my /opt/local/etc/bash_completion.d/git-completion and I put ...
72
votes
17answers
21k views

Add directory to $PATH if it's not already there

Has anybody written a bash function to add a directory to $PATH only if it's not already there? I typically add to PATH using something like: export PATH=/usr/local/mysql/bin:$PATH If I construct ...
69
votes
7answers
63k views

What to do when Ctrl + C can't kill a process?

Ctrl + C doesn't always work to kill the current process (for instance, if that process is busy in certain network operations). In that case, you just see "^C" by your cursor and can't do much else. ...
31
votes
3answers
3k views

Can history files be unified in bash?

I routinely run multiple screen sessions on my Linux desktops and servers. A problem with this is that when I grep through my command history, I find I issued a command in a different session, and ...
45
votes
3answers
8k views

What does the 'rc' in `.bashrc`, etc. mean?

Well, this is embarrassing. I feel like I just realised I don't know a loyal colleague's name after working with them for 10 years. "Hey, er... *cough!*, thanks for that great job you did on setting ...
34
votes
5answers
2k views

In bash, how can I rename a file without repeating the path? [duplicate]

Possible Duplicate: Reuse text on a bash command If I want to rename a file a few directories deep, how can I avoid repeating the path? For example: mv path/to/old_filename.txt ...
32
votes
3answers
3k views

Have a file named ~ (tilde) in my home-directory

I just noticed that I have a file called ~ in my ~-directory. $ ls -la ~ ... -rw-r----- 1 x1 x1 733962240 Mar 1 17:55 ~ ... Any idea how I can mv or rm it?
12
votes
7answers
6k views

Replace Symbolic Links with Files

Is there an easy way to replace all symbolic links with the file they link to?
4
votes
3answers
13k views

Ubuntu/ Gnome : Open an application in a specific workspace

How do tell an application to open in a specific workspace? More info: I like to have my C++ IDE in workspace 2, my Java IDE in workspace 3, and my email, browser and miscellaneous in workspace ...
14
votes
2answers
4k views

Unix: Files starting with a dash, -

Ok, I have a bunch of files starting with a dash, -. Which is not so good... and I want to rename them. In my particular case I would just like to put a character in front of them. I found the ...
8
votes
2answers
5k views

What is cmd's equivalent to Bash's & (ampersand) for running a command without waiting for it to terminate?

In bash: java -jar jarfile1.jar & java -jar jarfile2.jar & The ampersand lets you launch the first program, and then do another one while the first is still running. How do I do this in ...
8
votes
5answers
2k views

Search for a text pattern in linux

I'm a linux newbie. I need to search for a string "teststring" in all *.java files coming under /home/user1/ (including subfolders). How can I do it in linux via shell command.
3
votes
4answers
2k views

how to get beep working?

I have a laptop, I've installed the beep package. I turned every sound to full, and I do this: $ beep But I can't hear any beeping sound. What am I missing? I just need to run the beep when a ...
2
votes
3answers
408 views

How to start bash and immediately “type” command into it?

I want bash to first execute a command, but after the command finishes (or Ctrl+C'ed) go into interactive mode (preferrably with the command in history, available for up). How to attain it in easiest ...
100
votes
2answers
87k views

How do I change my default shell from bash to zsh?

I want to change my shell from the default bash shell to zsh on my Amazon EC2 instances. How do I go about doing it? Thanks!
134
votes
3answers
111k views

Go back to previous directory in shell

Is there a way to go back to previous directory we were in using bash,tcsh without using pushd/popd ? I'd like to type something like "back" and got returned to the previous directory I was in. Edit: ...
60
votes
2answers
10k views

Case insensitive tab completion in Bash

Is there any way to make Bash tab complete case insensitively? $ bash --version GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0) Copyright (C) 2007 Free Software Foundation, Inc. I am ...
31
votes
4answers
45k views

How to pipe command output to other commands?

Example: ls | echo prints nothing ( a blank line, actually ). I'd expect it to print a list of files. ls | grep 'foo', on the other hand, works as expected ( prints files with 'foo' in their name ). ...
27
votes
1answer
15k views

Bash completion for commands in Mac OS X

How do I get fink and macports to autocomplete program names when typing commands, as in Ubuntu's apt-get? For example when I type sudo port install ca and press tab, I want the terminal to ...
10
votes
1answer
2k views

How do I make OS X set the terminal title back to the original title when coming back from ssh?

Starting on OS X, I ssh into foo (a Linux box). My terminal title changes to foo. I then ssh into bar (another Linux box). My terminal title changes to bar. I log out of bar. My terminal title ...
16
votes
2answers
872 views

How to prevent Bash from altering history?

If I press the Up or Down arrows on my keyboard and then modify something from my history, it's changed forever. Even if I press Ctrl-C and then try to bring it up again, it's still changed -- I've ...
11
votes
8answers
5k views

Pushing my PS1 prompt over ssh

I use a specific PS1 prompt that I like. I share a few logins with other other people on a few different servers. I was wondering if there was a way to specify in my local bash profile a remote prompt ...
10
votes
2answers
2k views

Tab-completion with directories/links

I have this problem with tab-completion in terminal in both archlinux and ubuntu: I have a link which links to a directory named "something" in my home directory. Now when I open a terminal and want ...
8
votes
1answer
2k views

Make OS X Terminal commands I type BOLD

I'd like to make commands I've typed (input) into terminal stand out from all the output. For example: imac:~ buster$ chmod -R g-w myfolder imac:~ buster$ cd myfolder imac:myfolder buster$ ls -l ...
14
votes
3answers
5k views

How can I do Ctrl-Z and bg in one keypress to make process continue in background?

I follow this pattern of suspending the task and then letting it to continue too often with the Ctrl-Z bg sequence. I was wondering is there any way to compress that to single keypress? My shell is ...
7
votes
1answer
653 views

bash: per-command history. How does it work?

OK. I have an old G5 running Leopard and a Dell running Ubuntu 10.04 at home and a MacPro also running Leopard at work. I use Terminal.app/bash a lot. On my home G5 it exhibits a nice feature: using ...
13
votes
1answer
954 views

When should I put configurations into .bashrc vs into. .bash_profile?

I was looking at Questin 9152: Why doesn’t my path update now?. Which customizations should go into my ~/.bashrc file vs. into my ~/.bash_profile file?
13
votes
3answers
316 views

Reuse text on a bash command

If i'm writing a long command or just typing an extensive file path, is there any that i can "reuse" it with some command shortcut? e.g: 1.cp /home/myuser/really/big/file/here/and/there.png ...
10
votes
3answers
10k views

Filtering top command output

I'm running a Mac and want to filter the output of the top command for a particular process such that only the PID, COMMAND and %CPU columns are displayed. After getting the PID of the process, I ...