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

learn more… | top users | synonyms

9
votes
1answer
5k views

Why does my remote process still run after killing an ssh session?

I'm tailing a remote logfile by running this command in a local shell: ssh remotemachine tail -100f /path/to/error_file When I ctrl-c out of this command, it seems that the ctrl-c kills the local ...
9
votes
8answers
544 views

Save me from gibberish terminal

While logged in to a remote ssh session, sometimes I do cat to the wrong file (a binary or a diretory) and the display converts to gibberish. The only way out is to close the terminal and open a new ...
7
votes
2answers
2k views

Smart tab completion (for directories)?

Are there shell versions that have a more intelligent tab completion? I'd like to be able to type cd foo-<TAB> Then it would show me the possible completions along with numbers that I can ...
6
votes
10answers
16k views

Scripting: what is the easiest to extact a value in a tag of a XML file?

I want to read a pom.xml ('Project Object Model' of Maven) and extract the version information. Here is an example: <?xml version="1.0" encoding="UTF-8"?><project ...
5
votes
2answers
2k views

How to persist bash history?

I don't know if this is expected, but my history is not saved across sessions. This is to say, if I close the window, then when I open it again, the history is empty. How can I persist it across ...
5
votes
3answers
1k views

Alert after long running shell script

When I have wait for slow commands (operations on large databases for example), I start doing something else and often don't notice for a long time that it has finished, wasting valuable time. I am ...
5
votes
5answers
3k views

How to read one line from `tail -f` through a pipeline, and then terminate?

I would like to follow changes to a file via tail -f and then print out the first line that matches a grep command before terminating. What's the simplest way to do this? So far I've been ...
5
votes
4answers
3k views

Accessing the output of a Bash pipe with 'read'

I'm trying to pipe some data from a Bash pipe into a Bash variable using the read command, like this: $ echo "Alexander the Grape" | read quot $ echo $quot $ But quot is empty. Some Googling ...
5
votes
5answers
280 views

Linux/Unix in Windows

What would be the best way to get the full-blown Unix/Linux bash inside Windows? I don't mean the Virtual Machine, but rather only the terminal with mounted NTFS drives. This way I could use the ...
4
votes
2answers
150 views

Making custom, single-character directory mappings like ~ > $HOME

