Posts

Showing posts from 2021

tr command line tutorial

 https://www.tecmint.com/tr-command-examples-in-linux/ tr means translate It will walk through all the characters in the text and can translate a character or a phrase into a new character or a new phrase. For example: nguyenhuybo@VN-LV00184-N ~ % echo "Hello my love" | tr "[:lower:]" "[:upper:]" HELLO MY LOVE nguyenhuybo@VN-LV00184-N ~ % echo "{**} <3 me"| tr "{}" '[]' [**] <3 me nguyenhuybo@VN-LV00184-N ~ % echo I am sorry| tr "[:space:]" "\t" I am sorry %    

Multi stage builder with gradle

FROM  gradle:jdk11  AS  cache WORKDIR / app ENV GRADLE_USER_HOME / cache COPY build.gradle gradle.properties settings.gradle . / RUN gradle -- no-daemon build -- stacktrace FROM gradle:jdk11 AS builder WORKDIR / app COPY -- from= cache / cache / home / gradle / .gradle COPY . / app / RUN gradle -- no-daemon build -- stacktrace FROM harbor.hub.com / -project / openjdk: 11.0.12 - jre-slim RUN apt-get install - y tzdata # timezone env with default ENV TZ Asia / Tokyo RUN ln - snf / usr / share / zoneinfo / $ TZ / etc / localtime && echo $ TZ > / etc / timezone #COPY ./app/iims/build/libs/iims-1.0-SNAPSHOT.jar /app/ COPY -- from= builder / app / app / iims / build / libs / xxx-1 .0 - SNAPSHOT.jar / app / WORKDIR / app ENTRYPOINT [ "java" , "-jar" , "xxx-1.0-SNAPSHOT.jar" ]

Best application for MACOS

 https://starship.rs/ https://www.raycast.com/ https://superuser.com/questions/400360/syntax-highlighting-in-terminal-mac-os-x

shell script demo

  nguyenhuybo@VN-LV00184-N Downloads % cat call_api.sh   #!/bin/bash n=$1 echo $2 send_omikuji(){     echo "starting new call api: omikuji"     curl -X 'POST' 'https://talkfortune-notification-hook.line-apps-beta.com/callback' -H 'connection: close' -H 'user-agent: LineBotWebhook/2.0' -H 'content-length: 315' -H 'content-type: application/json; charset=utf-8' -H 'x-line-signature: plpngha8sEj7LJe6xd/6InfKBWQ32kso2SOaAQKL01o=' -H 'host: talkfortune-notification-hook.line-apps-beta.com' -d $'{"destination":"u367dfc1ff8ed00c67a5966f542e5c25e","events":[{"type":"message","message":{"type":"text","id":"379186645792718849","text":"おみくじ"},"timestamp":1638844157276,"source":{"type":"user","userId":"uf4167f77e339b332dd154eb8ead96191"},"...

cut command line

 https://www.geeksforgeeks.org/cut-command-linux-examples/?ref=lbp

tr command line

  1. How to convert lower case to upper case To convert from lower case to upper case the predefined sets in tr can be used. $cat greekfile Output: WELCOME TO GeeksforGeeks $cat greekfile | tr “[a-z]” “[A-Z]” Output: WELCOME TO GEEKSFORGEEKS or $cat geekfile | tr “[:lower:]” “[:upper:]” Output: WELCOME TO GEEKSFORGEEKS 2. How to translate white-space to tabs The following command will translate all the white-space to tabs $ echo "Welcome To GeeksforGeeks" | tr [:space:] '\t' Output: Welcome To GeeksforGeeks 3. How to translate braces into parenthesis You can also translate from and to a file. In this example we will translate braces in a file with parenthesis. $cat greekfile Output: {WELCOME TO} GeeksforGeeks $ tr '{}' '()' newfile.txt Output: (WELCOME TO) GeeksforGeeks

jobs, kill

  23. jobs command jobs  command will display all current jobs along with their statuses. A job is basically a process that is started by the shell. 24. kill command

locate, find, and grep

  11. locate command You can use this command to  locate  a file, just like the search command in Windows. What’s more, using the  -i  argument along with this command will make it case-insensitive, so you can search for a file even if you don’t remember its exact name. To search for a file that contains two or more words, use an asterisk  (*) . For example,  locate -i school*note  command will search for any file that contains the word “school” and “note”, whether it is uppercase or lowercase. 12. find command Similar to the  locate  command, using  find  also searches for files and directories. The difference is, you use the  find  command to locate files within a given directory. As an example, find  /home/ -name notes.txt  command will search for a file called  notes.txt  within the home directory and its subdirectories. Other variations when using the  find  are: To find files in the...

awk

  $ awk –F'[ :\t]' '{print $1, $2, $3}' people.txt ---------------------------- $ awk '{print NR, $1, $2, $4}' people.txt The output will be: 1 Bill Thomas 08/9/1968 2 Fred Martin 22/7/1982 3 Julie Moore 25/2/1978 4 Marie Jones 05/8/1972 5 Tom Walker 14/1/1977 ---------------------------- $ cat people.txt | awk '$3 > 6500 {print $1, $2}' ------------- Bill Thomas 8000 08/9/1968 Fred Martin 6500 22/7/1982 Julie Moore 4500 25/2/1978 Marie Jones 6000 05/8/1972 Tom Walker 7000 14/1/1977 $ awk '{ if ($3 > 7000) { print "person with salary more than 7000 is \n", $1, " " , $2;} }' people.txt The output is as follows: person with salary more than 7000 is Bill Thomas =========================== An example of the awk command with the for loop is as follows: $ awk '{ for( i = 1; i <= NF; i++) print NF, $i }' people.txt...

