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

learn more… | top users | synonyms

23
votes
3answers
23k views

How to join/merge many mp3 files?

Searching Google on how to join/merge many mp3 files, it suggests that I should just cat them together. That might "work", but clearly it is not the correct way to do it, as each header and set of ...
23
votes
1answer
5k views

How to get infinite command history in bash?

I set export HISTSIZE=99999999999999 but is that the best way? I don't know if an overflow might occur. I'm looking for a tested, reliable way to remove command history limits.
22
votes
7answers
3k views

Is there a standard unix program that returns a range of numbers

Im learning shell scripting from an outdated textbook, and it seems to me like it'd be really usefull to have a program that just returns a string of numbers delimited by spaces something like $ ...
22
votes
5answers
7k views

.profile and .bashrc doesn`t work on my Mac

This problem I have for a long time. After running terminal .profile, and .bashrc file doesn`t work (are not executed). Could you indicate where should I looking form a source of problem?
22
votes
3answers
28k views

unix copy a directory

How can I copy a directory structure dir1 to dir2 ? (with all the subdirectories) in unix using the terminal window
22
votes
3answers
6k views

How can I make the bash backtick operator keep newlines in output?

Is there a way to make bash not eat newlines in the backtick substitution? For example: var=`echo line one && echo line two` echo $var line one line two What I want is var=`echo line one ...
21
votes
2answers
903 views

How to create a directory named '-p' under Linux with Bash? [duplicate]

In Bash, how could I create a directory named -p? mkdir -p failed. mkdir "-p" failed. mkdir "\-p" failed. mkdir \-p failed.
21
votes
3answers
686 views

How to prevent a password or other sensitive information from being stored in the bash history when using grep?

I had to grep recently for a password that may have been saved in a file. I did not want that line to show up in the bash history. How can I prevent a password or other sensitive information from ...
21
votes
2answers
2k views

What is /usr/bin/[ and how do I use it?

I was looking at coreutils and found this as one of the files included as part of coreutils: /usr/bin/[. What is [ and what does it do? It is an executable. I just don't know what it does or how to ...
21
votes
2answers
15k views

Measure script execution time

In bash shell, is there a simple way for me to monitor the time taken to run a script and output the time taken?
21
votes
3answers
22k views

How to ignore certain filenames using “find”?

One of my favorite BASH commands is: find . -name '*.*' -exec grep 'SearchString' {} /dev/null \; which searches the contents of all of the files at and below the current directory for the ...
21
votes
2answers
7k views

Bash command to focus a specific window

Is there a way, in bash command line, to give focus to a specific window of a running process. Assume I know the process' name, number, and anything else I need. For instance, if I have a single ...
21
votes
1answer
2k views

How do I reload .inputrc using a bash script?

This question explains how to reload .inputrc using C-x C-r. But how would one reload it using commands in a bash script?
20
votes
2answers
8k views

Can the output of one command be piped to two other commands?

How can I pipe the output of one command to the input of two other commands simultaneously?
20
votes
4answers
12k views

Change Terminal Title in Mac OS X

How can I arbitrarily change the title of a Terminal window in Mac OS X? I have seen this question and this magicwrap thing, but think it's just a simple Mac OS X command.
20
votes
5answers
75k views

How to upload a file from the command line with FTP or SSH?

I have never done this before and I am creating a bash shell script to do this for me. I will also be connecting via ssh to do some things (which I already know how to do). So maybe there is a way to ...
20
votes
5answers
67k views

How can I get the mount path of a USB device on OSX?

I have a backup script that backs up some data to a USB device. The problem I have is that OSX sometimes changes the expected mount path. For example if some file is locked under the expected mount ...
20
votes
4answers
5k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
20
votes
2answers
7k views

Is there any way to get bash to have syntax highlighting like fish?

In the fish shell, the actual command line is syntax highlighted: Is there any way to get this same behavior in bash? There is something just like this but for zsh, not bash. Is it possible that ...
19
votes
4answers
3k views

Undo tar file extraction mess

I just untar'd an archive that produced a mess of files into my tidy directory. For example: user@comp:~/tidy$ tar xvf myarchive.tar file1 file2 dir1/ dir1/file1 dir1/subdir1/ dir1/subdir1/file1 ...
19
votes
2answers
552 views

Accidentally sourced .bash_history

In a moment of brilliance, I executed the command source ~/.bash_history. Fortunately, most of the commands are using vim to edit some file, but there are some scary commands in my history - moving ...
19
votes
2answers
17k views

Rename user's group name

I just did usermod -l login-name old-name to change the username, but the group name is still the old one. Any way of renaming the group name? I can't find any info to do so.
18
votes
7answers
12k views

Why doesn't echo support “\e” (escape) when using the -e argument in MacOSX

When I try to print out some colored text using ANSI escape sequences via the built-in echo command, it seems that the \e escape sequence in the string I provide is interpreted literally instead of as ...
18
votes
6answers
19k views

In bash, how to sort strings with numbers in them?

If I have these files in a directory cwcch10.pdf cwcch11.pdf cwcch12.pdf cwcch13.pdf cwcch14.pdf cwcch15.pdf cwcch16.pdf cwcch17.pdf cwcch18.pdf cwcch1.pdf cwcch2.pdf cwcch3.pdf cwcch4.pdf cwcch5.pdf ...
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 ...
18
votes
3answers
5k views

How do I chain commands on the console?

In bash, I sometimes want to run several commands in serial and don't want to wait for them to finish before I type the new ones. So I do something like this: cmd1; cmd2; cmd3 Unfortunately, one of ...
18
votes
3answers
2k views

Why does the output of some Linux programs go to neither STDOUT nor STDERR?

Why does the output of some Linux programs go to neither STDOUT nor STDERR? Actually, I want to know how to reliably capture all program output, no matter what 'stream' it uses. The problem I have is ...
18
votes
4answers
11k views

push/pop current directory?

With bash is there a way to push and pop the current working directory? I tried writing bash;cd dir; ./dostuff;exit; but the current directory is now dir.
18
votes
2answers
12k views

create mysql database with one line in bash

Is it possible to create an empty database with one line of command in bash? My newbie attempts have failed: mysql -uroot $(create database mydatabase;) I end up having to mysql -uroot create ...
18
votes
1answer
12k views

Remove single file from zip archive on Linux

I have a zip archive (created automatically in a script with -j -r flags) and I would like to remove a single file from it. I tried as documented. zip -d "picture_43_9.jpg" gallery.zip but I get ...
18
votes
1answer
5k views

How to rehash executables in $PATH with bash

The subject says it all, how to rehash the available executables available within one of the $PATHs after having changed things: e.g. removed a binary from one $PATH which is available in another ...
18
votes
4answers
19k views

cURL: how to suppress strange output when redirecting?

I'm trying to print just the verbose sections of a cURL request (which are sent to stderr) from the bash shell. But when I redirect stdout like this: curl -v http://somehost/somepage > /dev/null ...
17
votes
4answers
20k views

I want to change DPI with Imagemagick without changing the actual byte-size of the image data

I feel so horribly sorry that I have to ask this question here, but after hours of researching how to do an actually very simple task I'm still failing... In Gimp there is a very simple way to do ...
17
votes
4answers
8k views

Bash/ZSH: Undoing 'disown'

Is there a way to 'reattach' a process to the shells job table after it it has been 'disowned'? Edit: $SEARCHENGINE totally fails me. Doesn't look too good.
16
votes
8answers
16k views

How can I prepend a line number and tab to each line of a text file?

How can I append a line number and tab to the beginning of each line of a text file?
16
votes
5answers
19k views

How do I convert a bash array variable to a string delimited with newlines?

I want to write out a bash array variable to a file, with each element on a new line. I could do this with a for loop, but is there another (cleaner) way to join the elements with \n?
16
votes
3answers
7k views

What is the difference between &> and >& in bash?

What is the difference between &> and >& in bash? tldp did not mention the latter one. Is it really a redirection operator? Or does someone know a more complete tutorial?
16
votes
2answers
2k views

Bash autocomplete on symlink to directory complete to whole directory, including slash [duplicate]

Possible Duplicate: Tab-completion with directories/links when I've a symlink foo linking to a directory bar/ and I start typing f and hit tab, it completes to foo but I'd like to complete ...
16
votes
6answers
26k views

Run part of a bash script as a different user

Is there a way to make part of a script run as a different (non-root) user? If it helps , the part to be run as a different user occurs at the end of the script Edit : OS -> Ubuntu 9.04
16
votes
2answers
6k views

Putty SSH: CTRL+Cursor keys don't work skip to previous/next word

When I am connected to my local Ubuntu dev server with putty (from my Windows 7 box) via SSH, the following key combinations don't work to move the cursor forward and backward on word boundaries: ...
16
votes
4answers
12k views

Should I put *.sh and *.rb file extensions on all my scripts?

I have a bunch of hand-rolled executable scripts in my $HOME/bin directory. Some are written in bash, some in Ruby. All of them have the shebang line at the top telling the shell what interpreter to ...
15
votes
4answers
3k views

A command before every bash command

Does anyone know a mean of putting a 'time' command before every command in a bash session?
15
votes
7answers
7k views

How to retrieve the absolute path of an arbitrary file from the OS X

I'm looking for a simple command that can be used within Bash to find the absolute and canonicalized path to a file on an OS X (similar to `readlink -f' under Linux). The following sample bash ...
15
votes
4answers
4k views

