bash

How Can I Remove .DS_Store Files From A Git Repository?

How can I remove those annoying Mac OS X .DS_Store files from a Git repository? ...

count (non-blank) lines-of-code in bash

In Bash, how do I count the number of non-blank lines of code in a project? ...

How to compare files with same names in two different directories using a shell script

Before moving on to use SVN, I used to manage my project by simply keeping a /develop/ directory and editing and testing files there, then moving them to the /main/ directory. When I decided to move to SVN, I needed to be sure that the directories were indeed in sync. So, what is a good way to write a shell script [ bash ] to recursivel...

Problem with Bash output redirection

I was trying to remove all the lines of a file except the last line but the following command did not work, although file.txt is not empty. $cat file.txt |tail -1 > file.txt $cat file.txt Why is it so? ...

Bash variable scope

Please explain to me why the very last "echo" statement is blank? I expect that it was incremented in the while loop to a value of 1: #!/bin/bash OUTPUT="name1 ip ip status" # normally output of another command with multi line output if [ -z "$OUTPUT" ] then echo "Status WARN: No messages from SMcli" exit $STATE_WARNIN...

How do I remove the file suffix and path portion from a path string in Bash?

Given a string file path such as "/foo/fizzbuzz.bar" how would I use bash to extract just the "fizzbuzz" portion of said string? ...

Sync File Modification Time Across Multiple Directories

I have a computer A with two directory trees. The first directory contains the original mod dates that span back several years. The second directory is a copy of the first with a few additional files. There is a second computer be which contains a directory tree which is the same as the second directory on computer A (new mod times an...

Count number of occurences of token in a file

I have a server access log, with timestamps of each http request, I'd like to obtain a count of the number of requests at each second. Using sed, and cut -c, so far I've managed to cut the file down to just the timestamps, such as: 22-Sep-2008 20:00:21 +0000 22-Sep-2008 20:00:22 +0000 22-Sep-2008 20:00:22 +0000 22-Sep-2008 20:0...

How do I run a command in a loop until I see some string in stdout?

I'm sure there's some trivial one-liner with perl, ruby, bash whatever that would let me run a command in a loop until I observe some string in stdout, then stop. Ideally, I'd like to capture stdout as well, but if it's going to console, that might be enough. The particular environment in question at the moment is RedHat Linux but ne...

Can I specify redirects and pipes in variables?

I have a bash script that creates a Subversion patch file for the current directory. I want to modify it to zip the produced file, if -z is given as an argument to the script. Here's the relevant part: zipped='' zipcommand='>' if [ "$1" = "-z" ] then zipped='zipped ' filename="${filename}.zip" zipcommand='| zip >' fi echo "C...

Setting environment variables in OS X?

What is the proper way to modify environment variables like PATH in OS X? I've looked on google a little bit and found 3 different files to edit: /etc/paths ~/.profile ~/.tcshrc I don't even have some of these, and I'm pretty sure that .tcshrc is wrong, since osx uses bash now. Anybody have any idea where these variables, especially...

is bash getopts function destructive to the command-line options?

Can you use the bash "getopts" function twice in the same script? I have a set of options that would mean different things depending on the value of a specific option. Since I can't guarantee that getopts will evaluate that specific option first, I would like to run getopts one time, using only that specific option, then run it a secon...

How do I sort a file in place using bash shell?

I have a file temp.txt, that I want to sort with the "sort" command in bash. I want the sorted results to replace the original file. This doesn't work for example (I get an empty file): sortx temp.txt > temp.txt Can this be done in one line without resorting to copying to temporary files? EDIT: The -o option is very cool for sort. ...

How To Removing Trailing Whitespace Of All Files Recursively?

How can you remove all of the trailing whitespace of an entire project? Starting at a root directory, and removing the trailing whitespace from all files in all folders. Also, I want to to be able to modify the file directly, and not just print everything to stdout. ...

Escape < and > in sed/bash

How do I escape '<' and '>' character in sed. I have some xml files which needs some text between the tags to be replaced. How do I escape the '>' and '<' characters. The problem with > and < is it has special meaning in the shell to redirect the output to a file. So backslash doesn't work. ...

Case-insensitive Glob on zsh/bash

I need to list all files whose names start with 'SomeLongString'. But the case of 'SomeLongString' can vary. How? I am using zsh, but a bash solution is also welcome. ...

How to do something with bash when a text line appear to a file

I want to run a command as soon as a certain text appears in to a log file. How do I do it in bash? ...

bash script runs from shell but not from cron job

Cron installation is vixie-cron /etc/cron.daily/rmspam.cron #!/bin/bash /usr/bin/rm /home/user/Maildir/.SPAM/cur/*; I Have this simple bash script that I want to add to a cron job (also includes spam learning commands before) but this part always fails with "File or directory not found" From what I figure is the metachar isn't being ...

How to use 'find' to search for files created on a specific date?

How do I use the UNIX tool 'find' to search for files created on a specific date? ...

autoconf using sh, I need SHELL=BASH, how do I force autoconf to use bash?

I'm running autoconf and configure sets SHELL to '/bin/sh'. This creates huge problems. How to force SHELL to be '/bin/bash' for autoconf? I'm trying to get this running on osx, it's working on linux. Linux is using SHELL=/bin/bash. osx defaults to /bin/sh. ...