2017年5月15日 星期一

[Linux] How to find all files containing specific text on Linux?

grep -rnw '/path/to/somewhere/' -e 'pattern'
  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.
P.S. example: to find "if ["

grep -rnw '/path/to/somewhere/' -e 'if \['

    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...
    }

    2014年7月29日 星期二

    [Xcode] Fixed: Build error that it import Objective-C codes in the .cpp?

    Build error: (NSObjCRuntime.h & NSObject)

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:371:1: Expected unqualified-id

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:373:19: Unknown type name 'NSString'
    ...

    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/objc/NSObject.h:11:1: Expected unqualified-id
    ...


    [Solution]
    rename extension name from .cpp into .mm

    [Xcode] Fixed: _CMAudioFormatDescriptionGetStreamBasicDescription", referenced from: -[captureNSObject init] in captureNSObject.o

    I have a project to build some code,  and then it has error in the follow:

    Undefined symbols for architecture x86_64:
      "_CMAudioFormatDescriptionGetStreamBasicDescription", referenced from:
          -[captureNSObject init] in captureNSObject.o
      "_CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer", referenced from:
          -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
      "_CMSampleBufferGetNumSamples", referenced from:
          -[captureNSObject captureOutput:didOutputSampleBuffer:fromConnection:] in captureNSObject.o
    ld: symbol(s) not found for architecture x86_64

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    [Solution]
    Add CoreMedia.framework into "Linked Frameworks and Libraries".

    2014年7月24日 星期四

    [Xcode] Enable/disable a button

    @property (retain, nonatomic) IBOutlet UIButton *btnButton;
    enable/disable like this in .m file:
    btnButton.enabled = NO; // disable button
    btnButton.enabled = YES; // enable button