Bash script là những tập lệnh chạy trên Unix, Linux. Khi nào thì cần viết script
git pull mà một project có tới 20 cái repositories.Mới tìm hiểu nên cũng chỉ tìm hiểu ở mức cơ bản.
Một file bash script sẽ có đuôi là .sh. Ví dụ hello.sh
#!/usr/bin/env bash
NAME="Quach"
echo "Hello $NAME!"Và có quyền thực thi
$ sudo chmod u+x ./hello.shĐể thực thi hello.sh
$ ./hello.shMuốn dùng git pull cho tất cả thư mục thì viết script như thế nào.
Ý tưởng:
Thực hiện: Đặt tên file là pull_all.sh
for i in */; do
echo
date
echo "----git pull $i"
git -C $i pull
doneMuốn build một số projects thôi, không muốn build hết sẽ tốn thời gian mà không cần dùng tới.
#!/bin/bash
projects="projectA
projectB
projectC"
for i in $projects; do
date
echo "--------------------------------------------------------"
echo "----START build $i"
if [ -d $i ]; then
cd $i
mvn clean install -Dmaven.test.skip=true
cd ..
fi
doneMuốn xem những threads java đang chạy là những threads nào để mình kill nó
$ jps -vMuốn kill 1 threads thì làm sao
$ kill -9 12123Muốn xem những ports nào đang chạy
$ lsof -nP -iTCP:$PORT | grep LISTENCreate a Symbolic Link
$ ln -s /path/to/file /path/to/linkRemove Link
$ ls -l
$ unlink linkCheck running postgres
$ ps auxwww | grep postgresTham khảo:
Note 28-03-2020: