0% found this document useful (0 votes)
35 views2 pages

To See The Output in A Different Format

Learn unix commands. UNIX commands can often be grouped together to make even more powerful commands with capabilities known as I/O redirection

Uploaded by

Bimal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

To See The Output in A Different Format

Learn unix commands. UNIX commands can often be grouped together to make even more powerful commands with capabilities known as I/O redirection

Uploaded by

Bimal Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

To see the output in a different format:

date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"


DATE: 2009-03-07
TIME: 07:27:43
2.

To see the last Friday of the month:

date -v1d -v+1m -v-1d -v-fri


Fri Mar 27 07:29:28 SAST 2009

3. To display the current UNIX Timestamp:


date +%s
1236403850

4. Searching for files over 30 days old in current directory


find $PWD -type f -mtime +30 -print|grep -Ev "$PWD/.*/"
find $DIR -type f -atime +30 print
find . -mtime +30 \( ! -name . -prune \)
find -maxdepth 1
find . -type d -name .svn -prune -false -o -type f

5. Delete 30 days old file


#!/bin/sh
i="/pat/to/dir/you/wanna/check/"
msg () {
for i
do echo "clearing: $i" >&2
done
}
fatal () { msg "$@"; exit 1; }
if [ ! -d "$i" ]
then msg "no directory: $i"
elif [ ! -r "$i" -o ! -w "$i" ]
then msg "access denied (no rw- access): $i"
else
# search & destroy

find "$i" ! -type d -mtime +30d -print | xargs rm -f > /dev/null 2>&1
[ -d "$i" ] || continue
(cd $i || continue
for d in *
do
[ -d "$d" ] || continue
find . -depth -type d -mtime +30d -print |
xargs rmdir > /dev/null 2>&1
done
)
fi
exit 0

This works for me to delete files 30 days old from directory $i in depth

You might also like