Awesome but commonly unknown Linux Commands
anchor.com.au
anchor.com.au
notify-success:
notify-send --icon=gtk-dialog-info Success! "$*"
notify-failure: notify-send --icon=gtk-dialog-warning Failure! "$*"
When I want to run a long-running command and don't want to have to keep checking on it, I'll do something like this: make -j3 && notify-success "Build complete" || notify-failure "Build failed"Use "--expire-time" argument to "notify-send" to control how long the message is displayed.
My terminal (urxvt) will detect the bell and set the 'urgent' flag on the window, which is detected by Awesome, which sets the appropriate tag* icon to red.
* Tag in Awesome is more or less akin to a virtual desktop.
growlnotify -m "Hey I am done!" -t "Done!" growlnotify -s -t 'Done!' -m 'And I'm not going away until you click me' make -j3 >make.log 2>&1 ; echo $?
When make finishes, your prompt is printed again (activity!) and the window's caption is highlighted. I use the same mechanism to watch for new mail and chats in other windows. It's like Growl for your terminal. make && say "I'm done."http://www.commandlinefu.com/commands/browse
you can sort by date, #(votes) and also search
The top all-time popular one is:
* run last command as root: $ sudo !!
http://www.catonmat.net/blog/top-ten-one-liners-from-command...
$ pwd
/Users/me/Sites/foo
$ pushd .
$ cd /
$ pwd
/
$ popd
$ pwd
/Users/me/Sites/foo
Or in English: If you're in a directory that you need to leave but you know you'll go back there in a minute, use "pushd ." to save that directory. Then go off and do whatever you need to, and when you need to return to the saved directory, use "popd" to take you straight back there.
[testfunc(x) for x in testlist]
<successful result>
success = _
print _
<successful result>
It's useful when using the interpreter as a calculator, or when you're bashing out some calculation you can never remember how to do properly. >> "foo"
=> "foo"
>> bar = _
=> "foo"
>> bar
=> "foo" $ pwd
/home/foo
$ mkdir -p bar/baz/qux && cd $_
$ pwd
/home/foo/bar/baz/qux$ pwd
/some/long/compli/cated/v1.0.7/path/to/_stuff
$ cd /simple/
$ do -stuff
$ cd ./foo
$ do -stuff
$ rem now let's get back to that complicated directory again
$ cd -
oh, wait, I cd'ed twice, shit
For interactive use zsh has an option called autopushd that automatically pushes directories you `cd` to. I never remember to use pushd so it's a nice convenience.
for i in foo bar baz; do
cd $i;
#... do something
cd ..;
done;
if "bar" doesn't exist, your cd .. will throw you off your original directory, whereas for i in foo bar baz; do
pushd $i;
#... do something
popd;
done;
you'll be guaranteed that after "popd" you're back in the right place to start a new iteration. $ pushd .
$ cd /
Why not just $ pushd /
?Also, it's not linux-specific, but bash-specific.
c:\> pushd \\server\share
z:\> $ pushd /
oh, neat. Thanks.If you set CDPATH to '.:~/dev/python', you can easily jump to your project just by doing cd my_awesome_project, it doesn't matter where you actually are in your FS!
I use it heavily with cd -, you should give it a try!
But a few months ago found this.
also, in developer > applications there is an app called 'Instruments' which is an excellent GUI front-end to DTrace
For many of the systems applications I design for Illumos, I've used DTrace probes as a way of logging very frequent events, on demand (to avoid frequent IO). All of the events that _must_ be logged for the application to function properly, are logged and fsync'd.
I think that in most systems dynamic tracing will eventually replace a significant portion of the logging functionality that people code into their applications.
Either way, if you think strace is sweet, give DTrace a spin.
Some helpful links:
[0] A video demostration of DTrace, by the creator of DTrace.
[0] http://www.youtube.com/watch?v=6chLw2aodYQ
[1] A post I wrote, demonstrating DTrace. Similar posts can be found on the blog's dtrace-addict page.
[1] http://nickziv.wordpress.com/2011/04/08/adventures-of-a-dtra...
[2] A wiki that contains DTrace examples for various languages and system facilities. Some examples may be Illumos-centric.
[2] http://www.solarisinternals.com/wiki/index.php/DTrace_Topics
[3] DTrace's home. Contains blogs by the engineers behind DTrace.
UPDATE: Meant to reply to parent's parent.
On one system, I couldn't even invoke kernel functions.
On another system, the kernel panicked as soon as I executed `stap -e ...`.
Basically unusable, at this point.
I hope it improves because developers on linux could really benefit from dynamic tracing.
I've debugged stalled processes across 3 separate servers with these three tools alone.
# watch packet counters
watch ifconfig
# watch tcp connections
watch netstat -plan
# watch the load average
watch uptime
# watch directory contents
watch ls -lSpeaking of which, many people don't know about the 'moreutils' utils. Check them out ;)
vidir sounds very useful to me.
Seriously though - everyone knows this. Just use a temp file.
He says sponge "keeps the results in memory" - that's a problem if the file is huge.
Plus there are other tools to do in-place replacement.
Wrote about it (use case + example) here: http://www.chocobrain.com/Advanced-terminal-automation-with-...
That's very straightforward, and gets the job done without much weirdness.
find . -exec sem --id my_find -j3 sleep 4\; echo {} \;
See more about sem: http://www.gnu.org/software/parallel/sem.htmlhttp://stackoverflow.com/questions/896808/find-exec-cmd-vs-x... http://www.gnu.org/software/findutils/manual/html_node/find_...
xargs is "better" in that it spawns 1 new process for however many things are found. -exec spawns 1 new process for EVERY thing found.
So:
find . -name '*.log' -exec rm {} \;
spawns an rm for every log file. find . -name '*.log' -print0 | xargs -0 rm
spawns 1 rm for MANY log files. (Yes, I know zsh can do stuff like this too.)xargs also has options to limit command line length or # of items if you want to limit that. find -exec is about the same then as find ... | xargs -n1
I was sitting there and noticed with my iStat monitor that I was uploading something at 250 KB/sec. I closed Chrome and eventually all running programs in the doc, yet it still continued.
I tried to find out WHAT was uploading that, but to no avail. Any suggestions for tools? I ended up trying iftop, lsof -i, and netstat to get a glimpse, but it stopped before I could get to the bottom of it.
lsof -i- screen for accessing servers
- lshw for seeing Linux server hardware config
- cfengine for automating my system administration
- atop as an advanced top
http://www.atoptool.nl/downloadatop.php
atop uses color to show when a subsystem goes over warn/critical threshold. it can be run in present time, or can be used to go back in time and "play back the tape".
echo my_script.py | at 4am tomorrow
then list queued jobs with atq
note: its not enabled by default on mac os x, see man atrunhttp://www.huyng.com/bashmarks-directory-bookmarks-for-the-s...
rename 's/\.bak$//' *.baksimilarly: killall -u USERNAME
OFWGKTA
nuff said.