banner
Dave Horner's Website - Yet another perspective on things...
Home Tech Talk Unix/Linux/BSD/OSX/ETC Various tidbits - notes from korn bourne and friends.
If you appreciate the information found on this website, please drop me a line!

Who's Online

We have 19 guests online
Content View Hits : 1157148
moon and stars
How did you find my site?
 
How often do you answer random online questions?
 

Random Quote

"Being a robot’s great, but we don't have emotions, and sometimes that makes me very sad."
--Bender, Futurama
P1010048
P1010108
P1010116
P1010105

Various tidbits - notes from korn bourne and friends.

Saturday, 26 March 2005 10:45

How do I redirect stderr to stdout...or maybe redirect stderr to a file??

For some reason, remembering how to properly redirect stderr is beyond me. I always forget that 2>&1. Redirecting standard error (stderr) and stdout to file...
$ command &> command.log
OR
$ command > command.log 2>&1
OR
$ command 2>&1 | tee command.log

zsh

Zsh
robbyrussell's oh-my-zsh at master - GitHub


Korn Shell


KSH script BASICS
For filename completion, use ESC \ and ESC =
To enter your history, hit the ESC key, press k to move through prior commands.
To edit use h and l to move the cursor left and right, x to delete characters, i to insert characters (use ESC to finish the insertion). Just like vim style commands.


Screen is your friend!

Lately I have been really loving the program called screen.  It allows you to run multiple programs on a terminal and switch between them.  The power of screen comes in when you've got a bunch of tasks that you need to do on a single computer.  So for example, if I want to run a vim session on a configuration script, as well as run the server, and sit in the server debug console... you run a separate screen for each of these tasks.  Then, instead of exiting vim, running the script, and then running the command to get into the debug console... you simply hit CTRL-ALT-" to select which thing you want to do.  Saves a BUNCH of time!
To create a screen type:
screen -t screenname "cmd"

To reconnect to the detached terminal, use (-x)...hey works multiple.
screen -x

ctrl +a S horizontal split region
ctrl +a switches between regions

Screen FAQ
A nice article on screen @ the LinuxJournal
The power of 'screen' revisited
Screen: The terminal baby-sitter in the sysadmin's toolbox
scie.nti.st » GNU screen with vertical split support
Screen VT100/ANSI Terminal Emulator Cheat Sheet - good coders code, great reuse
Vertical Split for GNU Screen


Find & Replace String In A Non-Ascii File with Perl and Python

Fun with find

This finds all root owned suid files.
find . -user root -a -perm -4000 -print
This replaces 'search' with 'replace' in all files.
find . -type f -exec sed -i ’s/search/replace/’ {} \;
Delete empty directories
find -depth -type d -empty -exec rmdir {} \;


Grep with path and line numbers

I'm always forgetting this one, so maybe I'll remember if I document it. To get line numbers and filenames when using grep... Add the options -H (for filenames) and -n (for line numbers).  So for example lets say you want to search for all files in the current directory including subdirectories... you would use:
find . -name "*" -exec grep -H -n "Edit" {} \;


Mime-Construct is awesome:

Looking for a good command-line util for sending email?  One that might support multi-part attachments?  Well mime-construct might be exactly what you are looking for!  Get it from the PERL cpan archives [here].
mime-construct --to "
  This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 " --subject "Subject line" --attachment "attachmentname.ext" --file "path/to/file"


Security:

Here is a pam module that will execute a script when people login.
pam_preprofile.tgz

SNMP:

MibDepot

Linux Kernel Development

I've decided on doing some linux development.  More to come.
Doc on Linux Internals
Kernel Newbies
32-bit UID BSD Accounting patch
Linux Input Replay
Linux Related Mailinglists


I always for forget the escape key to get into command mode when connected to a remote host. When you get inside telnet press "^]" (CTRL-Right_Bracket is a common telnet escape, that will allow you to get to the telnet> prompt and then you can type quit to kill that telnet session to a remote host).

Flushing DNS

To flush DNS in Microsoft Windows run: ipconfig /flushdns
You can also use the command ipconfig /displaydns to view the DNS resolver cache.

How to Flush DNS in Mac OSX run: lookupd -flushcache

How to Flush DNS in Linux:
In Linux, the nscd daemon manages the DNS cache.
To flush the DNS cache, restart the nscd daemon.


To change your dynamic linking information, edit /etc/ld.so.conf, then run /sbin/ldconfig.
Many times you have to add "/usr/local/lib"

Undo the extraction of a tar gone wrong!

This oneliner deletes the list of files from a tar from the disk.
tar tfz filename.tar.gz | xargs rm -fR


Find programs with open ports

Having a firewall is good, but I also like to have a close look at the processes with open ports. The following will display port and process information:
netstat -apn|less
watch 'netstat -apn'


How to make backup copies with GNU tar

tar --create --gzip --preserve-permissions --same-owner --file=backup-`date +"%b_%d_%Y"`.tar.gz filestobackup/


scripts - perlhobby - One-sentence summary of this page. - Project Hosting on Google Code - bunch of random commands.

Using sed to comment and uncomment all lines in a script

Lets comment the already uncommented lines with #@ so that we can uncomment our programatic comments later.
sed -i 's/^\([^#]\)/#@\1/g' yourfile
 Now, lets remove those comments.
 sed -i 's/^#@//g' yourfile


awk

$ awk -F":" '{ print "username: " $1 "\t\tuid:" $3" }' /etc/passwd
The GNU Awk User's Guide
Awk by example, Part 1 --
Hartigan/Computer/AWK


[one-liner]: Special Variables in Bash « Lâmôlabs
[one-liner]: Bash’s wait Command « Lâmôlabs
[one-liner]: Removing a File’s Extension with Cut « Lâmôlabs
Pushing & Pulling Files Around Using tar, ssh, scp, & rsync « Lâmôlabs
Jonathan Ellis's Programming Blog - Spyced: Linux performance basics - vmstat,iostat,top
Last Updated on Wednesday, 27 October 2010 11:17