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

learn more… | top users | synonyms

167
votes
3answers
47k views

Difference between .bashrc and .bash_profile

What's the difference between .bashrc and .bash_profile and which one should I use?
104
votes
11answers
78k 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 ...
56
votes
4answers
15k 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 ...
103
votes
9answers
111k views

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

I type echo $PATH on the command line and get ...
9
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 ...
46
votes
6answers
13k 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
12
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 ...
20
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 ...
10
votes
3answers
1k 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?
73
votes
14answers
26k 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?
46
votes
4answers
13k 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 ...
38
votes
5answers
34k 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 ...
37
votes
5answers
15k 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.
25
votes
4answers
30k 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 ...
19
votes
10answers
15k 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 ...
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 ...
65
votes
12answers
39k 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 ...
41
votes
2answers
9k 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.
47
votes
7answers
36k 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. ...
29
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 ...
25
votes
3answers
5k 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 ...
32
votes
3answers
4k 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 ...
11
votes
2answers
2k 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 ...
2
votes
3answers
9k 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 ...
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 ...
7
votes
5answers
1k 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
3answers
3k 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.
2
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 ...
1
vote
3answers
270 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 ...
51
votes
12answers
16k 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 ...
77
votes
7answers
61k 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 ...
55
votes
1answer
42k 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!
37
votes
2answers
6k 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
5answers
1k 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 ...
8
votes
2answers
1k 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 ...
6
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 ...
13
votes
2answers
675 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 ...
9
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 ...
7
votes
8answers
4k 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 ...
6
votes
1answer
572 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
906 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?
8
votes
3answers
7k 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 ...
7
votes
2answers
3k 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 ...
12
votes
3answers
281 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 ...
2
votes
1answer
285 views

How do you remove nested empty directories using a Bash script on Linux?

I want to be able to run a script that will remove all my empty directories. The problem is some of them are nested, i.e. directories that only have empty directories in them, so the script needs to ...
1
vote
6answers
516 views

downloading complete web pages (not sites)

I often use offline time (e.g. when on the car/train/plane) to read articles pulled from the web. To store the content, I currently use Firefox's Save Page As. (Note that's not recursively downloading ...
8
votes
4answers
2k views

How to replace vim screen buffer with previous bash activity after quitting?

I'm trying to find out what a bash (or vim) feature is. Here's the scenario. I'm in a bash terminal, then edit something with vim, then exit back to bash. In some terminals, the vim session screen ...
3
votes
2answers
364 views

How to reorder folders? (as displayed in `ls -U`)

I've got a number of unordered folders on a memory stick, which my car stereo shows in order of their real position on the stick (i.e. same as ls -U) What's the easiest way of physically reordering ...
3
votes
2answers
4k views

How to use scp in a bash script without specifying password?

I am a bash newbie, and am writing a bash script that will allow transfer of files between two computers. BTW, is there a more secure alternative to scp? Currently, I am doing this manually, by using ...
85
votes
2answers
57k 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: ...