2016年7月28日 星期四

[Linux] Create encrypted (password protected) zip/upzip file

 - zip 

This will prompt for a password:
zip --encrypt file.zip files
This is more insecure, as the password is entered/shown as plain text:
zip --password (password) file.zip files

Warning, the standard zip encryption is very weak and is easily cracked.


- unzip 

unzip -P (password) file.zip

2016年3月4日 星期五

[Linux] How can I get what my main function has returned

Most shells store the exit code of the previous run command in $? so you can store or display it.
$ ./a.out
$ echo $?     # note - after this command $? contains the exit code of echo!
or
$ ./a.out
$ exit_code=$?    # save the exit code in another shell variable.

[Linux] Checking if a directory exists in Unix (system call)

#include <sys/stat.h>

struct stat sb;

if (stat(pathname, &sb) == 0 && S_ISDIR(sb.st_mode))
{
    ...it is a directory...
}