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 programs

norm - set permissions as open as possible

chmod  u+rwx,go+rx-w  $*

hide - as hidden as possible

chmod  u+rwx,go-rwx  $*

semihide - just open enough as needed for Web


chmod  u+rwx,g-rwx,o+x-rw  $*
files (web pages, images, etc):
chmod  u+rwx,g-rwx,o+r-xw  $*
"norm" could of course replace all 3 if you don't mind granting more access than strictly necessary.

rmifexists - silent repeated delete

e.g. Want to be able to repeatedly run:
rmifexists *.bak
and not get error message if no *.bak files found.

for i in $*
        if test -f $i
         rm $i


Why not:

        if test -f $*
         rm $*

Recursive rm

"Trying out some Deadly Linux Commands".
Includes typing rm -rf / and other scary commands, including the hilarious: mv / /dev/null
See more videos of people typing rm -rf /

wipe - clean up editor backup files

rmifexists *%
rmifexists .*% 

rmifexists  *~
rmifexists .*~

rmifexists  *.bak
rmifexists .*.bak

rmifexists  *.BAK
rmifexists .*.BAK
  1. Easier than having to point-and-click each one. Especially if do this for multiple directories.
  2. Safer than typing "rm *bak" every day. One day you will type "rm * bak"
  3. In general, if you regularly type some command that would be dangerous if you make a typo, it would be better to debug it once and put it in a script and never type it directly again.


Write a recursive wipe.

myspace - which of my directories use the most space

cd $HOME
du | sort -n

Command-line image processing

We need libjpeg utilities.
Should be installed on DCU Linux.

To make 1/4 size versions of 10,000 JPEGs without ever opening an image editor (or doing any work):

for i in *jpg

 djpeg  -scale 1/4 -bmp $i  > temp.bmp

 cjpeg  temp.bmp            > small.$i


JPEG needs to be decoded to a BMP (bitmap), then be re-sized, then re-coded back to JPEG.
Can do this in one line, leaving out the temporary file: Pipe result of djpeg into input of cjpeg.


Extract images from PDFs

I was once given an archive of thousands of scanned historical images. They were all inside PDFs.

I automatically extracted all the JPEGs from the PDFs as follows:

for i in *pdf					# i = x.pdf

  x=`basename "$i" ".pdf"`		# get root filename x (without .pdf bit)

  pdfimages  -j  $i  $x  		# extracts images to x-nnn.jpg



Command-line movie processing

You can do command-line movie processing with ffmpeg.

Your Shell script can bulk convert, split, join, rotate and resize thousands of videos. Without opening any window.

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.