The Archives
-
02.15.11find command in PowershellIn 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 ...
-
03.06.09Accents everywhere (to be removed, obviously)Accents have again (I still live in Spain and do some work for the Spanish Administration) crept into my terminal. This time it was a group of University professors which had to create a lot of files and directories concerning a historical catalog and even though I remember telling the coordinator not to use accents or spaces or any funny characters, they did it. I should have known better... The problem was then to take away all spaces and non-ASCII characters from directory and file names. After thinking about it a bit, I came up with the solution below. There may be ...
-
02.22.09Perl directory traversalThe following chunk of code sub traverse { my ($dir, $callback) = @_; my $present; opendir $present, $dir or return(); for (grep { ! /^(\.|\.\.)$/ } readdir $present) { my $path = "$dir/$_"; &$callback($path); traverse($path, $callback) if -d $path; } closedir $present; return(); } is an easy implementation (without error-checking) of a generic directory-traversing function in Perl. It should be called traverse(dir, ...
-
01.23.09Space forSo your friend sent you a batch of tiffs to be converted into jpg's (using ImageMagick's convert command). However your friend (who is not so geeky as you) uses spaces in filenames (which is a deadly sin), like in First photo of birthday.tiff Second photo.tiff You wanted to use a shell for loop, but the obvious $ for i in `find . -name *tiff` ; do convert "$i" "${i%tiff}jpg" ; done produces garbage (try it). This is just one of the consequences of your friend's carelessness. But there is a solution. IFS (Internal Field Separator) is a shell variable controlling what character(s) delimit a 'field' in ...
-
11.10.08Find files ending in mp3$ find / -name "*.mp3" Search for (starting at the root / directory) all the files ending in ".mp3"
-
10.25.08Recursive grep in Solaris$ find . | xargs grep PATTERN In Solaris, the grep command does not have the -R (-r, --recursive) option which reads all files under each directory, recursively. The above command can be used to do the same in Solaris.