What’s the difference between an exclusive lock and a shared lock?

I wrote this answer down because I thought this would be a fun (and fitting) analogy: Think of a lockable object as a blackboard (lockable) in a class room containing a teacher (writer) and many students (readers). While a teacher is writing something (exclusive lock) on the board: Nobody can read it, because it’s still … Read more

Shell Script — Get all files modified after

as simple as: find . -mtime -1 | xargs tar –no-recursion -czf myfile.tgz where find . -mtime -1 will select all the files in (recursively) current directory modified day before. you can use fractions, for example: find . -mtime -1.5 | xargs tar –no-recursion -czf myfile.tgz

Get last field using awk substr

Use the fact that awk splits the lines in fields based on a field separator, that you can define. Hence, defining the field separator to / you can say: awk -F “https://stackoverflow.com/” ‘{print $NF}’ input as NF refers to the number of fields of the current record, printing $NF means printing the last one. So … Read more

mkdir’s “-p” option

The man pages is the best source of information you can find… and is at your fingertips: man mkdir yields this about -p switch: -p, –parents no error if existing, make parent directories as needed Use case example: Assume I want to create directories hello/goodbye but none exist: $mkdir hello/goodbye mkdir:cannot create directory ‘hello/goodbye’: No … Read more

Shell script “for” loop syntax

Brace expansion, {x..y} is performed before other expansions, so you cannot use that for variable length sequences. Instead, use the seq 2 $max method as user mob stated. So, for your example it would be: max=10 for i in `seq 2 $max` do echo “$i” done