Command line arguments

  $0 Shell script name or command $1–$9 Positional parameters 1–9 ${10} Positional parameter 10 $# Total number of parameters $* Evaluates to all the positional parameters $@ Same as $*, except when double quoted "$*" Displays all parameters as "$1 $2 $3", and so on "$@" Displays all parameters as "$1" "$2" "$3", and so on 

aggreate data in mongodb

db.targetUsers.aggregate([ { "$sort" : { "userId" : 1 } } , { "$group" : { "_id" : "$mid" , "mid" : { "$first" : "$mid" } , "userId" : { "$first" : "$userId" } , "gender" : { "$first" : "$gender" } , "paidTime" : { "$first" : "$paidTime" } , "isFollowing" : { "$first" : "$isFollowing" } , "updatedAt" : { "$first" : "$updatedAt" } } } , { "$match" : { "userId" : { "$gte" : 2098 , "$lte" : 2110 } } } ])

Understanding chmod and chown in Linux with a Real-World Analogy

In Linux, the commands chmod and chown are used to manage file permissions and ownership. To help understand how these work, let's use an analogy with a house . chmod (Change Mode) - Setting Permissions for the House Imagine you have a house (which represents a file) and you want to decide how different groups of people can interact with it. chmod is used to set those rules. R (Read) : Group 1 can look at the house, see its contents, and understand what's inside. This is equivalent to the read permission. W (Write) : Group 2 can buy and move items into the house, arrange the furniture , and decorate the house. They can also delete items. This corresponds to the write permission. X (Execute) : Group 3 can use the house itself, meaning they can enter and interact with the environment in the house (e.g., open doors, use utilities). This represents the execute permission. There are three main groups for setting permissions: User (u) : The owner of the house (file). Gr...

Install Vagrant and VirtualBox

Virtual box để tạo máy ảo Ubuntu hoặc Debian hoặc Centos Vagrant dùng để làm công cụ kết nối ssh và testing

Useful Ansible commands

Help: [#> ansible --help] Version: [#> ansible --version] #> ansible --version ansible 2.0.0.2 config file = /etc/ansible/ansble.cfg configured module search path = Default w/o overrides Check: [#> ansible foo.yml --check] Inventory: [#> ansible -i 192.x.x.x, x.x.x.x] ListHosts: [#> ansible -list-hosts] OneLine: [#> ansible –-one-line] SyntaxCheck: [#> ansible –-syntax-check] TimeOut: [#> ansible –timeout=X] Verbose: [#> ansible –verbose] Example: Run an ad hoc command against an Ansible inventory group and limit the execution of a playbook to a max of 5 simultaneous servers: $ ansible europe -a "whoami" -f 5 Example: Execute a playbook against the Europe group as a privileged account (different from the SSH account $ ansible europe -a "/usr/bin/foo" -u username --become [ --ask-become-pass ] Example: Transfer a local (on the ansible control server) file to a set of remote hosts simultaneously $ ansible europe -m copy -a "src=/op...

How to install Ansible

https://www.snel.com/support/how-to-install-ansible-on-centos-7/ Install Ansible on Ubuntu $ sudo apt-get install software-properties-common $ sudo apt-add-repository ppa:ansible/ansible $ sudo apt-get update $ sudo apt-get install ansible Install Ansible on Centos # NOTE: Before installing Ansible you may need to install the epel-release repo # for RHEL or # Scientific Linux. Additional details on how to install EPEL can be found at # http://fedoraproject.org/wiki/EPEL $ sudo yum install ansible For Gentoo Linux users, installing Ansible can be accomplished fairly easily. The following command-line syntax can be leveraged to accomplish the installation: # The first command is optional, you may need to unmask the Ansible package prior to running emerge: $ echo 'app-admin/ansible' >> /etc/portage/package.accept_keywords $ emerge -av app-admin/ansible PKG for FreeBSD FreeBSD-specific users can use  pkg install  to install the Ansible control server solution and get Ansible...

Upload file to S3

 gradle implementation 'com.amazonaws:aws-java-sdk:1.11.163' import java.io.File ; import org.springframework.beans.factory.annotation. Value ; import org.springframework.context.annotation. Bean ; import org.springframework.context.annotation. Configuration ; import com.amazonaws.ClientConfiguration ; import com.amazonaws.Protocol ; import com.amazonaws.auth.AWSCredentials ; import com.amazonaws.auth.AWSStaticCredentialsProvider ; import com.amazonaws.auth.BasicAWSCredentials ; import com.amazonaws.client.builder.AwsClientBuilder ; import com.amazonaws.regions.Regions ; import com.amazonaws.services.s3.AmazonS3 ; import com.amazonaws.services.s3.AmazonS3ClientBuilder ; @Configuration public class Config { @Bean public AmazonS3 s3 () { AWSCredentials credentials = new BasicAWSCredentials( "xxxd20f819xxxxxxxxx2fa6268edxxx" , "yyyyy8e369zzzzzzzzz2b2f52tttttt" ) ; ClientConfiguration clientConfig ...