Scripting
How to find in Unix all the files, that are used by other applications? Here is find command:
find . -name "*" -exec /usr/sbin/fuser {} 2>&1 \; | grep ': *$'
HEX <-> DEC converting
awk split syntax
split(src_string,rez_array,[field_separator])
make filenames lowercase (awk+sh)
ls -1rt | awk '
{ printf("mv %s %s\n", $0, tolower($0)) | "sh" }
END { close("sh") }'
Print in color in Unix
function print_color {
local text=$1
local fg=$2
local bg=$3
case "$fg" in
red) fg="31m" ;;
green) fg="32m" ;;
yellow) fg="33m" ;;
blue) fg="34m" ;;
white) fg="37m" ;;
black) fg="30m" ;;
*) fg="37m" ;;
esac
case "$bg" in
red) bg="41m" ;;
green) bg="42m" ;;
yellow) bg="43m" ;;
blue) bg="44m" ;;
white) bg="47m" ;;
black) bg="40m" ;;
*) bg="40m" ;;
esac
echo -en "\033[${fg}\033[${bg}${text}\033[0m"
}
filedate utility
filedate is a tiny utility to display the file date.
You can download it here.
Usage: filedate.exe filename [format]
Format:
| d,dd,ddd,dddd | Day (1-31), (01-31),(Sun-Sat),(fullname) |
| m,mm,mmm,mmmm | Month (1-12), (01-12),(Jan-Dec),(fullname) |
| yy,yyyy | Year (99), (1999) |
| h,hh | Hour (0-23), (01-23) |
| n,nn | Minute(0-59), (01-59) (mm after hh also) |
| s,ss | Seconds(0-59), (01-59) |
reverse utility
rev is a nice small utility, that reverts every input line.
Example:
#: echo ABCD | rev
DCBA
The rev utility exists on Linux, but it is absent on some Unix machines.
So I wrote a simple C program for such systems.
I use it to display the comma-separated size of the files in ls output:
-rw-r--r-- file1 12,345,678
The complete expression is the following:
ll | rev | sed 's/\([0-9][0-9][0-9]\)/\1,/g' | rev | sed 's/\([^0-9]\),\([0-9]\)/\1\2/g;s/^,\([0-9]\)/\1/g'
|