Posts

Showing posts from November, 2021

Common Compression Instructions on Linux and Unix

 Below we will list a few common compressed file extensions. *.Z compress program compressed files; *.zip Files compressed by the zip program; *.gz files compressed by gzip program; *.bz2 The file compressed by the bzip2 program; *.xz xz program compressed file; *.tar The data packaged by the tar program has not been compressed; *.tar.gz tar program packaged files, which are compressed by gzip *.tar.bz2 tar program packaged files, which are compressed by bzip2 *.tar.xz tar program packaged files, which are compressed by xz   1. gzip, zcat/zmore/zless/zgrep Currently gzip can unzip files compressed by compress, zip and gzip. By default, the original file will be compressed into a .gz file name, and the original file will no longer exist . Compress and prints the compression ratio: $ gzip -v  service services:        79.7% -- replaced with services.gz Decompress: $ gzip -d service.gz Compress with the best compression ratio and keep the original file: $ gzip -c -9 service >

Common Commands for Sed on FreeBSD

Replace string: % sed -i .bak 's/original/new/g' test.txt      -i Edit files in-place, saving backups with the specified extension(here it is .bak ).   Replace the comments of C language: % sed 's/\(\/\*\).*\(\*\/\)//g' test.c Delete the line contains pattern string: % sed -i .bak '/pattern_string/d'  file.txt Add new line after pattern string: % sed -E 's/(pattern_string)/\1\nnew line/' file.txt -E Interpret regular expressions as extended (modern) regular expressions rather    than basic regular expressions (BRE's). \1 Represent pattern string. Escape single quote: % sed 's/ones/one\x27s/' And string ones thing will become one's thing . Copy specific lines in a file to another file: copy lines 10 to 15 of file1.txt into file2.txt . % sed -n '10,15p' file1.txt > file2.txt Non-greedy matching for ssed (super sed). The content of file test.txt was as follows: ssABteAstACoABnnACss   Non-greed matching command as follows:

The Different Commands between BSD Sed and GNU Sed

Replace string in the file. GNU sed: sed -i 's/original/new/g' test.txt BSD sed. You have to specify a backup file, like: sed -i .bak 's/original/new/g' test.txt

Generate PHP tags with exctags on FreeBSD

Generally, exctags(1) on FreeBSD is what you know as ctags on Linux based systems. 1.  Install exctags from port # cd /usr/ports/devel/ctags # make install clean Note: If you install ctags by command pkg install ctags , the ctags included in the basesystem is not what you expect on Linux based systems. For ctags you are looking for install ctags from package/ports, it will provide you with exctags binary. 2.  Generate tags  I generate tags by putting the generate_tags.sh script to the project directory and executes it. #!/bin/sh exec exctags \ --languages=PHP \ --langmap=PHP:+.phpt \ -h ".php" -R \ --exclude="\.git" \ --totals=yes \ --tag-relative=yes \ --PHP-kinds=+cdf \ --regex-PHP='/abstract class ([^ ]*)/\1/c/' \ --regex-PHP='/interface ([^ ]*)/\1/c/' \ --regex-PHP='/(public |static |abstract |protected |private )+function ([^ (]*)/\2/f/'   CTRL + ]   Go to tag's definition.  CTRL + t   Jump back from definition. or CTRL + o  

Commond Commands in Vim Command(Normal) Mode

dG : Deletes all data up to the last column where the cursor is located. gd   :  Goes to the local declaration in current file, while placing the cursor on any variable or function in your program. gD   : Goes to the global declaration in current file, while placing the cursor on any variable or function in your program. g + ] : Goes to the definition of variable or function in different file, while placing the cursor on any variable or function in your program. The premise is that the system has installed ctags , and executed the comand ctags -R * (generated file tags ) in the project directory. By the way I installed software  universal-ctags on Ubuntu. g* : Search for the word under the cursor (like * , but g* on "rain" will find words like "rainbow").  g# : Same as g* but in backward direction. gg : Goes to the first line in the buffer (or provide a count before the command for a specific line). G : Goes to the last line (or provide a count before the c

Common Commands on Vim Insert Mode

Combination keys Ctrl + N : Complete with the content text of the current file currently being edited as the keyword.

Commonly Used for awk

awk mainly deals with data in the field of each row, and the default field separator is blank key or tab key. We can use last to retrieve the information of the login person, and the result is as follows(take out only the first 5 lines): $ last -n 5 jimmy      unix:0.0                        Tue Nov  9 12:41   still logged in jimmy      unix:0.0                        Tue Nov  9 11:54 - 12:40  (00:46) boot time                                  Tue Nov  9 11:52 shutdown time                              Tue Nov  9 01:15 jimmy      unix:0.0                        Mon Nov  8 22:46 - 01:15  (02:29) I want to retrieve the account number and the day of the week, and the account number and the day of the week are separated by tab key: $ last -n 5 | awk '{print $1 "\t" $3}' jimmy    Tue jimmy    Tue boot    Tue shutdown    Tue jimmy    Mon   The $0 in the first line represents the line " jimmy      unix:0.0                        Tue Nov  9 12:41   still logged in &qu

