School of Computing. Dublin City University.
Online coding site: Ancient Brain
coders JavaScript worlds
chmod u+rwx,go+rx-w $*
chmod u+rwx,go-rwx $*
directories:
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.
If we "ls" a list of files - some of which exist and some do not - we get error messages.
e.g. Type this in a Web directory:
ls -l *html *css *js *phpBut what if one of these groups does not exist.
Here is a quiet version using a for loop and an if statement:
for i in $* do if test -f $i then ls -l $i fi done
Let's say every day we run a cleanup script that removes old editor .bak files:
rmifexists *.bak
If there are none today, or in this directory, this will give error messages.
Can we make a silent rm that does not complain about non-existing files?
for i in $* do if test -f $i then rm $i fi done
Why not:
if test -f $* then rm $* fi
A Steam for Linux
shell script
included a highly dangerous rm -rf line in 2015.
This led, depending how it was run,
to entire user filesystems being destroyed.
rmifexists *% rmifexists .*% rmifexists *~ rmifexists .*~ rmifexists *.bak rmifexists .*.bak rmifexists *.BAK rmifexists .*.BAK
shake ireland
To make 1/4 size versions of 10,000 JPEGs without ever opening an image editor (or doing any work):
for i in *jpg do djpeg -scale 1/4 -bmp $i > temp.bmp cjpeg temp.bmp > small.$i done |
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.
for i in *pdf # i = x.pdf do x=`basename "$i" ".pdf"` # get root filename x (without .pdf bit) pdfimages -j $i $x # extracts images to x-nnn.jpg done |
# extract images and save as default PPM: pdfimages file.pdf prefix # extract images and save as JPEGs: pdfimages -j file.pdf prefix # sometimes JPEGs do not extract well, save all images as PNG: pdfimages -png file.pdf prefix # just list all images without extract: pdfimages -list file.pdf pdfimages -help
Your Shell script can bulk convert, split, join, rotate and resize thousands of videos. Without opening any window.
Not installed at DCU. Get your own Linux and install it.