Skip to content

Instantly share code, notes, and snippets.

View nobucshirai's full-sized avatar

Nobu C. Shirai nobucshirai

View GitHub Profile
@nobucshirai
nobucshirai / emrm.sh
Created October 8, 2013 10:53
A shell script for removing empty files.
#!/bin/bash
# $Id: emrm.sh,v 1.4 2012-10-13 09:13:03+09 shirai Exp $
# EMPTY REMOVE
list=(`ls`)
# MAIN
main(){
if [ $# = 0 ];then
@nobucshirai
nobucshirai / dls.sh
Created October 8, 2013 10:57
A wrapper script of ls command to show only directories
#!/bin/bash
# $Id: dls.sh,v 1.2 2013-10-03 13:43:21+09 shirai Exp $
dls(){
ls -F $@ | grep /
}
dls $@
@nobucshirai
nobucshirai / backer.sh
Last active May 8, 2021 06:55
A simple backup script.
#!/bin/bash
# AUTHOR
# 2013/10/08 Nobu C. Shirai
# 2018/10/06 Akira Hasegawa
description='
Creating backup files in the arguments in each backup directory.
The name of each backup file with backup directory is
"org_filename.dir/X_org_filename" where "X" is the index number
of backups which starts from 0.
@nobucshirai
nobucshirai / prefixer.sh
Last active December 24, 2015 23:49
A wrapper script of mv command to add a prefix to a file name.
#!/bin/bash
# $Id: prefixer.sh,v 1.1 2013-10-04 13:34:41+09 shirai Exp shirai $
ArgFile=$1
prefix=$2
main(){
check_args $@
mv -vi $ArgFile ${prefix}${ArgFile}
}
check_args(){
@nobucshirai
nobucshirai / suffixer.sh
Created October 8, 2013 11:07
A wrapper script of mv command to change an extension of a file.
#!/bin/bash
# $Id: suffixer.sh,v 1.1 2013-10-04 13:34:41+09 shirai Exp shirai $
ArgFile=$1
suffix=$2
main(){
check_args $@
mv -vi $ArgFile ${ArgFile%.*}.${suffix}
}
check_args(){
@nobucshirai
nobucshirai / dog
Created October 9, 2013 00:05
Shell has a "cat" command but it doesn't have "dog".
#!/bin/bash
# $Id: dog,v 1.2 2012-03-10 03:02:20+09 shirai Exp shirai $
printf "(\,..,/)\n"
printf "〈 c c 〉\n"
printf "(_,),.、)) \n"
for i in {1..6};do
printf "\033[1A\033[1A\033[1A\r"
if [[ $i = 1 ]];then
printf "(\,..,/)\n"
printf "〈 c c 〉\n"
@nobucshirai
nobucshirai / name_sedder.sh
Created October 9, 2013 01:02
"mv" command wrapper to change file name using "sed".
#!/bin/bash
#$Id: name_sedder.sh,v 1.1 2012-10-13 09:13:03+09 shirai Exp $
before="$1"
after="$2"
old_name=$3
main(){
check_args $@
new_name="`echo $old_name | sed "s/$before/$after/g" `"
@nobucshirai
nobucshirai / box_cp.sh
Last active December 26, 2015 12:29
A wapper script of cp. Copy files to temporary directory of current directory.
#!/bin/bash
# $Id: box_cp.sh,v 1.2 2013-10-25 21:30:26+09 shirai Exp shirai $
main(){
ArgCheck $@
BoxMaker
diae cp -av ${file_list[@]} ${box_dir}
}
ArgCheck(){
@nobucshirai
nobucshirai / Backdiffer.sh
Last active July 19, 2018 03:39
Check difference between a file in a current directory and its backup file in backup directory created by backer.sh.
#!/bin/bash
#$Id: Backdiffer.sh,v 1.3 2013-12-07 12:48:18+09 shirai Exp shirai $
Backdiffer(){
check_options $@
check_dir
counter=(`ls $BackDir | wc -w`)
DiffFile="${BackDir}/$((counter-1))_${ArgFile}"
CheckFile="$DiffFile"
while true
#!/bin/bash
#$Id: rewrite.sh,v 1.10 2014-01-08 14:09:47+09 shirai Exp $
rewrite(){
all=()
check_options $@
file="${all[$((${#all[@]}-1))]}"
file_check $file
tmp="TEMP_${file##*/}"
${all[@]} > $tmp