Tag Archive for 'bash'

Using bash to find a file modified in a specific date/time interval?

Did you ever need to find a file stored somewhere in a bunch of folders, which you didn’t remember the name, but you remember about when you last modified the file? At work, it sometimes happens that I need to find some log file, among 20 Gigs of log files, which was modified on a certain day. Here is a simple bash trick to do just that:

 touch -d "13 october 2006 15:00:00" ~/date_start
 touch -d "14 october 2006 21:00:00" ~/date_end
 find some/path -newer ~/date_start -and -not -newer ~/date_end

Start Cygwin from a folders context menu

My friend had a great little program, which essentially let you right click on any folder and open the command prompt there. The only program is that I never use the command line (CMD.EXE)… I use cygwin. A wonderful program that emulates Linux for windows, but also makes everything complicated!

After a short search on the web, I found a nice little discussion on a newsgroup that explained how to do it for cygwin. I just wanted to note the steps for windows XP, just so I don’t forget (If you really care… you can find steps for other versions on the discussion board).

1. Edit Registry

Start regedit.exe.

HKEY_CLASSES_ROOT\Directory\shell\BashHere="Bash Here"
HKEY_CLASSES_ROOT\Directory\shell\BashHere\command="C:\\WINDOWS\\System32\\CMD.EXE /E:4096 /c C:\\cygwin\\cygwin.bat %1"

Adjust the path to cygwin.bat if necessary.

Finish regedit.

You should now see the entry “Bash Here” in the context menu of a folder. However, when you use it, it will start the shell in your home directory ($HOME).

2. Edit cygwin.bat in c:/cygwin

Insert “set BASHHERE=%1″ before the line with “bash…”. This Environment variable now contains the complete path of the opened folder and is availabile in the bash shell (echo $BASHHERE).

3. Edit profile

Make $BASHHERE the current directory by adding the following line to
/etc/profile or ~/.profile:

if [ "$BASHHERE" != "" ]; then
    cd $( echo $BASHHERE | tr "\134" /)
fi

Vim Tip: Restore cursor’s last position

Here’s a useful vi trick that turned out to be a real time saver. It’s a set of commands you add to your vimrc file (on windows) that will recover the cursor’s last position when the file was last closed. The original tip was found on the vim wikia, which is full of those very useful vim tricks. Give it a try!

" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :20 : up to 20 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
 
" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
 au!
 autocmd BufReadPost *
 \ if expand("<afile>:p:h") !=? $TEMP |
 \ if line("'\"") > 1 && line("'\"") <= line("$") |
 \ let JumpCursorOnEdit_foo = line("'\"") |
 \ let b:doopenfold = 1 |
 \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
 \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
 \ let b:doopenfold = 2 |
 \ endif |
 \ exe JumpCursorOnEdit_foo |
 \ endif |
 \ endif
 " Need to postpone using "zv" until after reading the modelines.
 autocmd BufWinEnter *
 \ if exists("b:doopenfold") |
 \ exe "normal zv" |
 \ if(b:doopenfold > 1) |
 \ exe "+".1 |
 \ endif |
 \ unlet b:doopenfold |
 \ endif
augroup END




coolphotoblogs Photo Blog Blogsbonuel at flickrvfxy W