2016年5月12日 星期四

Linux - crontab with date

問題

在 cron 中加入一筆定時移除七天前檔案的指令,檔案名稱格式為 20160505-xxxxxxx.tar.gz,
* 3 * * * rm -f /path/`date "+%Y%m%d" --date="-7 day"`-*
但發現 cron 並沒有完成執行。


解決方法

把 cron 指令換成
* 3 * * * rm -f /path/`date "+\%Y\%m\%d" --date="-7 day"`-*

參考資料

2016年1月4日 星期一

Git - tag 標籤

查看標籤
$ git tag


新增標籤
$ git tag -a NEW_TAG -m "MESSAGE"


上傳標籤
$ git push origin NEW_TAG


上傳所有標籤
$ git push origin --tags


刪除標籤
$git tag -d OLD_TAG


刪除遠端標籤
$ git push --delete origin OLD_TAG

2015年11月18日 星期三

Git - 儲存帳號密碼

作業系統:Windows

事件狀況:使用 Git 指令,登入伺服器需要輸入帳號密碼,如果遇到很多 submodule 時,動作更是繁瑣。

解決辦法:
  1. 設定環境變數 HOME。
    $setx HOME %USERPROFILE%
  2. 在家目錄下新增 _netrc 檔案。
    machine hostname1
    login login1
    password password1
    machine hostname2
    login login2
    password password2

2015年11月1日 星期日

Linux - 使用 grep 搜尋檔案內容

尋找單一檔案中的特定字串

 grep -n "keyword" /directory/file

尋找資料夾中含有特定字串的檔案

 grep -rl "keyword" /directory/*

尋找資料夾中含有特定字串的檔案,並標明字串位置

grep -rn "keyword" /directory/*

2015年10月2日 星期五

2015年9月25日 星期五

Git - 重新命名 branch

重新命名
$git branch -m OLD_NAME NEW_NAME

上傳新名稱 branch 到遠端
$git push origin NEW_NAME:NEW_NAME

刪除遠端的舊名稱 branch
$git push origin --delete OLD_NAME

2015年9月24日 星期四

Git - 同步 github 到 gitlab

下載 repository 到本地端
$git clone https://github.com/username/repo-name.git
進入 repository 目錄
$cd repo-name
增加遠端 repository
$git remote add gitlab https://gitlab.com/username/repo-name.git
上傳 commit
$git push -f --tags refs/heads/*:refs/heads/*