We all know that ~ maps to $HOME or /home/user. Is it possible to make other mappings like this on other characters (@,_)? A possible workaround I thought of was to use variables (which require at ...
4
votes
5answers
17k views

How do I run a script in the background and leave it running when I log out? [duplicate]

Possible Duplicate: Leave bash script running on remote terminal while not logged in? I have a bash script that runs Gaussian, a chemical structure calculator, which spends a couple days ...
4
votes
3answers
7k views

Can't edit /etc/profile on my mac

In terminal, I do this: sudo vi /etc/profile But I get a read-only version. I've never not been able to edit anything as a super user- What's going on?
4
votes
2answers
2k views

rsync N newest files in a directory

What would be the easiest way to go about rsyncing the n newest files in a directory to a remote server?
4
votes
4answers
4k views

How do I only display the base dir in my Ubuntu Terminal?

In Ubuntu 10.04 Terminal when I traverse into some long directory structure the entire path gets displayed, this leads to lot of space wastage on my terminal, where the cursor comes way over to the ...
4
votes
1answer
3k views

Equivalent of bash's `source` command in Powershell?

To run a bash script line-by-line (so as to preserve environment variables, for instance), one does the following: $ . myscript.sh Or: $ source myscript.sh I have a PowerShell script that - ...
3
votes
1answer
477 views

Function which overrides bash command

Is it possible to call a bash command which has been overridden with a function? I'd like to make pushd with no arguments alias to pushd . otherwise get normal behaviour. I've tried pushd(){ if [ ...
3
votes
8answers
7k views

How to recursively download an entire web directory?

i have a web directory that has many folders and many sub folders containing files. i need to download everything using wget or bash.
2
votes
4answers
129 views

Manage a few Linux servers at once

I have a small cluster that consists of a few Linux nodes. There's a shared NFS, and I have the same user account with shared SSH keys on all nodes, but other than that each node has it's-own file ...
2
votes
2answers
384 views

Recursively zip files into .cbz-files based on folder in command line

I'm trying to figure out how to write a script to automate creating .cbz files from images in folders on OSX. My directory tree will look like this: /toplevel/ cbz/ comics/ Comic1/ ...
2
votes
2answers
6k views

How list file by range of date?

I would like to list files with 3 days years old. I found this one at stackoverflow: find . -type f -printf "%-.22T+ %M %n %-8u %-8g %8s %Tx %.8TX %p\n" | sort | cut -f 2- -d ' ' | grep 2012 But I ...
2
votes
1answer
751 views

Bash autocomplete paths “through” environmental variables

I used to be able to type cd $home/p hit the tab key and the command would change to cd /home/phill Now it doesn't. When cd'ing to a directory based on an environmental variable, I'm "flying ...
2
votes
3answers
706 views

What escape code do I need in PS* to make sure terminal is back in normal settings on shell prompt?

Sometimes I accidentally cat some binary data; sometimes some ncurses program crash - for plenty of reasons terminal can end up in bad state, requiring manual reset. This is happening too often. Such ...
0
votes
2answers
595 views

What is the difference in various commands for compressing files in linux?

What are the commands for compressing files in linux and what are the difference between them? (for example: tar, gzip, rar). I'm working on Linux Mint 11 and doing a script for compressing files. I ...
27
votes
5answers
12k 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 ...
13
votes
1answer
2k views

How to prevent clearing of terminal output when I “exit” an SSH session?

This is the situation: I open a terminal in Ubuntu, and do ssh host-1, which works as expected. From host-1, I do ssh host-2, which again works fine and connects me to host-2. From host-2 I do, for ...
11
votes
1answer
25k views

How to permanently add current directory to PATH in Linux? [duplicate]

Possible Duplicate: Add folder to PATH I want to a add a directory to my bash to search in, and I am using the $PATH=.... it works however when I open a new command window it is not there. ...
9
votes
6answers
9k views

Copy files in Linux, avoid the copy if files do exist in destination

I need to copy a /home/user folder from one hard disk to another one. It has 100,000 files and around 10G size. I use cp -r /origin /destination sometimes I get some errors due to broken ...
8
votes
4answers
2k views

BASH history truncated to 500 lines on each login

For some reason, I cannot get my system to keep my BASH history after a reboot. Here are the relevant sections of my ~/.bashrc: shopt -s histappend PROMPT_COMMAND='history -a; updateWindowTitle' ...
8
votes
6answers
5k views

Clear stdin before reading

I have the following bash script: # do some time consuming task here read -p "Give me some input: " input Now as you might have guessed, if a user presses some random keys during the "time ...
8
votes
5answers
2k views

bashrc: how to know X window is available or not?

There is a part in my ~/.bashrc, which sets $EDITOR to be gvim. It works fine when I am in X window. However, if I ssh to my workstation (from another workstation) gvim starts to complain "cannot open ...
7
votes
4answers
335 views

Running `exec` with a Bash built-in

I defined a shell function (let's call it clock), which I want to use as a wrapper to another command, similar to the time function, e.g. clock ls -R. My shell function performs some tasks and then ...
7
votes
3answers
6k views

Gnome: Change title of current terminal from bash command line

I know there are options to start a new terminal with a specified title, and that is is possible to change the title from a terminal using the menu: 'Terminal' -> Set Title. However, I want to change ...
7
votes
3answers
7k views

Use OpenOffice from command line to convert HTML to RTF

I'm trying to build a bash script in Cygwin that will convert HTML files to RTF. In OS X this is trivial with textutils, but that doesn't exist for regular Linux or Cygwin. Instead I'm trying to use ...
6
votes
2answers
5k views

Monitor a Folder OSX for file changes then run a bash script [duplicate]

Possible Duplicate: Watch Filesystem in Real Time on OS X and Ubuntu I'm looking for a efficient method to monitor a local directory in OSX and if any files have been changed in that ...
5
votes
3answers
4k views

Can I use pipe output as a shell script argument?

Suppose I have a bash shell script called Myscript.sh that need on argument as input. But I want the content of the text file called text.txt to be that argument. I have tried this but it does not ...
5
votes
5answers
2k views

Why does wget'ing an image give me a file, not an image?

I do wget http://services.runescape.com/m=itemdb_rs/3809_obj_sprite.gif?id=2 and it downloads the following file: 3809_obj_sprite.gif?id=2 How can I make it save as the following? 2.png
5
votes
5answers
3k views

How to color grep output

When I type memcached -vv 2>&1 | grep --color=always "SET\|GET" I get nice memcached stats GET AR-City-1 GET rest-part-241 SET rest-part-241 Value len is 685 GET ...
5
votes
3answers
749 views

Is it wasteful to call cat?

I’m sorry if this question is really stupid, but this is basically what I have been thinking about constantly. Suppose I run: : cat ./somefile.txt A few hundred times a second. How much faster is ...
5
votes
1answer
596 views

Is there a way to preprocess input to bash?

I would like to be able to define arbitrary modifications to command lines that happen before bash sees them at all, ie, before expansion of any kind. Is this possible? I'm not trying to solve one ...
4
votes
1answer
388 views

Vim process stops after executing an external command

I've been using vim recently to program in C. I have created shortcuts for compiling and running the programs from within vim itself, but recently vim's process has been stopping after executing the ...
4
votes
3answers
210 views

Determine whether a bash script was launched by icon click or from terminal

I have a script that I want to have a different behaviour depending on whether it was launched from the terminal or by (double) clicking the icon in the file manager. Can I do this?
4
votes
3answers
19k views

Connect to WiFi network using Mac Terminal

Every time I try to find out how to do this, I find out how to do it on a linux, and it doesn't transfer. How do I connect to a WiFi network using Mac Terminal Bash?
4
votes
4answers
5k views

Using SQLite3 with Cygwin

I'm trying to use sqlite3.exe command shell with a mintty terminal in cygwin. I tried the program from a windows command prompt and it works. When I try to use it from the cygwin mintty terminal it ...
3
votes
3answers
225 views

Which files are run when I log into or reboot my machine?

I'm trying to figure out which "script" (really it's probably an "*rc" file) is running a particular command when I reboot my ubuntu machine. I've tried grepping for what is being displayed when I log ...
3
votes
1answer
1k views

Ping server/domain and capture its IP on Linux

With Windows, you could ping a given domain name and capture the IP as a variable, even if no reply was received. I believe the command looked something like this: ping domain.com for /f "tokens=1,2 ...
3
votes
1answer
1k views

Open Sublime Text 2 with new tab instead of new window

I've got an alias to open files in Sublime Text 2: alias sub='/Applications/Sublime\ Text\ 2.app/Contents/MacOS/Sublime\ Text\ 2' But this spins up another instance of Sublime Text 2 (complete with ...
3
votes
2answers
1k views

How to delete readonly variable in bash?

$ mySite="superuser" $ readonly mySite $ unset mySite bash: unset: mySite: cannot unset: readonly variable How can we delete mySite, as it is a readonly variable?
3
votes
2answers
3k views

Redirect stdout to a file when process is run in background

How can I redirect the stdout of a program to a file when it's run in the background? I have a program that generates output every second. When I run it normally and redirect to a file, the output ...
3
votes
2answers
2k views

Is there a face recognition command line tool?

I've download a lot of images in one directory including People and Landscape. I want to split the directory into two. I'm looking for a Linux command line tool to filter by face.
3
votes
1answer
935 views

~/.bashrc not sourced in a new lxterminal window

I added some lines to my ~/.bashrc like export JAVA_HOME=/opt/jdk1.6.0_22 I sourced it: $ source ~/.bashrc $ env | grep 'JAVA' JAVA_HOME=/opt/jdk1.6.0_22 Then I created a basic bash script under ...