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

learn more… | top users | synonyms

17
votes
2answers
3k 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 ...
17
votes
4answers
6k 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.
17
votes
1answer
5k 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 ...
16
votes
4answers
2k 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 ...
15
votes
3answers
4k 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 ...
15
votes
4answers
8k 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.
15
votes
4answers
41k 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 ...
15
votes
1answer
3k 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.
15
votes
1answer
542 views

How do I reduce a PDF's size and preserve the bookmarks?

I have a ~259 MB PDF. I did pdf2ps and ps2pdf. The final size was 45 MB. I don't see any visible difference in quality in any reader. Although, the bookmarks were lost. I tried using pdftk, but it ...
15
votes
2answers
4k views

What happens to running processes when I lose a remote connection to a *nix box?

I occasionally lose my remote SSH connection to my VPS. I use screen for long-running processes, but am wondering what happens to the processes I had running aside from those run within a screen ...
14
votes
5answers
14k 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 ...
14
votes
8answers
11k 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?
14
votes
6answers
4k views

Is there a Windows command line with smart bash-like autocompletions / command history?

I recently started using bash, and discovered some really wonderful features (not necessarily come out of the box, but can be configured): Up/down arrows support partial completion: Type "git ", ...
14
votes
9answers
20k views

Copy all files and folders excluding subversion files and folders on OS X

I'm trying to copy all files and folders from one directory to another, but exclude certain files. Specifically, I want to exclude subversion files and folders. However, I'd like a general yet ...
14
votes
3answers
10k 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'?
14
votes
2answers
29k views

How to execute a bash script?

So I've written my first bash script: #!/bin/bash echo 'hello world!' exit I know it has the right location to bash and is executable: $ which bash /bin/bash $ chmod +x myscript.sh Now I want to ...
14
votes
6answers
16k 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
14
votes
2answers
47k views

.profile in Mac OS X?

I have set my terminal preferences to execute: set -o vi at startup. The problem is I don't get that command executed when open a new terminal tab. Is there something like .profile in OS X where ...
14
votes
2answers
7k 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 ...
14
votes
4answers
12k 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 ...
14
votes
4answers
2k views

Double root folder vs single root folder

On my Linux box, in bash, I have access to a "double root" folder denoted by two forward slashes: tomas:~ $ cd / tomas:/ $ ls bin/ cdrom@ ... tomas:/ $ cd // tomas:// $ ls bin/ cdrom@ ... The ...
14
votes
1answer
3k views

How can I get bash to perform tab-completion for my aliases?

I have a bunch of bash completion scripts set up (mostly using bash-it and some manually setup). I also have a bunch of aliases setup for common tasks like gco for git checkout. Right now I can ...
13
votes
7answers
8k 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 ...
13
votes
6answers
11k views

How does Mac's command line compare to Linux?

I love Ubuntu Linux - especially the commmand line. But I have to admit that, at least for now, Windows is more user-friendly - there's more software for it, more drivers, and more stuff just works. ...
13
votes
4answers
2k views

A command before every bash command

Does anyone know a mean of putting a 'time' command before every command in a bash session?
13
votes
5answers
5k 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 ...
13
votes
3answers
580 views

How to insert the date into vim

In vim you can execute comands with "!". You can combine that with "r" to insert the output into your current buffer. :r!date Fri Jul 20 09:39:26 SAST 2012 will insert the date into a file. ...
13
votes
2answers
57k views

How do I concatenate strings in a bash script?

How can I concatenate strings and variables in a shell script? stringOne = "foo" stringTwo = "anythingButBar" stringThree = "? and ?" I want to output "foo and anythingButBar"
13
votes
1answer
1k views

What's an elegant way to copy the creation and modification dates of a file to another file?

How can I set the time information of a file to be the same as of another file on OSX / Linux?
13
votes
5answers
54k 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 ...
13
votes
2answers
21k views

bash: ulimit: core file size: cannot modify limit: Operation not permitted

Fedora 12 gcc 4.4.1 I am doing some programming, and my program gave me a stack dump. However, there is no core file for me to examine. So I did: ulimit -c unlimited and got this error message: ...
13
votes
5answers
15k views

How can I do a recursive find and replace from the command line?

Using a shell like bash or zshell, how can I do a recursive 'find and replace'? In other words, I want to replace every occurrence of 'foo' with 'bar' in all files in this directory and its ...
13
votes
3answers
4k views

Escaping apostrophe in single quotes string in bash

I don't understand how Bash evaluates escaping of apostrophe characters in single quoted strings. $ echo ''\''Hello World'\''' 'Hello World' #works $ echo '\'Hello World\'' > # expects you to ...
13
votes
2answers
6k views

Check number of pending security updates in Ubuntu

Let me start by saying I have been forbidden to enable automatic updates on our Ubuntu servers, for both security and regular packages. When I log into any of my four Ubuntu servers, the welcome ...
13
votes
4answers
9k 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 ...
13
votes
3answers
16k views

how to add a day to date in bash?

For example, I have date: 4 August 1993 and I want to add 348 days to it, how can I do it in bash?
13
votes
2answers
4k 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 ...
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?
13
votes
4answers
4k views

Cygwin bash prompt is wrapping lines on the same line

I'm using Cygwin bash prompt, and for long commands the text will wrap around on the same line as opposed to going to the next line despite setting my PS1 to simply ' $'. Here's a screenshot,
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 ...
13
votes
2answers
15k views

Environment variables in bash_profile or bashrc?

I have found this question [blog]: Difference between .bashrc and .bash_profile very useful but after seeing the most voted answer (very good by the way) I have further questions. Towards the end of ...
12
votes
8answers
996 views

Bash Script to repeat every word in a line?

I have a string like: dog cat bird whale And I want to get dog dog cat cat bird bird whale whale All the words are in the same line. Any idea?
12
votes
8answers
563 views

Is there a command for going back a number of steps in a directory, without using cd?

I'm constantly going 'cd ../../../../'. Is there a command/alias that could let me go 'cmd 4' and I'd be taken back 4 directories?
12
votes
5answers
2k views

Which directory does path `//` represent in Linux?

When I want to go back to upper level directory in Linux by typing cd .., I typo-ed cd //. To my great surprise, no errors are reported. What's more the prompt becomes username@hostname://$. ls ...
12
votes
8answers
8k views

Show only odd lines with cat

HI, probably is this something very easy, but I do not get the point now. In Linux, shell, given a text file, how can I do something like, cat filename so I only see the first line, the third line, ...
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 ...
12
votes
5answers
1k views

How do I tell mkdir to try creating dir1, and if it already exists create dir2, etc, until it hits a name that doesn't exist?

I want to create a directory with a number at the end, e.x. "dir1", and increment that number if the directory already exists until it hits a directory name that doesn't exist, and I need to do this ...
12
votes
4answers
2k 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 ...
12
votes
5answers
9k views

Writing “tail -f” output to another file

As a continuation from my last post where I have used grep & tail -f to find occurences of "rare" events. I would like to record this in another file. I've tried turning tail -f log.txt | ...
12
votes
3answers
11k views

How to cd to a directory that contains a space in its name?

I have a directory called "Reader 0.5" in my Desktop on Mac Os X. When to access the directory in terminal, I am using below code: cd /Users/niho/Desktop/Reader 0.5 but it throws: No such file or ...