Generating a password-protected archive

Generating an archive file from either a file or directory is a cinch using the command-line. Here’s the structure: zip [options] [archive name] [file or folder to be archived] While there are many options available, the one we’re interested in is -e, for “encrypted”, like so: zip -e example.txt To create a password-protected archive […]

Using “du” to determine directory size

The *nix command ls returns lots of useful information, particularly with the -alh flags, to display permissions, owner, group, modification date, file name, and human-readable size for all files and directories within the current directory. Well, sort of. It falls short on directory size, treating the directory like a file and returning only the size […]

Changing ownership with chown

Because I can never remember the syntax for CHanging the OWNer of a file or directory, here it is in all of its glory: chown [new owner] [file or directory] If, for example, I wanted to change the owner of /var/www/vhosts/my_website/tmp to “root” I’d run this: chown root /var/www/vhosts/my_website/tmp If you want to apply the […]

Removing a non-empty directory

It’s fine to use rmdir [dir name] for empty directories. If you’re looking to remove a non-empty directory you need recursion: rm -rf [dir name] Use with caution — you will not be prompted to verify! I always run a ls -l on the directory in question immediately before running this command, just to idiot-check […]

Changing permissions with chmod

Here’s the syntax for CHanging permissions or MODe — also known as “chmod” — for files & directories: chmod [permissions] /path/to/file/or/directory The three possible users are: file owner group of authorized users everyone else (a.k.a. “the world”) The possible actions (and associated binary values) are: 4: read 2: write 1: execute Total the values for […]