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

learn more… | top users | synonyms

195
votes
3answers
57k views

Difference between .bashrc and .bash_profile

What's the difference between .bashrc and .bash_profile and which one should I use?
130
votes
9answers
14k views

I accidentally typed password into bash command line

I accidentally typed my password into bash command line, mistaking the Last login: ... line for Wrong password (I was in a hurry). What do I do to cover my trace? What I did was editing .bash_history ...
115
votes
12answers
96k 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 ...
115
votes
7answers
92k 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 ...
106
votes
8answers
118k views

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

I type echo $PATH on the command line and get ...
101
votes
2answers
78k 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: ...
95
votes
4answers
48k views

Why does Ctrl + V not paste in Bash (Linux shell)?

When I copy something to the clipboard and press Ctrl + V in Bash, nothing happens; However, right clicking and selecting Paste does the job. Why? Is there any reasonable issue (I'm sure there is) ...
92
votes
6answers
89k views

chown is not changing symbolic link

I'm trying to change the user/group of a symbolic link with the command: $ chown -h myuser:mygroup mysymbolic/ But it's not changing. I'm logged in as root. The current user/group is set to ...
84
votes
16answers
43k 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?
78
votes
9answers
37k views

How can I search the bash history and rerun a command?

Can I search history in bash and run the result?
70
votes
12answers
43k 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 ...
66
votes
10answers
39k views

Is it possible to `tail -f` the output of `dmesg`?

Want to do something like dmesg | tail -f but it doesn't work: I use Mac OSX 10.6.7, by doing that the tail will exit, instead of monitoring the output. I wonder if there is any way to do it, or ...
65
votes
6answers
4k views

How do I perform commands in another folder, without repeating the folder path?

Is there a clever way to do copy and move operations or a command to duplicate a file, without having to do a cd, then mv after, at the same folder? For example, I have to run the following: mv ...
64
votes
5answers
25k views

In bash, how do I escape an exclamation mark?

I want to do something like bzr commit -m "It works!". I can sort of escape the exclamation mark by doing bzr commit -m "It works\!". However, then my commit message includes the backslash. How do I ...
62
votes
2answers
58k 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!
61
votes
4answers
17k 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 ...
61
votes
13answers
18k 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 ...
59
votes
4answers
5k views

Why would you `cat /dev/null > /var/log/messages`?

On this bash scripting example page the author presents this script: # Cleanup # Run as root, of course. cd /var/log cat /dev/null > messages cat /dev/null > wtmp echo "Log files cleaned up." ...
57
votes
7answers
59k views

How do I add text to the beginning of a file in Bash?

Hi I want to prepend text to a file. For example I want to add tasks to the beginning of a todo.txt file. I am aware of echo 'task goes here' >> todo.txt but that adds the line to the end of ...
56
votes
6answers
18k 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
56
votes
2answers
2k views

Make bash terminal cursor flash to the beat of Survivor - “eye of the tiger”

I was listening to Survivor - "Eye of the Tiger" and writing some documentation in Vim and noticed that the cursor not flashing to the beat started to annoy me. Can this be fixed? I'm using ...
54
votes
5answers
96k views

Where to find the .bashrc file on Mac OS X Snow Leopard and Lion?

I want to install rvm on my Snow Leopard machine. It says I need to add a line to my .bashrc file (I'm using bash) but where is my .bashrc file?
53
votes
4answers
15k 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 ...
51
votes
7answers
46k 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. ...
51
votes
5answers
2k views

How to “unextract” a zip file?

I extracted a zip file into a non-empty folder. The zip file has lots of files and a deep hierarchy, that merged with the existing tree of the target directory. How can I remove the files and ...
51
votes
2answers
6k views

How can Homebrew print a beer mug in Terminal?

Homebrew has a neat trick of printing out little icons next to its output. Like this: If I copy paste the icon it on its own and hit enter I get the result: -bash: $'?\237\215?': command not found ...
50
votes
4answers
87k views

How to remove a symbolic link to a directory?

I made a symbolic link with the following commmand: ln -s ../test5 I want to remove it now but my rm fails: $ rm -Rf test5/ rm: cannot remove `test5/': Not a directory $ rm test5/ rm: cannot ...
46
votes
4answers
43k views

Bash: Iterating over lines in a variable

How does one properly iterate over lines in bash either in a variable, or from the output of a command? Simply setting the IFS variable to a new line works for the output of a command but not when ...
46
votes
2answers
13k 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.
46
votes
5answers
18k 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.
46
votes
3answers
49k views

How to find the executable files under a certain directory in linux?

How to find the executable files under a certain directory in linux?
45
votes
2answers
7k 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 ...
42
votes
9answers
44k views

Remove a certain line from Bash history file

How can I remove a certain line from history's database?
41
votes
9answers
3k views

Why is Bash everywhere (in most if not all Linux distributions)?

Bash is used by default in every Linux distribution I have tried, over alternatives like Z shell (zsh). Is there a technical or historical reason for this?
41
votes
6answers
41k 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 ...
40
votes
2answers
5k views

what is the difference between “command && command” and “command ; command”

I see these two usage on Ubuntu "command && command" and "command ; command", e.g. apt-get update && apt-get upgrade What would differ if I use apt-get update; apt-get upgrade? I ...
39
votes
4answers
7k views

Does the Shellshock bug affect ZSH?

Does the Shellshock Bash bug affect ZSH? Is upgrading Bash the only solution?
38
votes
10answers
25k views

Unix: ls, how to sort first directories then files etc

I would like to use ls command to first show direcotries and then files. I tried ls -la | sort -k 1 But I got a wrong order.
36
votes
2answers
6k views

how to expand aliases inline in bash?

Is there a way to expand aliases inline in bash? $bash>alias ll='ls -l ' $bash>ll<tab> $bash>ls -l
35
votes
5answers
27k views

Change default text editor for crontab to vim

I'm using ubuntu 9.10 and the default text editor is nano, which i hate. (doesn't everyone?) Normally it's not a problem as i just vi or gedit everything but crontab -e is opening with nano. I ...
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 ...
34
votes
3answers
46k views

How can I change shell in Ubuntu? [duplicate]

I have a Ubuntu Server VPS and I want to use /bin/bash/ as my shell. How can I change my shell? I have root access but I don't work as root. So dash is my default shell now. I have read How do I make ...
34
votes
6answers
41k views

Mac OS X keyboard shortcuts for terminal

After googling for some Mac OS X terminal shortcuts, I wanted to find how can I go back characters on a line on the terminal or words or similar. I found ALT + B but it does not work. Do you know ...
34
votes
3answers
5k 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 ...
33
votes
12answers
3k views

How do I remove a file in Linux whose name looks like it's ONLY a hyphen, as in “-”

I've tried rm -- - rm "-" rm "\-" rm \- Gave Perl a shot ~$ perl -e '$junk = glob("-"); chomp $junk; print "$junk\n"; `rm $junk`;' - rm: cannot remove `-': No such file or directory ...and... ...
33
votes
3answers
6k 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 ...
33
votes
4answers
11k views

Bash: Spaces in alias name

I am trying to create an aliases in bash. What I want to do is map ls -la to ls -la | more In my .bashrc file this is what I attempted: alias 'ls -la'='ls -la | more' However it does not work ...
32
votes
3answers
31k views

What does export do in BASH? [duplicate]

Possible Duplicate: Difference between “a=b” and “export a=b” in bash It is hard to admit, but I have never really understood what exactly export does to an ...
31
votes
5answers
6k views

How can I save the current contents of less to a file?

If I've piped the results of a command to less and then decided that I want to save the contents to a file, is this possible? I've tried setting a mark a at the end of the buffer, and then returning ...
31
votes
2answers
8k views

How do I reload .inputrc?

Background I have heard that the readline module is reading ~/.inputrc and that is how it changes the behaviour of keystrokes under programs such as bash. Question How can I reload this after ...