I found myself typing find . -name "*.java" | xargs -iHn "something" so often I decided to make it into a bash script and put it in a new ~/Dropbox/bin folder so that I never have to do it again. Worse I never use the print0 option which let's you search files that have spaces in the filename, as it's too hard to remember. So, here's the script.
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
Sunday, June 29, 2014
Easy find
I found myself typing find . -name "*.java" | xargs -iHn "something" so often I decided to make it into a bash script and put it in a new ~/Dropbox/bin folder so that I never have to do it again. Worse I never use the print0 option which let's you search files that have spaces in the filename, as it's too hard to remember. So, here's the script.
Tuesday, April 1, 2014
Watch
So this is pretty cool.
The watch command (available linux and on Mac via brew) will run a program every n seconds and display the results in a terminal.
For example, the following common will show the display above with human readable disk free space on your system. But since the command can be anything you want this is a pretty powerful tool.
The watch command (available linux and on Mac via brew) will run a program every n seconds and display the results in a terminal.
For example, the following common will show the display above with human readable disk free space on your system. But since the command can be anything you want this is a pretty powerful tool.
watch -n 3 df -h
Sunday, April 29, 2012
find grep on Mac OS X
On linux machines I search files using find, egrep and xargs as follows:
find . -name "*.cpp" | xargs -i egrep -iHn "some search string" {}
this outputs any matches with the filename and number and also disables case dependency.
On my Mac it doesn't work. I tried reverting to egrep -r (to search recursively) instead, but that doesn't work. It just fails silently too. I tried installing findutils with brew to see if that helped, as often gnu tools are more up to date in brew than in the Apple version, but that didn't help.
So after some fiddling I found that the syntax below works:
find . -name "*.cpp" | xargs egrep -iHn "some search string"
Only subtly different!
Actually, hold up, this does not work for filenames that have spaces in them. :(
Try this instead:
find . -type f -print0 | xargs -0 egrep -iHn "some search string"
J.
find . -name "*.cpp" | xargs -i egrep -iHn "some search string" {}
this outputs any matches with the filename and number and also disables case dependency.
On my Mac it doesn't work. I tried reverting to egrep -r (to search recursively) instead, but that doesn't work. It just fails silently too. I tried installing findutils with brew to see if that helped, as often gnu tools are more up to date in brew than in the Apple version, but that didn't help.
So after some fiddling I found that the syntax below works:
find . -name "*.cpp" | xargs egrep -iHn "some search string"
Only subtly different!
Actually, hold up, this does not work for filenames that have spaces in them. :(
Try this instead:
find . -type f -print0 | xargs -0 egrep -iHn "some search string"
J.
Saturday, April 17, 2010
Using tar and gzip

Picture from flickr by Windwirral
First you want to create and add files to the archive. Go to the target directory and enter individual filenames and directories you want to have included.
tar -vzcf mystuff.tar.gz file1.txt file2.doc mypictures/
Now you can test if that worked by listing the files in the archive.
tar -tvf mystuff.tar.gz
When you want to extract the files, go to the folder where you want to extract them, in this case 'targetfolder'.
cd targetfolder
tar -vxf mystuff.tar.gz
Subscribe to:
Posts (Atom)