printf on sh or bash shell

 The content of  test.txt are as follows: Name     Chinese   English   Math    Average DmTsai        80        60     92      77.33 VBird         75        55     80      70.00 Ken           60        90     70      73.33 Example 1: The content of the file test.txt with data just above only lists names and grades: (separated by [tab]) printf '%s\t %s\t %s\t %s\t %s\t \n' $(cat test.txt) Example 2: After the second line in test.txt display as string, integer and decimal point respectively: printf '%10s %5i %5i %5i %8.2f \n' $(cat test.txt | grep -v Name) %10s : Represents a string field with a length of 10 characters. %5i : Represents a numeric field with a length of 5 characters. %8.2f : Represents a field with a decimal point with a length of 8 characters, where the decimal point has a width of 2 characters, the decimal point itself ( . ) occupies one place Example 3: List the characters represented by the hexadecimal value 45? printf '\x45\n'

Extended Regular Expressions Characters

 regular_express.txt   + : Repeat the previous RE character of one or more. Example : Search for "god" "good" "goood"... etc. strings.   egrep -n 'go+d' regular_express.txt     ? : Zero or one before the RE character. Example: Search for the two strings "gd" and "god". egrep -n 'go?d' --color=auto regular_express.txt   | : Find out several strings by OR. Example: Search for the two strings "gd" or "good". egrep -n 'gd|good' --color=auto regular_express.txt () :  Find group string. Example: Search for the two strings "glad" or "good", because "g" and "d" are duplicates, so I can list "la" and "oo" in () and separate them with |   egrep -n 'g(la|oo)d' --color=auto regular_express.txt ()+ :  Identification of multiple repeated groups. Example: I'm looking for a string that starts with "A" and ends with "C

regular express

"Open Source" is a good mechanism to develop programs. apple is my favorite food. Football game is not use feet only. this dress doesn't fit me. However, this dress is about $ 3183 dollars. GNU is free air not free beer. Her hair is very beauty. I can't finish the test. Oh! The soup taste good. motorcycle is cheap than car. This window is clear. the symbol '*' is represented as start. Oh!    My god! The gd software is a library for drafting programs. You are the best is mean you are the no. 1. The world <Happy> is the same with "glad". I like dog. google is the best tools for search keyword. goooooogle yes! go! go! Let's go. # I am VBird

Common Examples of Using gsed on FreeBSD

gsed [-nefir] [action] Options and parameters: -n :  Use silent mode. In general gsed usage, all data from STDIN will generally be listed on the screen. But if the -n parameter is added, only the line (or action) that has been specially processed by gsed will be listed . -e command :  Edit gsed actions directly in the command line mode. -f   command_file :  Write the gsed action directly in a file, -f command_file can execute the gsed action in command_file . -i   : Modify the content of the read file directly instead of outputting it on the screen. -r :  The action of gsed supports the grammar of extended formal expressions. (The default is basic regular expressions grammar) . Action description: [n1[,n2]]function   n1, n2   :  It doesn’t necessarily exist. It generally means "choose the number of lines to perform an action". For example, if my action needs to be performed between 10 and 20 lines, then "10,20[action behavior]".   The function has the follo

Regular Expressions Special Symbols

[:alnum:]   Represents English uppercase and lowercase letters and numbers, and 0-9, A-Z, a-z. [:alpha:]   Represents any English uppercase and lowercase letters, as well as A-Z, a-z. [:blank:]   Represents both the space key and the [Tab] key . [:cntrl:]   Represents the control keys on the keyboard, including CR, LF, Tab, Del... etc. [:digit:]   Represents only numbers, that is, 0-9 . [:graph:]   All keys except blank characters (space key and [Tab] key) . [:lower:]   Represents lowercase characters, i.e. a-z . [:print:]   Represents any character that can be printed. [:punct:]   Represents punctuation symbol, that is: "'?!;: # $... [:upper:]   Represents uppercase characters, which is A-Z. [:space:]   Any characters that will produce blanks, including blank keys, [Tab], CR, etc. [:xdigit:]   Represents a hexadecimal number type, so it includes: 0-9, A-F, a-f numbers and characters.

Commonly Used Regular Expressions

Search for a specific string Use dmesg to list the core information and then use grep to find out which line contains " tap" , and to color the captured keywords, and add the line number to indicate: dmesg -a | grep -n --color=auto 'tap' The first two lines and the last three lines of the line where the keyword is located are also captured and displayed: dmesg -a | grep -n -A3 -B2 --color=auto 'tap'   dmesg is a command on most Unix-like operating systems that prints the message buffer of the kernel. The output includes messages produced by the device drivers.   Suppose we want to get the specific string "abc" from the file just now, the easiest way is like this:   grep -n 'abc' regular_express.txt  -n   Show line number. I want to display the line where the string abc is a specific ignoring case: grep -in 'abc' regular_express.txt -i   Ignore case.   What we want is that the line does not have the string "abc" to be d

FreeBSD安装SCIM中文输入法(csh/tcsh)

1. 安装拼音 # pkg install zh-scim-pinyin 2. 安装五笔 # pkg install zh-scim-tables Install CJKUnifonts # pkg install zh-CJKUnifonts 3. 配置 ~/.cshrc % ee ~/.cshrc 加入下面两行: setenv XMODIFIERS @im=SCIM setenv LC_CTYPE zh_CN.UTF-8 4. 配置 ~/.xinitrc   % ee ~/.xinitrc 在确保执行xfce命令之前, 如下: exec scim -d & . /usr/local/etc/xdg/xfce4/xinitrc 5. 重启 # reboot

How to mount ntfs disk on FreeBSD

1.  Install fusefs-ntfs # pkg install fusefs-ntfs Add the following content to file /boot/loader.conf   fusefs_load="YES" 2. And then reboot. # reboot 3. Mount ntfs disk # ntfs-3g  /dev/da0s1 /media /dev/da0s1 : The ntfs disk. /media : Where your ntfs disk disk will be mounted.