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

learn more… | top users | synonyms

0
votes
2answers
4k views

Bash processes - reattach process started in background

Is there a way to reattach to a specific terminal a process that was started from terminal with &? For instance, I started Kate by: kate & and now I want to reattach the process to a given ...
15
votes
2answers
5k 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
4answers
9k views

How do you escape apostrophe in single quoted string in bash?

I don't understand how bash evaluates escaping of apostrophe characters in single quoted strings. Here is an example: $ echo ''\''Hello World'\''' 'Hello World' # works $ echo '\'Hello World\'' ...
10
votes
8answers
25k views

Bash: is there a way to search for a particular string in a directory of files? [duplicate]

Possible Duplicate: Search for a text pattern in linux In bash, I was wondering if there were any commands that would let you know if a particular string you are looking for exists within ...
10
votes
5answers
2k views

How can I still see the 'man' text after I quit man?

I typically use tcsh or bash and often want to use 'man' to review a command's options. Currently when I quit man or ctrl-C, the man text disappears and I see the scrollback buffer that was there ...
8
votes
2answers
831 views

How do I delete a file named “-p” from bash?

How do I delete a file named -p in bash? Trying rm "-p" complains that -p is not a valid argument.
7
votes
2answers
3k views

Will a job put in background continue running after an SSH session is closed?

I have an AWS instance, and there I some tasks that I need to complete that will take some time. If I run these before commuting to/from work (e.g. wget <someStuff>), then commit it to ...
6
votes
5answers
4k views

Must I sftp to an intermediate server?

I can't sftp directly into a particular host. To move a file from my home machine to the host, I must sftp a file to an intermediate host; ssh into the intermediate host; and sftp the file to the ...
4
votes
2answers
1k views

Practical (closer to the classical Linux one) way to use (automate) SUDO for CygWin

Being able to use sudo commands in CygWin is useful, and faster than opening an elevated shell: Luis@Kenobi /cygdrive/c/Users/Luis $ net user /add TestUser System error 5. Access denied. Luis@Kenobi ...
4
votes
2answers
956 views

How can I create keyboard shortcuts to run commands in a terminal?

I was wondering is it possible to bind say F5 to output sudo apt-get update so I can press one key to write this into the terminal?
1
vote
1answer
38 views

Incorrect output of history command of ssh. How to read the timestamp info correctly

I set the HISTTIMEFORMAT variable to store the timestamp info .bash_history file. I am able to display the history properly if I use interactive shell. But, when I run history command to display ...
1
vote
2answers
5k views

Finding and removing duplicate files in osx with a script

From: http://www.chriswrites.com/2012/02/how-to-find-and-delete-duplicate-files-in-mac-os-x/ How do I modify this to only delete the first version of the file it sees. Open Terminal from Spotlight or ...
0
votes
2answers
178 views

How to replace a command with the result of another in linux?

I want to create a command which uses the result of another like this: JNLP_FILE='find . -name viewerApplet.jnlp' cp ${JAR_FILE} ../../sign-jar/$PROFILE/ But I don't know how to execute the find ...
22
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 ...
9
votes
4answers
913 views

Unix tools: what if a file is named minus something?

I'm always wondering: most GNU/Unix tools take options in the form "minus something", sometimes followed by an argument. What if you got a file named minus something? $ ls -f $ rm -f $ ls -f $ mv -f ...
7
votes
4answers
590 views

Terminal: prefix previous command?

Frequently in Terminal (though I fully expect any answer will work in bash and most others), I type some command, and then get some sort of permission error due to missing sudo. Okay, so press 'up', ...
6
votes
2answers
18k views

How to solve: -bash: : cannot execute binary file

I have a file named b1 that contains assembly language. I am trying to execute the file on OSX using $ ./b1 I get the following error: -bash: ./b1: cannot execute binary file I've looked at ...
6
votes
1answer
6k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
6
votes
3answers
6k views

Cygwin .bashrc not being source because cygwin starting in Windows home

NOTE: Please see my second edit below for an update on the problem. Cygwin was working fine for me until last week. Now .bashrc isn't getting sourced. I must have installed something or changed ...
6
votes
4answers
7k views

Unix command to list all directories larger than 10mb

Is this possible, and what would the command be?
5
votes
1answer
3k views

Bash Find Files with zero size and delete files with different extensions

This command will find files of zero size: find . -size 0 A filename returned might be filename.001 I am looking for a one liner that will delete files found with this, plus any that have the ...
5
votes
2answers
10k views

Write a PID file manually from Bash script

How could I write a Bash-script that runs a long running program and stores the programs process id in a separate file? I want something like #!/bin/bash exec long_running_tool echo `ps af |grep ...
3
votes
2answers
931 views

How to invoke Windows' gvim in a Windows environment from within Cygwin?

When I give a gvim command in Cygwin, I want it to invoke the gvim I've installed in my Windows. I tried writing a function in my .bashrc called gvim that invokes the gvim.exe in my Program Files ...
3
votes
1answer
3k views

How can I execute a script each time I log in and out from OS X?

What I want is to send a URL with variables to a server which will track when someone is present based on when they login and logout of their workstation. I've tried setting the LoginHook in ...
3
votes
3answers
3k views

How can I grep in source files for some text?

At the moment I'm using two commands, I'm sure there must be a better way... wim@wim-acer:~/ffmpeg$ find . -name "*.h" -print0 | xargs -0 grep -i invalid\ preset wim@wim-acer:~/ffmpeg$ find . -name ...
3
votes
3answers
7k views

When running `rm -rf`, is it possible to exclude certain subdirectories?

