Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged solaris from sorted by
Terminal - Commands tagged solaris - 24 results
find /some/directory/* -prune -type f -name *.log
2014-05-02 00:14:32
User: bigstupid
Functions: find
0

This find syntax seems a little easier to remember for me when I have to use -prune on AIX's find. It works with gnu find, too.

Add whatever other find options after -prune

wget -qO - http://www.asciiartfarts.com/random.cgi | sed -n '/<pre>/,/<\/pre>/p' | sed -n '/<table*/,/<\/table>/p' | sed '1d' | sed '$d' | recode html..ascii
pflags core.12462 | grep "core "
find . -type f -exec awk '/linux/ { printf "%s %s: %s\n",FILENAME,NR,$0; }' {} \;
truss date 2>&1 | awk '/^time/{print $3}'
perl -e 'foreach (@ARGV) {@T=stat($_); print localtime($T[8])." - ".$_."\n"}'
perl -e '@F = `ls -1`;while (<@F>){@T = stat($_);print "$_ = " . localtime($T[8]) . "\n";}'
2010-05-20 15:02:51
User: hckhckhck
Functions: perl
0

Solaris 'ls' command does not have a nice '--full-time' arg to make the time show after a year has passed. So I spit this out quick. It hates spaces in file names.

utime(){ python -c "import time; print(time.strftime('%a %b %d %H:%M:%S %Y', time.localtime($1)))"; }
utime(){ awk -v d=$1 'BEGIN{print strftime("%a %b %d %H:%M:%S %Y", d)}'; }
utime(){ date -d "1970-01-01 GMT $1 seconds"; }
utime { date -d @$1; }
2010-05-12 12:21:15
User: deltaray
Functions: date
4

More recent versions of the date command finally have the ability to decode the unix epoch time into a human readable date. This function makes it simple to utilize this feature quickly.

utime(){ perl -e "print localtime($1).\"\n\"";}
2009-11-06 12:58:10
User: MoHaG
Functions: perl
1

A shell function using perl to easily convert Unix-time to text.

Put in in your ~/.bashrc or equivalent.

Tested on Linux / Solaris Bourne, bash and zsh. using perl 5.6 and higher.

(Does not require GNU date like some other commands)

lucreate -n be1 [-c be0] -p zpool1
find . \( ! -name . -prune \) \( -type f -o -type l \)
2009-09-12 15:58:56
User: mobidyc
Functions: find
1

you must be in the directory to analyse

report all files and links in the currect directory, not recursively.

this find command ahs been tested on hp-ux/linux/aix/solaris.

fuser -k `who -u | awk '$6 == "old" { print "/dev/"$2'}`
2009-09-07 03:36:43
User: lbonanomi
Functions: awk fuser
Tags: Linux solaris
2

Shell timeout variables (TMOUT) can be very liberal about what is classified as 'activity', like having an editor open. This command string will terminate the login shell for an user with more than a day's idle time.

perl -e 'print scalar(gmtime(1234567890)), "\n"'
echo "0t${currentEpoch}=Y" | /usr/bin/adb
2009-08-25 12:17:01
User: verboEse
Functions: echo
0

this works on Solaris, so not better than the "only-GNU"-tool :-(

I think, there is no one-liner for this, that will work on all *nix-es

/usr/proc/bin/pfiles $PID | egrep "sockname|port"
pkgchk -l -p <full path to the file>
2009-07-04 08:22:11
User: sengork
Tags: solaris
0

Find which package a file belongs to on Solaris along with it's packaging system metadata.

more /var/adm/messages
2009-05-29 12:10:18
User: miccaman
Functions: more
Tags: solaris
-10

read system logs of sun solaris 9

init 6
2009-05-29 07:44:05
User: miccaman
Functions: init
Tags: solaris Reboot
-11

init states on solaris are numbered

init 0 boot with prompt

init 5 shutdown

init 6 reboot

vmstat 1 10 | /usr/xpg4/bin/awk -f ph-vmstat.awk
2009-05-04 04:55:00
User: MarcoN
Functions: vmstat
5

% cat ph-vmstat.awk

# Return human readable numbers

function hrnum(a) {

b = a ;

if (a > 1000000) { b = sprintf("%2.2fM", a/1000000) ; }

else if (a > 1000) { b = sprintf("%2.2fK", a/1000) ; }

return(b) ;

}

# Return human readable storage

function hrstorage(a) {

b = a ;

if (a > 1024000) { b = sprintf("%2.2fG", a/1024/1024) ; }

else if (a > 1024) { b = sprintf("%2.2fM", a/1024) ; }

return(b) ;

}

OFS=" " ;

$1 !~ /[0-9].*/ {print}

$1 ~ /[0-9].*/ {

$4 = hrstorage($4) ;

$5 = hrstorage($5) ;

$9 = hrnum($9) ;

$10 = hrnum($10) ;

$17 = hrnum($17) ;

$18 = hrnum($18) ;

$19 = hrnum($19) ;

print ;

}

lockstat -I -i 977 -s 30 -h sleep 1 > /tmp/profile.out
2009-03-13 13:17:53
User: garylittle
Functions: sleep
2

Lockstat will sample the kernel 977 times per second, and print out the functions that it sees executing on the CPU during the sample. The -s 10 switch tells lockstsat to not only print that function, but also show the call stack (up to 10 deep).

ifconfig -a | nawk 'BEGIN {FS=" "}{RS="\n"}{ if($1~ /:/) {printf "%s ", $1}}{ if($1=="inet") {print " -- ",system("arp "$2)}}'|egrep -v "^[0-9]$"
2009-03-02 23:15:13
User: leprasmurf
Functions: ifconfig
1

Needed to get the Mac of various devices on a solaris box, but didn't have root. This command used awk to display the Network device, the IP, and the MAC a line at a time.