Copy folder recursively, excluding some folders

Use rsync: rsync -av –exclude=”path1/to/exclude” –exclude=”path2/to/exclude” source destination Note that using source and source/ are different. A trailing slash means to copy the contents of the folder source into destination. Without the trailing slash, it means copy the folder source into destination. Alternatively, if you have lots of directories (or files) to exclude, you can … Read more

How do I create a nice-looking DMG for Mac OS X using command-line tools?

After lots of research, I’ve come up with this answer, and I’m hereby putting it here as an answer for my own question, for reference: Make sure that “Enable access for assistive devices” is checked in System Preferences>>Universal Access. It is required for the AppleScript to work. You may have to reboot after this change … Read more

Purpose of #!/usr/bin/python3 shebang

#!/usr/bin/python3 is a shebang line. A shebang line defines where the interpreter is located. In this case, the python3 interpreter is located in /usr/bin/python3. A shebang line could also be a bash, ruby, perl or any other scripting languages’ interpreter, for example: #!/bin/bash. Without the shebang line, the operating system does not know it’s a … Read more

Test for non-zero length string in Bash: [ -n “$var” ] or [ “$var” ]

Edit: This is a more complete version that shows more differences between [ (aka test) and [[. The following table shows that whether a variable is quoted or not, whether you use single or double brackets and whether the variable contains only a space are the things that affect whether using a test with or … Read more

How to resolve symbolic links in a shell script

readlink -f “$path” Editor’s note: The above works with GNU readlink and FreeBSD/PC-BSD/OpenBSD readlink, but not on OS X as of 10.11. GNU readlink offers additional, related options, such as -m for resolving a symlink whether or not the ultimate target exists. Note since GNU coreutils 8.15 (2012-01-06), there is a realpath program available that … Read more

How to redirect the output of a PowerShell to a file during its execution

Maybe Start-Transcript would work for you. First stop it if it’s already running, then start it, and stop it when done. $ErrorActionPreference=”SilentlyContinue” Stop-Transcript | out-null $ErrorActionPreference = “Continue” Start-Transcript -path C:\output.txt -append # Do some stuff Stop-Transcript You can also have this running while working on stuff and have it saving your command line sessions … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)