Equivalent/Alternatives for Alt+Dot in Mac

One thing i miss from the Linux shell is the Alt+Dot shortcut. What it does is insert the last argument of the previous command. It appears to be a trivial technique, but it's really useful. i.e. if ...
15
votes
10answers
30k views

Filesystem full: how to find the biggest directories or biggest file? [duplicate]

Under Linux, I'm looking for a command to list the biggest file and/or the biggest directories under a directory.
15
votes
3answers
2k views

Command vs program?

I was looking up the difference between adduser and useradd, and an explanation is that useradd is a command while adduser is a perl script. I understand what a perl script is, but what I do not ...
15
votes
3answers
17k views

Get home directory by username

I want to obtain home dir of any user with echo echo ~puchuu >> /home/puchuu But I cant use variable echo ~$USER >> ~puchuu echo `echo ~$USER` >> ~puchuu
15
votes
4answers
134k views

How can I resolve the error “cannot execute binary file”?

When I login using SSH, all I can see is this... -bash: /usr/bin/id: cannot execute binary file -bash: [: : integer expression expected I couldn't do anything in here. Commands such as halt, ...
15
votes
2answers
12k views

Avoid unwanted path in Zip file

I'm making a shell script to package some files. I'm zipping a directory like this: zip -r /Users/me/development/something/out.zip /Users/me/development/something/folder/ The problem is that the ...
15
votes
5answers
24k views

When to use Bash and when to use Perl/Python/Ruby?

We are doing all our scripting with Bash so far, but I'm starting to feel a bit silly about it. While we can of course do everything we want with Bash (it's quite powerful), I'm starting to wonder if ...