顯示具有 [Linux] 標籤的文章。 顯示所有文章
顯示具有 [Linux] 標籤的文章。 顯示所有文章

2021年10月25日 星期一

[Linux] Check os version in Linux

> cat /etc/os-release

root@58d01b6b8b17:/# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

2017年8月15日 星期二

[Linux] How to add a literal tab character in a bash shell?

$'\t'

ex: $ sort -t $'\t'
$ echo -n $'\t'

$ echo -e ' \t ' | hexdump -C
00000000 20 09 20 0a | . .| 00000004

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