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

learn more… | top users | synonyms

6
votes
4answers
6k views

Unix command to list all directories larger than 10mb

Is this possible, and what would the command be?
5
votes
5answers
3k 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
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 ...
4
votes
2answers
971 views

Creating an alias containing bash history expansion

I often forget to run a command with sudo, so I find myself often typing sudo !! immediately afterwards. I tried aliasing this, but bash chokes on the !! part. Is there some way to represent this ...
3
votes
2answers
8k 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 ...
3
votes
1answer
2k 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
2k 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
6k 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
2answers
667 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 ...
2
votes
1answer
2k 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
97 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 ...
0
votes
2answers
2k 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 ...
0
votes
2answers
168 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 ...
11
votes
4answers
6k 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 ...
8
votes
2answers
2k 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
436 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
5k 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 ...
5
votes
2answers
8k 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 ...
4
votes
3answers
1k 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 ...
4
votes
4answers
11k 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
159 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
630 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
3answers
3k views

sudo permission denied

I ran this code: sudo cat <<EOF | sudo sed -e "s,%,$,g" >/etc/init.d/dropbox echo "Hello World" EOF But even though, I get "permission denied", cause you have to be root to make changes ...
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
839 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
1answer
674 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 ...
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
26 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
147 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
113 views

Bash prompt error when pressing up arrow

I've written this nice and colorful prompt for my OS X terminal: parse_git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ [\1]/' } export ...
1
vote
1answer
235 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
151 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
249 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 ...
1
vote
2answers
2k views

Open a terminal from a Crontab

How do I get a gnome-terminal window to open from a crontab? I have tried this: * * * * * /usr/bin/gnome-terminal * * * * * source /home/user_name/.bashrc ; /usr/bin/gnome-terminal * ...
1
vote
2answers
4k views

“Syntax error near unexpected token '$'\r''” in shell script [closed]

I am writing a script am I am getting an error on lines 2-3. The error is printed like this: ./ex6.sh: line2: $'\r': command not found ./ex6.sh: line3: syntax error near unexpected token '$'\r'' ...
1
vote
1answer
173 views

PS1 problem, cmd is looping

I've set PS1 to the following value: PS1="\033[0;37m[\033[1;33m\w\033[0;37m]\n\t \[[34m\]\u\033[0;37m@\[[34m\]\[[1m\]\h\[(B[m\] $" The problem is that any command spanning more than a line loops ...
1
vote
1answer
579 views

Creating an alias or function, need to be able to pass in a parameter

I want to wrap 3 lines of execution into an alias, but I also need to pass a parameter when I call it in terminal. Do I need to create a function for this? I'm new to this, but I know there are ...
1
vote
3answers
500 views

On a Mac, how can I group together commands I want run into a alias?

In my .bash_profile I have created alias to commands that I run often. What if I want to group together multiple commands together, and they should run in serial one after the other. How would I do ...
1
vote
1answer
423 views

When does mac/ubuntu use .bash_profile and/or .bashrc? [duplicate]

Possible Duplicate: Difference between .bashrc and .bash_profile Are they both the same type of file in terms of setting the bash terminal settings, and if no .bash_profile exists then it ...
1
vote
1answer
573 views

Multiple hops SSH tunnel

I need to open an ssh tunnel through to an oracle database port...after much fluffing around I cant seem to get it to work. Here is the scenario... My Machine --> host1 --> host2 --> ...
1
vote
5answers
2k views

Insert a newline in a perl -e statement?

Consider the following Perl one-liner: perl -e '$x; $y;' I'm executing this command in bash and I'd like to insert a newline (\n) between the ; and $y. I'd like to know how to do this in two ...
1
vote
3answers
951 views

Custom Vim Highlighting (only works with specific file types)

I have this in my vimrc: "on will override defaults set. Enable will allow you to set defaults." syntax enable ... "attempting to highlight specific keywords so it is easy to see in code." "see ...
0
votes
1answer
102 views

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

I'm trying to test my installation for Pickit 2 on my Mac for the first time and when I put in: pk2cmd -?v I get: -bash: /usr/local/bin/pk2cmd: cannot execute binary file How do I resolve this ...
0
votes
1answer
37 views

Script won't loop through files like planned

I got this script that loops through log files, but I changed something and it doesn't work: #!/bin/sh n= while true do fname="trace$n.log" [ -f "$fname" ] || break n=$(($n+1)) done ...
0
votes
1answer
47 views

Run a command on every file in a directory, changing the output name

I need to compile all of the C files in a directory into seperate outputs... see example gcc -Wall program1.c -o program1.out How do I do this?
0
votes
2answers
86 views

Different initial BASH prompt

This is somewhat of a cosmetic (and trivial) question, but I suppose it may be useful to others than myself. I've been playing around with the $PS1 variable in my ~/.bashrc, and I was wondering if ...
0
votes
2answers
398 views

How to permanently reset my $PATH?

I was trying to add something to $PATH and it went totally wrong. I now can't run any commands such as ls. I've looked at this answer ...
0
votes
2answers
4k 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
860 views

How to use sudo with rcp command to copy files from linux host to HP-UX host?

I'm having this issue where when I try to use sudo to rcp some files from a Linux host to an HP-UX host (note that the destination directory requires root access to write to), I get the following ...