Archive for the 'OS' Category

Linux:Script to find files

Wednesday, August 17th, 2011

I regularly have to find where a file is located and usually use find:

find . | grep 

Where is replaced with the filename or partial name to match. So I finally decided to write a script to just run this and allow me to print the matching names and even potentially pass the -i flag to grep.

#!/bin/sh


if [ $# -lt 1 ]; then
  echo 1>&2 Usage: $0 ""
  exit 127
fi
icase=

while [ $# -ge 1 ]; do
   case $1 in
     -i)  icase=$1;;
      *)  search=$1 ;;
   esac
   shift
done

find .  | grep $icase $search

This is just a simple script which I have named ffind that searches starting from the current directory. This lets me search with the following commands:

ffind bak$

This will search for all files that end with “bak” .

ffind -i edr

This will search for all files with “edr” regardless of case

Tags: , , , ,

Ddrescue saves the day…eventually

Saturday, August 13th, 2011

So, after a Linux crash that caused my previous ddrescue to fail(after 350GB), I started to look into how to speed it up, because 30+ hours did not sound like a good idea to me.
I look into ways to speed it up and using a larger block size did the trick. I experimented with a few different sizes and figured out that using 2M gave me the best throughput. So instead of a couple of megs a second i was getting over 24 MB/s. So about a 4 1/2 hour recovery after that.

ddrescue -b 2M /dev/sda2 /media/newdisk/olddata /media/newdisk/logfile

The ddrescue process will attempt to recover any lost sectors and retrim the lost data. Luckily, I only lost about 3100k of data so the most of my data is safe.

You can attempt to rerun ddrescue with the -r <# of times to retry> and it will continue to attempt to read those failed sectors that were unrecoverable. There is no guarantee that you will get back all the data.

Once this data is recovered, you can (hopefully) mount this file as a disk under linux.

 mount /media/newdisk/olddata /mnt/newdisk 

Now remember to back up your data and you will not go through the pain that I did to recover this data.

Part 1 of article

Tags: , ,

Mounting drives in Linux

Tuesday, August 9th, 2011

Sometimes you have a drive that your want to mount under Linux. The mount command can make the drive available to you. But you need to also create a directory to hold the mount point.

mkdir /mnt/drivepoint

Then you can mount the drive to that mount point by using the mount command and giving the device identifier, in this case it is /dev/sda1, and the mount point which we created as /mnt/drivepoint. One thing to note, is that the mount will use whatever directory you specify, so if there are files located in the directory you use as a mount point, they will no longer be visible.

mount /dev/sda1 /mnt/drivepoint

This must be run as root or with the sudo command.

Tags: , ,

Setting timestamp with Touch

Wednesday, July 20th, 2011

Did you know? You can Set file timestamp using touch command. One way to do this is:
touch -c -t YYMMDDhhmm filename.txt

Retrieve drive letter on Windows

Thursday, June 16th, 2011

The other day I had to write a script to change to a working directory and back to the original directory. The problem was they were on different drives on Windows. So I had to find a way to capture the drive letter
and switch back to that drive. When using the following command,

cd F:somedir

you are not moved to the “F:” drive without an explicit “F:” command.

The cd Command on windows will show the current directory location. Using some string manipulation on that and capturing it to a variable allows us to go back to that drive.

REM Capture the current drive letter
set ORIGDRIVE=%cd:~0,2%

F:
REM some other scripting things here

REM Return to the original drive letter
ORIGDRIVE

The first line captures the current drive letter by specifying the first character with 0 and the ,2 states to pick up the next 2 characters which would hold the “C:” or whatever drive you started on.

Tags: , , ,

Windows: Grep for windows

Monday, May 2nd, 2011

If you don’t have access to a Unix environment on your windows box, you can still search files with findstr. The findstr command will allow you to search files close to the same way as grep.

findstr /S "search string"

will recursively find your string in the current directory and subdirectories.

There are more options that you can find if you run the following command:

findstr /?

will show you the help message.

Tags: ,

Linux: watch command

Monday, March 14th, 2011

So every once in a while I want to see the progress of an upload or backup. So I turn to the watch command in Linux. The watch command gives the user the ability to re-run a command and see the updated output.

The syntax is ‘watch -n -d .

So for watching a file downloads progress you could run the following:

watch -n 30 ls -l filedownloading

This would show the ls output and you could watch the size of the file grow as it is dowload progress.

Android: SD card unmounting when I connect to the computer

Wednesday, January 12th, 2011

So I was charging my Droid X and noticed that while I was connected I could not use my SD card anymore. And the camera will not take any picutures if there is no SD card present.

So I pulled down the task bar and selected “USB connection” .

Once I selected the “Charge Only” option, it was smooth sailing and my SD card was available to my phone again.

This is also the place to turn on “USB Mass storage” when you are ready to copy off those pictures.

Tags:

Droid X first glance

Wednesday, January 5th, 2011

So I finally moved away from the iPhone(as it turned horrible when I used the “supported” update to iOs 4 on my 3g) and have gotten myself a Droid X. This phone has been awesome(and I have only had it for 2 days).

The Google driving directions app that comes with the phone has been awesome and the unified mailbox is pretty cool. The Android market has been nice and I have perused quite a few apps so far and have been very excited as to what is out there. I was a little afraid as I had heard some less then great things but am very happy to be misinformed.

I am still on the hunt for a good messaging app that supports popup messages (like the iPhone had) and also looking for a new expense receipt tracking app.

I will be following up with some useful information about using the Android OS as I have access to two of them in the house.

I am excited to have this new toy and looking forward to the things I can do with it.

Tags: , , ,

Edit the hosts file

Monday, November 1st, 2010

If you have every wanted to set certain IP addresses in your network without depending on a nameserver, you can edit the ‘hosts’ file in your operating system.  This can be done to stop access to any inappropriate sites as well.

The hosts file in Windows is:

%systemroot%System32driversetchosts

This is typically  in:

c:windowsSystem32driversetchosts

On linux this file is:

/etc/hosts

The common layout of the file is

<IP address> hostname [hostname]

So if would look something like this:

127.0.0.1  localhost
192.168.2.222 homeserver homeserver.mydomain.net
127.0.0.1 badlocation

Remember that these lookups happen before looking to a nameserver. So this will override any name lookup. So if you happen to do this on a laptop that you regularly use outside of your home network, make sure that you do not override an address that might be needed when you are not at home.

You will need appropriate privileges to access the file. So you may have to be root or use sudo on Linux and you may have to open an editor as administrator before opening the file on Windows.

Tags: ,