James Fishwick

  •  Minimal
  •  CSS Tomfoolery

Can regex even match a null character?

CLI, Code Snippet, Note to Self

No Comments


Share this post

Yes.
\x00
That is a null char and you can match it with any PCRE engine. Note that most visual tools, like Dreamweaver etc, won’t handle this well, and won’t even display it. In fact, most will stop processing the file when they hit the null character.

The exception being the mighty Notepad++. So use that if you’re afraid of the CLI.

Read more

Get a list of recursive one-per-line paths

CLI, linux

No Comments


Share this post

just want a flat listing of files with their full paths?

No, no, no. Don’t use ls. Use find.

find . -type f

Get certain file types:

find . -name \*.txt

Even better, if you have it, is tree. So boss. In fact, install this now if you don’t have it. Check it.

tree -if .
tree -if directory/

For just files:

tree -if | grep -v \>

Of course, grep out any certain file types if you want.

Read more

total directory size hold the extra foo

CLI, Code Snippet

No Comments


Share this post
du -h | tail -n 1

Read more

bash find and boolean operators

CLI, Code Snippet, Note to Self

No Comments


Share this post

Just because it took me way too long this morning to figure out how Boolean operators work with find.

Suppose I want to find the files with .png and .jpg extensions.

Its not

$ find /path/ -name '*.png' -and -name '*.jpg'

but

$ find /path/ -name '*.png' -or -name '*.jpg'

The “-and” refers to one set of file names where both conditions are met (as if we didn’t use the boolean at all). The “-or” says I’m looking for either/both of two sets.

So to explain further:

Read more

Download a list of HTML pages with dependencies

CLI, Code Snippet

No Comments


Share this post
wget --page-requisites -i list.txt

Where ‘list.txt’ is a list of URLs separated by line breaks.

If you aren’t interested in certain files, say images, there is a further flag to reject certain file types:

--reject=gif,jpg,png

I love wget!

 

Read more

textutil use cases

CLI, Note to Self, Production Automation

No Comments


Share this post

I don’t use my Mac as my main development/production workstation anymore, but its still my one-stop shop for all matter of text conversions.

While I have a very specific and regular use-case for textutil, namely converting Word .docs into barebones HTML or PDFS, there are plenty of features that make it a highly useful and general purpose tool. textutil can convert from/to txt, html, rtf, rtfd, doc, docx, wordml, odt and webarchive.

The basic syntax is:

textutil -convert fmt filename

Read more