I routinely use bind mounts to aid in making space available in multiple locations without having to have multiple logical volumes / physical partitions / LUNs, etc. For example, I may have a 200G LV ...
2
votes
1answer
3k views

Messed up $PATH variable in Mac OS X

I did something to my PATH. I was trying to add some new path and now none of the command like open ~/.bash_profile work, and echo $PATH only shows one path which is /Application/Filename. Is ...
2
votes
4answers
1k views

Keyboard shortcuts in Bash shell [closed]

I know some useful Bash shell shortcuts, and I am wondering if there are others. The ones I know: CTRL + W: delete until beginning of word CTRL + U: delete until beginning of line Up / Down: ...
1
vote
1answer
103 views

Bash - how do you make it so that the result of a command gets placed into a variable?

For instance, let's say I wish to type the command pwd. It gives me a really long path to the current directory I am in. What I would really like to do is make it so that I can go into a completely ...
11
votes
4answers
7k views

Going to directory using bash variables doesn't work when directory names have spaces

Let's say I want to store the following command in a variable cd "/cygdrive/c/Program Files/" So I do this dir="cd \"/cygdrive/c/Program Files/\"" That should store the command to navigate to ...
10
votes
2answers
3k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
6
votes
7answers
495 views

Can I shorten my directory commands in Ubuntu?

When working on a rails app I like to open all of my files through the command line like so CD my_app gedit app/views/user/show.HTML.erb Is there a way that I could shorten this so that I could ...
5
votes
3answers
2k views

cp -u is illegal on mac. What are the alternatives?

I have a MacbookPro Lion, and I have tried to archive my files that is tried to copy and overwrite if the source is newer than the destination. I tried the following command cp -u source destination ...
5
votes
2answers
3k views

Removing files matching a numeric range regular expression

I have a folder which has many files. Some of the data files are labelled 1, 2, 3, ..., 300 I want to remove these data files using the terminal. How do I do this? I want to do something like rm ...
4
votes
3answers
2k views

Supply SU password in a bash script, within the script?

The purpose is to restart the machine if it doesn't get an abort command from the user. The problem is that the way the terminals are set up, user must supply SU password for shutdown, init, reboot, ...
4
votes
4answers
13k views

bash process uses 90% CPU, comes back on computer restart

I’ve replaced the old HDD of my late 2008 unibody MacBook (8 GB of RAM, running OS X 10.7.4) with an OCZ Vertex 3 SSD. After doing this, I've installed Lion and restored my data from a Time Machine ...
3
votes
6answers
203 views

How to match everything from after the last YAML delimiter onwards

I normally use grep to search for a pattern in a string. However in this particular instance I have to identify a YAML header, also, it ends with a triple dash. My test.info file has the following ...
3
votes
4answers
845 views

When I ssh into a ubuntu machine, what kind of shell am I using

I keep reading about interactive, non-interactive, login, and non-login shells. (This is in the context of which of the .bash* files is read). I don't understand what each type of shell is, so let's ...
3
votes
2answers
737 views

save bash history, regularly

I have bash set up to save history, to a file. It does this whenever bash exits [properly]. As sometimes bash does not exit properly the history is lost. So the question is can I set up bash to save ...
3
votes
5answers
235 views

Writing in bash while it is working

When you are performing time consuming operations in bash like installing new software, is it possible to write text that will appear at the prompt when the operation has finished. E.g Imagine ...
2
votes
4answers
2k views

Can't install Git

Im following the tutorial below to install git. https://help.github.com/articles/set-up-git However when I get to the end where I need to install the helper into the same directory where Git itself ...
2
votes
1answer
1k views

Tab Auto-Completion in Mac OS X when using sftp in terminal

i have been getting very frustrated lately since the readline functionality has been removed from MacOSX and Tab Auto-Completion doesn't work anymore. So i was wondering if anyone knew a good ...
2
votes
4answers
1k views

Mass Rename Files with bash

I've got a bunch of numbered files like this: file #01.ext file #02.ext file #03.ext file #04.ext file #05.ext And what I want is to make them all have three digits (two leading 0's) instead of ...
1
vote
1answer
71 views

Bash quotes unescaped on command substitution

Can someone explain me why this is working (listing the contents of a directory that has a whitespace in its name): ret="$(ls "my dir")" Shouldn't it rather be interpreted as: ret="$(ls " my dir ...
1
vote
1answer
39 views

Website updating from git (over ssh)

I have a script that I run over SSH, which updates my website from a Git repo. cd website-git git checkout master git pull # Update protected directory rsync -v -a --delete --exclude=db ...
1
vote
1answer
92 views

Using cURL command-line tool on Mac, What can I do to this script to ask it to fetch stock data which will replace commas with NO SPACES

Example: Google Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API via the below script. The issue is; that numbers WITH commas or spaces are a bloody ...
1
vote
2answers
381 views

How to make a bash script wait and then continue running?

I have an .sh script. I would like to wait 25 minutes and then continue running, NOT repeat. It's something like this: #!/bin/bash /bin/bash ~/path/script.sh I want it to kill a process after ...
1
vote
1answer
293 views

Clean logging with BASH

I have a script that deletes files 7 days or older and then logs them to a folder. It logs and deletes everything correctly but when I open up the log file for viewing, its very sloppy. ...
1
vote
1answer
185 views

put in bash or zsh history absolute path to files I working on

I have found that in bash i frequently use something like that: vim ./somefile1 less less ./dir1/dir2/somefile2 cp some_other_relative_path_to_file and so on After that when I trying to find a ...
1
vote
2answers
291 views

What determines what shows up in the bash history command?

When I run history, I get a list of commands. However, it does not appear to be complete, even for a given period of time. (It doesn't feel like it has continuous coverage of the past N commands - it ...