Essential UNIX Tricks and Tools?
Chris Lesner asks: "What handy UNIX tricks/tools do you use everyday? I'm asking for stuff that amazes your friends and makes you wonder how they use UNIX w/o them.
Some simple examples include: job control (with fg, bg/&, jobs, Ctrl-Z); moving login sessions between machines with Screen for vt100 and VNC for X11 and using screen and VNC to share login session b/w users for demos etc.; using find, xargs -i and
echo to build command strings which after
inspection can be piped back though bash e.g.
`find . -type f | xargs -i{} echo "cp {} {}.bak" | bash` I'm asking b/c my source for this kind of information has dried up as my UNIX skills have matured. I'm guessing other Slashdot readers have the same problem. By the way, if you think the examples I give are lame I challenge you to better them!"
All the tricks you can cram into one of those big books, and more: Unix Power Tools -- O'Reilly's best book, IMHO.
-- Ken Kinder ken@_nospam_kenkinder.com http://kenkinder.com/
In my .bashrc:
In my-- Ken Kinder ken@_nospam_kenkinder.com http://kenkinder.com/
It's 10 PM. Do you know if you're un-American?
A lot of people don't know about the "watch" command
/dev/hda
:p
watch -n1 df -h
I always use hdparm to speed up IDE drives too.
hdparm -c1 -d1 -A1 -a16 -m16 -u1 -S240 -W1 -k1 -K1 -X66
Of course there's aliases you can set to reduce keystrokes.
alias ll='ls -l'
pgrep and killall can be pretty useful.
killall java
renice 19 `pgrep java`
I also have a button on my GNOME panel that runs xkill so I can click on a locked up GUI app and terminate it.
If you have a multiprocessor box, you can do "make -j3" to run parallel builds.
And updatedb and locate are really useful for finding files quickly.
If you're trying to remember a command you've run before you can run this to find it quickly.
history | grep 'command'
They you can run !850 to run command #850 from your history for example.
And you can run this to find GNOME packages.
rpm -qa | grep gnome
That's all I can think of for now. Other posters are welcome to point out faster ways to do any of the tips I've given.
The biggest single command which saves me time is 'cd -' which changes to your previous directory under bash.
It doesn't sound terribly useful, but it is... Take my word for it.
An easier way (and not needing xterms) would have been to use script:
...
...
$ script
Script started, output file is typescript
$ telnet remotehost
remotehost $ cat filename
remotehost $ exit
$ exit
Script done, output file is typescript
$
Of course, instead of cat, use uuencode for a binary file...
Instead of
$ ps aux | grep foo | grep -v grep
use
$ ps aux | grep [f]oo
The brackets will show up in the ps output but don't match your pattern, so your grep is automaticly excluded from your final output.
I consider this pretty basic, but I remember some junior coworkers blown away by
<tt>something | sort | uniq -c | sort -rn</tt>
On the coding level, I constantly use the regex library (with extended regular expressions) and profiling. There are a lot of places where a single well-designed RE can eliminate many lines of code, and profiling can help you ensure that you close all files you open, free all memory you malloc, etc.
For every complex problem there is an answer that is clear, simple, and wrong. -- H L Mencken
Two biggies for me are 2>a to send errors to a file named "a". And strace, when you really need to know what a prgram is doing.
/dev/. The list goes on.
I couldn't live without strace. I had a font problem with X, strace told me where the problem was. xine wasn't playing sound, strace showed be that it was hitting the wrong entry in
For Debian users, apt-spy (requires installation of the package) to find fast sites for package downloads, and apt-listchanges to list what all the changes are.
To wow silly Windows users, eject and aafire (part of aalib).
Have you read my journal today?
your python script may crap out due to the stdin stream disappearing (i know nohup redirects stdout and stderr, but i don't think it redirects stdin)
/dev/null &
you might try nohup python myscript.py
Need a Catering Connection
One of the first things I install on a new system is always xtail.
It has nothing to do with X Windows.
It works just like 'tail -f' but it can watch multiple files. You can even watch whole directories and it will notice when new files are created.
http://www.unicom.com/sw/xtail/
Very handy tool.
After hacking around on *nix for years, everything in that book was old news to me. Well, almost everything. Out of 1000+ pages, here's the only trick I had never seen before:
If you have a directory full of files that are precious to you, run "touch ./-i" in that directory. This creates an empty file named "-i". Why do this? Because:
If you accidentally "rm *" there, the shell's default collating order while expanding the * will put the "-i" file first in the list, which will then be interpreted by rm as the interactive option, rather than a file.
(I've never used this trick, but I can see how it would be much less hassle than trying to remember to chmod u-w a precious file every time you get done working with it. Refinements on the technique include hardlinking the "-i" file to different directories instead of touch'ing it more than once, to save on inodes.)
(This also assumes that the user is already familiar with any of the half-billion methods of actually deleting a file whose name starts with '-'. This is /the/ most frequently asked FAQ in comp.unix.*.)
There. Now you know the most interesting trick in the whole book, and you don't need to spend the sixty bucks. :-)
You cannot apply a technological solution to a sociological problem. (Edwards' Law)
UGU offers a Unix tip of the day at http://www.ugu.com/sui/ugu/show?tip.today - that should keep you in tips for a while.
Why can't I moderate something "Wrong" or at least "Grossly Misinformed"?