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

learn more… | top users | synonyms

4
votes
4answers
3k 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
2k 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
2answers
4k views

How can I start multiple screen sessions automatically?

I'm trying to build a command that launches screen, creates four sessions with different names, and run four different commands. I know how to do this manually: 1. screen 2. ./command1 args 3. ...
3
votes
1answer
418 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 [ ...
2
votes
5answers
10k 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 ...
2
votes
3answers
661 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 ...
25
votes
5answers
8k 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 ...
12
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 ...
10
votes
3answers
8k 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 ...
9
votes
4answers
3k views

`alias rm=“rm -i”` considered harmful?

I have read some time ago (can't find the reference) that using such an alias as alias rm="rm -i" was very bad. Is there historical evidence or common sense explanation for that fact? I would ...
9
votes
6answers
5k 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
1answer
17k 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. ...
7
votes
3answers
6k 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
10answers
8k 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
3answers
3k 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 ...
5
votes
3answers
692 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 my ...
5
votes
5answers
2k 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
5answers
1k views

What is the difference between “Shell” and “Terminal”?

I am fairly new to Ubuntu and I am loving it! But I don't quite understand the difference between the shell and the terminal. Can any one explain? Someone told me that a terminal is just a "tool" to ...
5
votes
5answers
222 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
1answer
133 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
2answers
999 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 ...
4
votes
2answers
3k 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 ...
4
votes
1answer
476 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 ...
3
votes
3answers
713 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 ...
3
votes
1answer
704 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 ...
3
votes
1answer
126 views

Attach command to execute when long-running thread returns

Let's say I've just started a command that will take a long time to execute, like hg clone the entire Pypy development set. Halfway through, I decide I'd like to run another process, like hg up, once ...
3
votes
3answers
12k 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?
3
votes
4answers
4k 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
1answer
726 views

How to write a script to sudo the last command

Usually, for some commands such as apt-get install xxx, I forget to add sudo first, then I need to retype it. What I want is in such cases, I just type a simple command, for example resudo. It will ...
3
votes
1answer
566 views

Can I make ssh-agent wait until I use ssh to prompt for a password?

I have ssh-agent set up to automatically start and prompt when I open a terminal window, as is explained here. It gets somewhat annoying though since many times when I open a shell I don't plan on ...
3
votes
4answers
278 views

Change directory upwards to specified goal

I'm often deep inside a directory tree, moving upwards and downwards to perform various tasks. Is there anything more efficient than going 'cd ../../../..'? I was thinking something along the lines ...
2
votes
2answers
122 views

Unable to get profile variable using ssh

Unable to retrieve the profile variable using ssh. server2 ==> user apptst ==> bash profile has $APPHOME variable. Was trying to retrieve the value from server1 using ssh but failed. Used options ...
2
votes
2answers
832 views

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ [3~

bash home/end/delete key inserting tilde, or if preceded by escape key, [1~ say I type echo hellp, move cursor to hel|lp and type delete, and bam, i got ~tilde say I type echo hellp, move cursor to ...
2
votes
2answers
561 views

Find difference with mtime - and +

Can someone explain the difference with mtime - and + switch as both are not bringing back the results I need. I'm looking to delete all files older then 5 days find /mnt/sdb1/tmp/ -type f -mtime +5 ...
2
votes
3answers
3k views

How to replace part of a text file between markers with another text file?

Say I have a text file like this: # custom content section a b ### BEGIN GENERATED CONTENT c d ### END GENERATED CONTENT I'd like to replace the portion between the GENERATED CONTENT tags with the ...
2
votes
5answers
2k views

Move all files in sub-directories to current directory?

I've got files in a bunch of subdirectories, and I'd like to flatten them out and move them all to the current directory. I found this question, but adapting the answer to: mv * . didn't work. I ...
2
votes
1answer
450 views

How can I remap Ctrl+C to send an interrupt signal with another key?

I've got a process in bash that I can call to stop using Ctrl+C. As far as I can see, this equals to sending an exit(1) signal. I would like to loop through these processes for a list of different ...
2
votes
2answers
725 views

curl not uploading file to ftp

I am using curl to upload a file to ftp server. The same script is working on another system, but on this one after connecting to ftp it is not doing anything and connection times out. The detailed ...
2
votes
1answer
679 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
2answers
654 views

Remove bash startup behaviour (mac user)

When I start the terminal (which uses bash) a echoed message appears several times right before the message "You have mail." and it is added by someone that has used my computer. It also happens when ...
2
votes
1answer
296 views

Force a bash script to run to completion where some items may stick

I've a Uni assignment I'm building that I need to run multiple times with multiple different parameters to check run times. At the moment I've a simple bash script that looks a little like the below - ...
2
votes
8answers
5k 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.
1
vote
2answers
2k 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 ...
1
vote
1answer
1k views

Pass arguments to osascript via shell function in OS X Mountain Lion

The answer in How to open a new Firefox window with URL argument is broken in Mac OSX Mountain Lion (10.8.2). I can't comment on that answer or question, so I had to create a new question. It fails ...
1
vote
2answers
903 views

Diff and ignore lines missing in one file

I want to diff two files and ignore lines that are present in one file but missing in the other. For example File1: foo bar baz bat File2: foo ball bat I'm currently running the following diff ...
1
vote
3answers
470 views

Background job in bash is shutting down when the firing window is closed: how to avoid this?

You can go quickly to the question starting reading from 'Having said that' The following are details on my specific needs I'm on lubuntu oneiric and trying to create a desktop launcher to start / ...
1
vote
4answers
1k views

less emulate a TTY to preserve piped color output

When you pipe something through less, the program usually discards color codes because it's not outputting to a TTY. So you have to add --color=always to the options for it to work. ls -l ...
1
vote
0answers
62 views

select files from a set [closed]

I need the Bash code for select file in a set of files. I use something like this find . -type f -name \*.txt to locate the set of files I want to work with. After that I would want select only the ...
1
vote
1answer
10k views

-bash: ls: command not found at Terminal on Mac OS X

I need to start using GIT for my projects from now on and I need to use some UNIX commands. but no matter what I do, I always receive "command not found" error. I installed MacPorts, but still cant ...
0
votes
2answers
60 views

sum numbers in different lines in shell

i have 8000 lines similar to this <Flow flowId="1" timeFirstTxPacket="+0.0ns" timeFirstRxPacket="+924100.0ns" timeLastTxPacket="+199984927558.0ns" timeLastRxPacket="+199675473275.0ns" ...