Compress the contents of the current directory, but compress the smallest files first (handy when short of disk space for intermediate files):

ls -s | awk NR!=1 | sort -n | awk '{print $2}' | xargs bzip2 -9v

Use 7-Zip and tar together with standard input/output:

tar cf - (directory_path) | 7za a -si -mx=7 directory.tar.7z
7za x -so directory.tar.7z | tar xpf -

Find the largest file in a directory tree:

find /path -type f -exec ls -s {} \; | sort -n | tail -1

Print the number of regular files in each subdirectory of the current directory:

for x in *; do printf "%40s %g\n" $x $(find $x -type f -print | wc -l); done

Print the total bytes of files in a directory grouped by date (useful for Oracle archived log volume summaries):

ls -l|awk 'length($6)==3{x[$6" "$7]+=$5};END{for(i in x)printf"%s:\t%d\n",i,x[i]}'

Shell function to search the process table. Change -ef to aux below for the Berkeley form (better information) if your system supports it (on Solaris, look for /usr/ucb/ps). For example, "pfind ora_dbw" will search for all running Oracle database writer processes.

pfind(){ IFS='|';ps -ef|while read x;do [ -z "$y" ] && echo $x;y=1;case $x in *$1*)echo $x;;esac;done }

	or (Linux-specific version)

pfind() {
	IFS=\\
	unset qx qy
	if [[ -z "$COLUMNS" ]]
	then
		COLUMNS=80
	fi
	ps -eo user:7,pid:5,%cpu,%mem,args |
	while read qx
	do
		if [[ -z "$qy" ]]
		then
			echo $qx
			qy=1
		else
			case $qx in
				*$1*) echo ${qx:0:${COLUMNS}};;
			esac
		fi
	done
}

	or (gawk, using regex instead of sh pattterns)

pfind(){ ps aux | gawk -v p="$1" 'NR==1;$0~p&&$2!=PROCINFO["pid"]'; }

Burn a CD of the current directory on Linux without an intermediate ISO file (check size with "du -sm ." first; also check "cdrecord -scanbus" for the right device ID):

nice --18 mkisofs -r -T -J -V "Volume Label" . | cdrecord -v fs=6m speed=8 dev=ATA:1,1,0 -eject -

Convert cdparanoia-style tracks to cdda2wav (for cdrecord's useinfo):

x=1;while true;do f=$(printf "track%02g.cdda.wav" $x);[ ! -f $f ] && break;mv $f $(printf "audio_%02g.wav" $x);((x++));done

Burn a DVD with a volume label:

growisofs -Z /dev/cdrom -V "Volume Label" -r -J .

Burn a pre-existing ISO file with growisofs:

growisofs -dvd-compat -Z /dev/cdrom=file.iso

Send a message to a remote syslog (works in bash and ksh93 [most commonly /usr/dt/bin/dtksh] - ksh seems to need an IP address, not a hostname). The remote syslog might need to be running with the "-r" option:

 echo message to remote syslog >> /dev/udp/remote.syslog.host.com/514

Remove spaces from filenames in the current directory (use with caution; examine the output before you pipe to the shell).

ls|awk '{a=$0;gsub(/ /,"",a);print "mv '"'"'"$0"'"'"' "a}'|sh

Remove blank lines and comments (lines beginning with #).

awk '$1!~/(^#|^$)/' /path/to/file.txt

Show what ports are open on your Linux system, and what progams are listening on them:

netstat -ap --numeric-ports | awk '$(NF-1)=="LISTEN"'

Print out a list of all CVE numbers addressed by patches in your RPM database:

rpm -qa | while read x; do rpm -q "${x}" --changelog; done | awk 'BEGIN{IGNORECASE=1}; /cve-/ {i = $0; while(p = match(i, "cve-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]")){print toupper(substr(i, p, 13)); i = substr(i, p + 1)}}' | sort -u | tee vul.txt

Print all expiring accounts from /etc/shadow in a format similar to "chage -l":

gawk 'function dt(x) { return strftime("%b %d %Y", x * 86400 + 86400) }; BEGIN { FS=":"; OFS="\t"; while (getline < "/etc/shadow") if($5 != 99999) print $1, dt($3), dt($3 + $5), dt($3 + $5 + $7), $4, $5, $6 }'

Sort accounts by password expiration (read from /etc/shadow):

gawk 'BEGIN { FS=":"; OFS="\t"; while (getline < "/etc/shadow") if($5 != 99999) print (($3 + $5) * 86400 - systime())/86400, $1, strftime("%b %d %Y", ($3 + $5) * 86400 + 86400); }' | sort -n

Use gawk to generate a 20 byte alphanumeric stream suitable for a random password (does not include the letter "O" or the number "0" to avoid confusion; syntax also workable in DOS):

gawk "BEGIN{srand(systime()+PROCINFO[\"pid\"]);for(l=0;l<20;l++){t=rand()*((!!l)*10+24);t>14?t++:7;p=p (t>26?int(t-25):sprintf(\"%c\",65+t))}print p}"

Tell Oracle to let you see the time as well as the date:

alter session set nls_date_format = "RRRR/MM/DD HH24:MI"

How big is your Oracle database?

select v.name, d.mb from v$database v, (select sum(bytes)/1024/1024 mb from dba_data_files) d;

Show Oracle index size and key compression status:

select s.owner||'.'||s.index_name, s.bytes, i.compression,i.prefix_length from
  (select owner, index_name, compression, prefix_length from dba_indexes) i,
  (select owner, segment_name index_name, sum(bytes) bytes
    from dba_segments where segment_type='INDEX' group by owner, segment_name) s
where i.owner = s.owner and i.index_name = s.index_name
order by s.bytes;

Under a command prompt on Windows, find all files larger than 64 megabytes and print their size, date, and path delimited by semicolons (sorted by size). You can override the 64 megabyte threshold by specifying -v T=#BYTES (as shown in the second example):

dir /s /-c | \bin\gawk "BEGIN{T=(T?T:67108864)};{if($1==\"Directory\"&&$2==\"of\"){d=$0;gsub(/(^ Directory of |[\\]$)/,\"\",d)};if($3~/^(AM|PM)$/&&$4~/^[0-9]+$/&&$4>T){m=substr($0,1,20);gsub(/[ ]+/,\" \",m);f=substr($0,40);gsub(/\r/,\"\",f);f=d\"\\\\\"f;s[f]=$4+0;t[f]=m;k[$4]=1}};END{for(i in k)l[j++]=i+0;u=asort(l);OFS=\";\";for(i=1;i<u;i++)for(j in s)if(l[i]==s[j])print s[j],t[j],j}"
dir /s /-c | \bin\gawk -v T=40000000 "BEGIN{T=(T?T:67108864)};{if($1==\"Directory\"&&$2==\"of\"){d=$0;gsub(/(^ Directory of |[\\]$)/,\"\",d)};if($3~/^(AM|PM)$/&&$4~/^[0-9]+$/&&$4>T){m=substr($0,1,20);gsub(/[ ]+/,\" \",m);f=substr($0,40);gsub(/\r/,\"\",f);f=d\"\\\\\"f;s[f]=$4+0;t[f]=m;k[$4]=1}};END{for(i in k)l[j++]=i+0;u=asort(l);OFS=\";\";for(i=1;i<u;i++)for(j in s)if(l[i]==s[j])print s[j],t[j],j}"