Dave Horner's Website - Yet another perspective on things...
Home Tech Talk Unix/Linux/BSD/etc Various tidbits - notes from korn bourne and friends.
130 guests
Rough Hits : 2954465
moon and stars
how did u find my site?





 
this website would be better without ads?!




 
I have discovered a truly marvelous proof of this, which this margin is too narrow to contain.
--Pierre de Fermat
1=0.999...

Various tidbits - notes from korn bourne and friends.

Saturday, 26 March 2005 10:45

Move to the beginning and end of line in bash

Ctrl-a - move to start of current line.
Ctrl-e - move to end of current line.

Clear and redraw screen in bash

Ctrl-L

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

Current path of script

path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

zsh

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


fish shell - a smart and user-friendly command line shell for OS X, Linux, and the rest of the family.

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.


tmux

tmux - tmux is a terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.
zolrath/wemux - wemux enhances tmux to make multi-user terminal multiplexing both easier and more powerful. It allows users to host a wemux server and have clients join in either: Mirror Mode gives clients (another SSH user on your machine) read-only access to the session, allowing them to see you work, or Pair Mode allows the client and yourself to work in the same terminal (shared cursor) Rogue Mode allows the client to pair or work independently in another window (separate cursors) in the same tmux session. It features multi-server support as well as user listing and notifications when users attach/detach.
kikijump/tslime.vim -Send command from vim to a running tmux session
Vimux: simple vim and tmux integration
A Tmux Crash Course
aziz/tmuxinator - Manage complex tmux sessions easily (ruby gem)
tmux is sweet as heck - fuzzy notepad
Practical Tmux
Caps Lock + Tmux
tmuxinator/tmuxinator - gem install tmuxinator;echo "source ~/.bin/tmuxinator.bash">>~/.bin/tmuxinator.bash; Manage complex tmux sessions using YAML.
tmux Tutorial - Split Terminal Windows Easily - Ctrl+b " h split, Ctrl+b % v split, Ctrl+b arrow key:switch pane, hold Ctrl+b, don't release it and hold one of the arrow keys: resize pane. great article, includes scripting tmux info,etc.
dayid's screen and tmux cheat sheet


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
Scripting screen for fun and profit... :) - Jerris Blog - Jerris Welt
GNU Screen and Zmodem « Adam Monsen
Setting the Terminal Title in Gnu Screen


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

exclude all permission denied lines from find

2>/dev/null removes the errors from your output. or you can do the whole 2>1 | grep -v "Permission Denied"

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 {} \;


executing a command against a list of files

use find, add a -o for each additional -name, surround in \( \).
command line - How can I chmod/chown a specific list of files? - Super User


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.
Flush DNS cache in Ubuntu | Emphatic Nonsense


Update your dynamic library settings in unix

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

Dynamic linker tricks: Using LD_PRELOAD to cheat, inject features and investigate programs | Rafa? Cie?lak's blog


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



Setting your domainname

of course you know about /etc/hostname and /etc/hosts. But did you know that there is actually kernel level domain/hostname values to be set on your machine? Checkout /etc/sysctl.conf, set kernel.hostname and kernel.domainname settings execute the command sysctl -p /etc/sysctl.conf to read and apply the changes of your /etc/sysctl.conf configuration file. also on redhat/centos, there is /etc/sysconfig/network HOSTNAME, which should be FQDN. I've seen and done it myself, running hostname -s in rc.local...


Get a random word with no '

shuf -n1 /usr/share/dict/words | sed 's/[^a-z]*//g'
Last Updated on Saturday, 03 January 2015 02:16