shell

find command in Powershell

In my actual job I have a laptop with Windows 7 installed on it. The last time I used Windows on a daily basis was four years ago and it was Windows XP. The terminal (cmd.exe) was… well, that was not a real terminal neither a real shell.

The first days using Windows 7 I had a problem (which I will explain it later) and while I was installing cygwin to run some commands I found Powershell. I have to admit that Windows now has a real shell and it seems pretty powerful. It can be installed in Windows XP and Vista too.

The big difference between Powershell and any unix shell is that instead of the unix “all is a file” philosophy in Powershell one has to use objects.

The problem I had was I opened a Microsoft OneNote document I had received (I do not know why people do not like plain text files and have to use special programs to take notes, but that is another problem) and it created a file in every single directory of my G: partition. Each time I changed to a directory, there it was, a file with the extension onetoc2.

I looked for the find command in Powershell and I found Get-ChildItem (its alias is gci):

PS G:\> gci . -recurse -include *.onetoc2

The above command returns all the files with the extension onetoc2 in the G: partition. I was curious to know how many files OneNote had created so I run:

PS G:\> (gci . -recurse -include *.onetoc2).count
4228

I swear I only opened a single OneNote file a workmate sent me.

Finally to delete all the mysterious generated files I run:

PS G:\> gci . -recurse -include *.onetoc2 | ri

ri is the alias of the Remove-Item command.

I think this time Microsoft has provided sysadmins with a useful tool.

speak up

Add your comment below, or trackback from your own site.

Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*Required Fields