For example, to display the 20 largest files owned by joe:
find / -printf "%k\t%p\n" -user joe | sort -n | tail -20
commandsfilesfindpermissionsprintfsorttailusers
You can use this command to show duplicate lines in a file:
$ uniq -d MYFILE
commandsduplicatesfiltershellsortuniq
You have a mailbox you need to sort. You can't have it come back through your MTA, of course. Use this script to push it through the procmail filter of your choice:
#!/bin/sh ORGMAIL=/var/spool/mail/$LOGNAME if cd $HOME && test -s $ORGMAIL && lockfile -r0 -l3600 .newmail.lock 2>/dev/null then trap "rm -f .newmail.lock" 1 2 3 15 umask 077 lockfile -l3600 -ml cat $ORGMAIL >>.newmail && cat /dev/null >$ORGMAIL lockfile -mu formail -s procmail <.newmail && rm -f .newmail rm -f .newmail.lock fi exit 0
commandsmailboxmtaprocmailscriptsshellsort
You have an array of IP addresses but are only interested in the unique values. Since perl doesn't have a unique() function, we'll exploit the concept of unique keys in hashes:
#!/usr/bin/perl
my @ipAddresses = ('192.168.0.1', '192.168.0.27',
'192.168.0.1', '192.168.0.3');
print "Before: ", qq(@ipAddresses), "\n";
undef %saw;
@saw{@ipAddresses} = ();
@sorted = sort keys %saw;
print "After : ", qq(@sorted), "\n";
Resulting in:
Before: 192.168.0.1 192.168.0.27 192.168.0.1 192.168.0.3 After : 192.168.0.1 192.168.0.3 192.168.0.27
perlsortunique
If you have a bunch of files in your home directory and you want to push them into ~/sort, create the directory and then do the following:
$ find . -type f -maxdepth 1 ! -name ".?*" | xargs -I '{}' mv '{}' sort
Note: GNU xargs uses -i. BSD versions use -I.
bsdcommandsdirectoryfindgnushellsortxargs