Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain


CA216      CA249      CA318

CA400      CA651      CA668

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

Feeds      w2mind.org      ancientbrain.com

On the Internet since 1987.