Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain


CA114      CA170

CA668      CA669      Projects

Sample Shell script - filterbaks

The following is to illustrate that   .* files are only "hidden" by convention. We can pipe all our commands through a "filterbaks" program to make lots of other files also hidden by convention:

Might hide text editor backup files (things like file%, file~, file.bak):

Directory listing program:

	ls -al $* | grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"

grep -v means match any line that -doesn't- contain the pattern
(i.e. filter out the lines that do)

$ means end-of-line
^ means start-of-line
. means any character
so \. means the literal character '.'

Do -precisely- the pattern that matches, no less and no more.
e.g. Don't match '.bak' or 'bak' in middle of filename like:


Might make it a separate file, called say "filterbaks":

       grep -v "%$" | grep -v "~$" | grep -iv "\.bak$"

so we can reuse it in directory listing:

	ls -al $* | filterbaks

and in other progs:

      if test `echo $i | filterbaks`
Makes backup files invisible everywhere (until needed).

Finally, it would be more efficient to replace 3 programs piped together with 1 program (with more complex arguments). (Why would this be more efficient?)
We can do this using the "egrep" program, which can grep for boolean expressions. filterbaks can be rewritten as simply:

	egrep -iv  "%$|~$|\.bak$" 
where, inside the string here,   |   means "OR".

d - my own ls script

ls -l $* | filterbaks

ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.

Wikipedia: Sometimes I link to Wikipedia. I have written something In defence of Wikipedia. It is often a useful starting point but you cannot trust it. Linking to it is like linking to a Google search. A starting point, not a destination. I automatically highlight in red all links to Wikipedia and Google search and other possibly-unreliable user-generated content.