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

learn more… | top users | synonyms

172
votes
3answers
49k views

Difference between .bashrc and .bash_profile

What's the difference between .bashrc and .bash_profile and which one should I use?
128
votes
9answers
13k 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 ...
105
votes
11answers
80k 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 ...
103
votes
9answers
112k views

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

I type echo $PATH on the command line and get ...
89
votes
4answers
35k 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) ...
85
votes
2answers
59k 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: ...
78
votes
7answers
64k 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 ...
76
votes
14answers
28k 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
5answers
72k 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 ...
66
votes
12answers
40k 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 ...
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 ...
63
votes
5answers
29k views

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

Can I search history in bash and run the result?
56
votes
5answers
20k 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 ...
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 ...
56
votes
10answers
32k 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 ...
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 ...
55
votes
1answer
43k 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!
52
votes
13answers
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 ...
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 ...
48
votes
7answers
46k 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 ...
47
votes
7answers
37k 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. ...
46
votes
5answers
81k 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?
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
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 ...
44
votes
4answers
75k 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 ...
44
votes
2answers
5k 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 ...
42
votes
2answers
10k 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.
39
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?
38
votes
2answers
4k 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 ...
38
votes
5answers
35k 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 ...
38
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 ...
37
votes
5answers
16k 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.
34
votes
4answers
32k 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 ...
34
votes
3answers
41k 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?
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
9answers
21k 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.
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 ...
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 ...
31
votes
5answers
20k 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 ...
31
votes
2answers
5k 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
30
votes
9answers
34k views

Remove a certain line from Bash history file

How can I remove a certain line from history's database?
30
votes
3answers
39k 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 ...
30
votes
4answers
9k 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 ...
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 ...
28
votes
5answers
870 views

Deleting millions of files

I had a dir fill up with millions of gif images. Too many for rm command. I have been trying the find command like this: find . -name "*.gif" -print0 | xargs -0 rm Problem is, it bogs down my ...
28
votes
5answers
37k 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 ...
27
votes
9answers
4k views

Any shortcut for “cd ..”?

Is there any shortcut for cd ..?
27
votes
4answers
15k views

Cygwin fatal error unable to remap.. What does it mean?

0 [main] python 6140 C:\cygwin\bin\python.exe: *** fatal error - unable to remap \\?\C:\cygwin\lib\python2.6\lib-dynload\time.dll to same address as parent: 0x2B0000 != 0x360000 Stack trace: Frame ...
27
votes
5answers
9k views

What is the difference between bash and sh?

I see two types of code being used: #!/usr/bin/sh and: #!/user/bin/bash I searched for this online and opinions vary a lot. The explanations I saw on most websites say that sh is older than ...
26
votes
6answers
19k views

How many cores I am using on a Linux Server?

I am just wondering how I can find out in bash how many CPU cores a user is now using on a Linux Server? I am submitting a fair amount of background jobs to the server, so I'd like to write a bash ...