Use sed to add a newline to the end of a file (this will perform an in-place replacement and create a backup file, MYFILE.bak):
$ sed -i.bak '$G' MYFILE
Some programs, such as Emacs, will omit the trailing newline from a file unless configured to add one. Emacs can be configured to add a newline automatically.
backupcommandsconfigurationeditorsemacsin-placeline-endingsnewlinesedshell
To add a service to boot automatically on startup, do the following:
# chkconfig --level 345 <service_name> on
bootchkconfigcommandsconfigurationservicestartup
Sometimes MTU issues arise, particularly with PPPoE on Cisco DSL CPE. These can be addressed by changing the TCP Maximum Segment Size (MSS) on the pertinent interface:
interface Dialer1 ! ... ip tcp adjust-mss <size in bytes> ! ...
ciscoconfigurationdslmssmtupppoetcp
Instead of poluting your otherwise pristine aliases file, include larger files using this syntax:
all_users: ":include:/filename"
This will allow you to email all_users@localhost and get all the users in the referenced file.
aliasesconfigurationmailmtasendmailserversyntax
While looking at the summary of your message press A to attach a message in one of your spools. You'll be prompted for the mailbox. Then, tag (t) the messages you want attached and quit (q).
attachmentsconfigurationkeystrokesmailboxmessagesmuamutt
Put this into ~/.vimrc:
fun! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfun
fun! ShiftInsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<s-tab>"
else
return "\<c-n>"
endif
endfun
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-r>=ShiftInsertTabWrapper()<cr>
:set dictionary+=dict.file
:set dictionary+=%
:set iskeyword+=:
:set complete+=k
autocompletionconfigurationeditorssettingsvivimvimrc
Use these screenrc commands to bind specific key sequences to commands outside of the escape sequence (normally C-a). You can bind key combos to commands this way so you don't always have to prefix commands with your escape key sequence:
# Bind Control-PageDown to 'next', Control-PageUp to 'prev' # to navigate between windows bindkey ^[[5;5~ prev bindkey ^[[6;5~ next # Bind arrow keys Control-Down to 'next', Control-Up to 'prev' # to navigate between windows bindkey ^[[1;5A prev bindkey ^[[1;5B next
(The keycodes for these keys can be obtained by running cat > /dev/null and pressing the desired key combination.)
bindingbindkeycommandsconfigurationescapekeystrokesscreenscreenrc
%@ is the specifier for timestamps in output formatting:
/fset send_public %@%P<%n$2%P>%n $3- /fset send_action %@%K* %W$1 %n$3-
bitchxcommandsconfigurationirctimestamps
If you've got another service (e.g., tomcat) fighting for port 8080, you can change the port Oracle uses with the following calls:
-- change HTTP port from 8080 to 8083 call dbms_xdb.cfg_update(updateXML(dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/httpconfig/http-port/text()', 8083)); -- change FTP port from 2100 to 2111 call dbms_xdb.cfg_update(updateXML( dbms_xdb.cfg_get(), '/xdbconfig/sysconfig/protocolconfig/ftpconfig/ftp-port/text()' , 2111)); -- refresh settings exec dbms_xdb.cfg_refresh;
Tip borrowed from an article by red-database-security.com.
configurationconflictftphttporacleportssqltomcat
To change the color of a particular face (e.g. font-lock-comment-face), use this elisp (editing where necessary):
(custom-set-faces '(font-lock-comment-face ((t (:foreground "lightblue" (background light)))) ) )
lightblue and other color names are defined in rgb.txt, included with your emacs and X installations.
colorsconfigurationeditorselispemacsx11
Ever been on a machine that was ailing and just wouldn't respond? As soon as you're root, lower the priority of the offending process ID(s) (in this example, 1103) by using the 'renice' command:
# renice -19 1103
commandsconfigurationcontroldebuggingmonitoringpriorityprocessrecoveryrenicerescuesecurityshell
Tired of those wide tables that wrap? You can end your query with a \G to get output like this:
mysql> select * from users\G
*************************** 1. row ***************************
id: 1
name: xinu
created: 20050115210745
*************************** 2. row ***************************
id: 2
name: cygnus
created: 20050115210803
2 rows in set (0.00 sec)
configurationconvertmysqloutputsql
Some recommended settings for your ~/.vimrc because we all hate tabs (right?):
set sw=4 set ts=4 set sts=4 set expandtab syntax on
configurationeditorsindentationvimvimrc
To set your own global keybinding to a function, use global-set-key in your ~/.emacs as follows:
(global-set-key "C-cl" 'enlarge-window-horizontally)
configurationdot-emacseditorselispemacskeystrokes
If you like working with a dark background and enjoy syntax highlighting but hate the navy blue on black, try putting the following line in your ~/.vimrc:
set background=dark
backgroundconfigurationeditorshighlightingsyntaxvimvimrc
If instead of a blank space you'd prefer something that tells you a particular column in a row is NULL, you can set it:
\pset null '(null)'
commandsconfigurationpostgresqlpsql
If you want to run a query or a function and ditch the output, you can do something like this:
xinu=# select my_void_function() \g /dev/null
commandsconfigurationpostgresqlpsql
You can send windows to other desktops in Openbox by right-clicking on the title bar and clicking the appropriate desktop name from the Send to desktop submenu. An easier way to do this is to click and hold on a window title bar and use your desktop switching keys (usually C-A-PgDown and C-A-PgUp by default). As you change desktops, the window you're holding onto will move to each desktop you visit. Just release the mouse button when you've reached the desired desktop.
These keybindings also facilitate the same behavior if you press the keys while focused on the window you want to move:
<keybind key="S-A-Left"> <action name="SendToDesktopLeft"><wrap>no</wrap></action> </keybind> <keybind key="S-A-Right"> <action name="SendToDesktopRight"><wrap>no</wrap></action> </keybind> <keybind key="S-A-Up"> <action name="SendToDesktopUp"><wrap>no</wrap></action> </keybind> <keybind key="S-A-Down"> <action name="SendToDesktopDown"><wrap>no</wrap></action> </keybind>
This has been tested with Openbox 3.2.
configurationkeybindingskeystrokesopenboxwmx11xml
If you want to see how a query like \du is being built:
\set ECHO_HIDDEN
analysiscommandsconfigurationpostgresqlpsqlsql
To edit the programs that run on startup of a Windows 9X / XP installation (this doesn't work on Windows 2000), go to Start -> Run and run msconfig. Click on the Startup tab and check or uncheck items to add or remove them from your startup sequence.
bootconfigurationstartupwin2kwin9xwindowswinxp
If you want Openbox to invoke multiple commands for a keybinding, you can just add extra action elements inside the keybind element. Sometimes XMMS freezes up on my machine, so I use this in my rc.xml file:
<keybind key="C-A-k"> <action name="Execute"><execute>killall -9 xmms</execute></action> <action name="Execute"><execute>xmms</execute></action> </keybind>
This has been tested with Openbox 3.2.
configurationinvocationkeybindingskeystrokesopenboxrc.xmlwmx11xmlxmms
If you want to change the fill column, do the following:
C-u 60 C-x f
(where '60' is the fill column setting you want to use.)
configurationeditorsemacskeystrokes
Like you, I love Firefox for many reasons, including its popup blocking support. It turns out that some clever people figured out that you could launch popups from Flash, getting around the Firefox default settings.
Fortunately, you can get around it:
1. Type about:config into the Firefox location bar. 2. Right-click on the page and select New and then Integer. 3. Name it privacy.popups.disable_from_plugins 4. Set the value to 2.
The possible values are:
0: Allow all popups from plugins. 1: Allow popups, but limit them to dom.popup_maximum. 2: Block popups from plugins. 3: Block popups from plugins, even on whitelisted sites.
Note: Borrowed from http://www.petebevin.com. Read the original article.
browserconfigurationfirefoxpopupspamui
If you want to flush your inbox and move the messages you've read into the =read box without leaving mutt, just revisit your INBOX again by pressing c!.
configurationinboxkeystrokesmailboxmessagesmuamutt
To force it to run through the queue (again), you can run:
# ${PATH_TO_POSTFIX}/postfix flush
commandsconfigurationmailmtapostfixqueueserver
Use this in your ~/.emacs to bind a key to goto-line:
(global-set-key "C-cl" 'goto-line)
configurationdot-emacseditorselispemacskeystrokes
Starting with Mutt 1.5.7, you can have Mutt cache IMAP headers to improve IMAP performance considerably. Set the header_cache option in your ~/.muttrc:
set header_cache=/home/bob/.cache_dir
cacheconfigurationheadersimapmessagesmuamutt
You can use this in your shell dotfile (e.g. ~/.bash_profile, ~/.zshrc) to create a screen session when you log in or reattach to an existing screen:
if [[ $TERM != 'screen' ]] ; then
if [[ `screen -list | grep -v "No" | awk '$2 { print }' | wc -l` == 0 ]] ; then
screen
else
screen -dr
fi
fi
This works in bash and zsh.
attachbash_profilebootconfigurationscreenscreenrcsessionshellstartup
Update /etc/sysctl.conf and add (or alter):
kernel.shmmax = <max bytes>
and run sysctl -p to update the system settings.
commandsconfigurationshared-memorysysctlsysctl.confsystem
To create a macro:
C-x (
Once in macro recording mode, enter a series of commands. When finished:
C-x )
To name the most recently recorded macro:
M-x name-last-kbd-macro
Enter a name for the macro. The name will now be accessible as M-x <name>.
To generate macro elisp suitable for reload, run M-x insert-kbd-macro and enter the name of a defined macro. Paste the resulting code into ~/.emacs.
configurationdot-emacseditorsemacskeystrokesmacros
To get emacs to stop inserting tab characters and insert spaces instead, use this in your ~/.emacs file:
(setq-default indent-tabs-mode nil)
configurationdot-emacseditorsemacsindentationspacestabs
Emacs features a minor mode, mouse-avoidance-mode, which causes the mouse to move away from the Emacs point when the point gets too close. This can be really helpful if you're used to moving your mouse away from the cursor to avoid typing "underneath" the mouse. In your custom-set-variables section in ~/.emacs, add the appropriate elisp:
(custom-set-variables . . '(mouse-avoidance-mode (quote animate) nil (avoid)) . .
The animation parameters of mouse-avoidance-mode can be customized with M-x customize.
configurationeditorselispemacsmouseneat
If you want to start up multiple pages in Firefox, put a string like this in your start URL under Tools -> Options:
http://www.google.com/|http://www.slashdot.org/
browserconfigurationfirefoxstartup
If you know you want to use a previous email as a template, find the message and press M-e. It will dump you in an editor with the same headers and content.
configurationeditorheaderskeystrokesmuamutttemplate
In your ~/.psqlrc, add this to emulate MySQL-style borders in query results:
\pset border 2
commandsconfigurationmysqloutputpostgresqlpsqlpsqlrc
If you've logged on and there's a stale connection still up holding your nick, you can notify the server that it's a ghost and get it back with the following:
/m nickserv ghost <nick> <password>
configurationfreenodeircnickserv
If you want to omit traffic from certain hosts (the dev machines, etc) you can add these directives to your configuration block:
SetEnvIf Remote_Addr 192.168.1.99$ do_not_log CustomLog logs/access_log combined env=!do_not_log
*Note: You need to have mod_env installed for this to work.
apacheconfigurationloggingmod_env
Press T and enter a pattern like:
~s foo
or:
~c bogus@example.com
After you've tagged the messages you want to operate on, press ; followed by an action (e.g. s some_folder).
configurationkeystrokesmessagesmuamutttagging
Open about:config in a new tab and make the following changes:
network.http.pipelining -> True network.http.pipelining.maxrequests -> 10
Anywhere on the screen, right-click and add a new integer:
nglayout.initialpaint.delay -> 0
If you're using a proxy, also change the proxy versions:
network.http.pipelining.proxy.pipelining -> True
WARNING: Be conservative when setting your pipelining settings. To the untrained eye this feature looks like a DOS attempt on the server side and might get you blocked.
browserconfigurationfirefoxgotchanetworkperformance
If you use middle-clicking to paste into Emacs windows but don't like how the paste occurs at the click location and would rather paste at point, use this in your ~/.emacs:
(setq mouse-yank-at-point t)
Thanks to Kevin Turner for pointing this out.
configurationdot-emacseditorselispemacsmousepointyank
Use this command to purge old configs and files from your system that are in uninstalled packages:
$ dpkg --get-selections | awk '/deinstall/ {print $1}' | xargs dpkg --purge
awkcommandsconfigurationdebiandpkgpackagespurgexargs
If you want to see how long a query is taking to run, you can either run explain analyze or enable timing for the client by typing \timing.
analysisconfigurationdebuggingdurationoutputperformancepostgresqlpsqlruntimesqltiming
Some of your commonly accessed mutt folders have shortcut names. Press c to change folders and then use the following:
! - inbox < - sent messages > - read messages
aliasesconfigurationfolderskeystrokesmuamutt
If you need your script to have access to ActiveRecord, ActiveMail, et al. you can place these directives at the top of your script:
#!/usr/bin/env ruby require 'rubygems' require_gem 'activesupport'
activerecordconfigurationlanguagesmodulesprogrammingrailsrorruby
If you have a services script in /etc/rc.d, you can add the service to the various run levels to create the appropriate start/kill symlinks:
# chkconfig --level 345 imap on # service xinetd restart
bootchkconfigcommandsconfigurationfedoraredhatservicesstartupsymlinks
To redirect all pages to / with Apache, use mod_rewrite:
RewriteEngine On RewriteRule \/.+ / [L,R]
apacheconfigurationmod_rewriteredirectrewriterules
If your BGP neighbour is a Cisco unit (and possibly others), it is possible to reprocess all learned routes and new announcements without clearing and retransmitting the full contents of the BGP table. This is known as a "soft reconfiguration," and is supported as of IOS 12.0. This avoids fast route cache invalidation, network service disruption, and other results associated with wiping the BGP table that would normally be undesirable, although it is more memory-intensive:
Router# clear ip bgp <neighbor IP, AS number, or *> in
To trigger a release of updates toward a neighbor in a similar fashion:
Router# clear ip bgp <neighbor IP, AS number, or *> out
bgpciscocommandsconfigurationiospeerrefilterrouterouter
You can remove the "help line" at the top of your Mutt screen (the one that says "q:Quit d:Del ...") by unsetting the 'help' config item in ~/.muttrc:
unset help
configurationdisplayhelpmuamuttmuttrcunset
Reset the root password:
1. Insert the Solaris install CD. 2. Issue STOP-A (Ctrl-Break). 3. Type: boot cdrom -s 4. fsck /dev/rdsk/c0t0d0s0 5. mnt /dev/dsk/c0t0d0s0 /a 6. cd /a/etc 7. TERM="vt100"; export TERM 8. vi shadow 9. on root line, delete everything in the second ":" delimited field. 10. exit out of file (ESC :wq! -or ESC ZZ)
bootcommandsconfigurationhackpasswordresetrootsolarisstartup
Beware that on some versions of PHP, the PHP session ID value is a hexadecimal hash but on some newer systems the configuration is used to adjust the contents of the session ID string:
; Define how many bits are stored in each character when converting ; the binary hash data to something readable. ; ; 4 bits: 0-9, a-f ; 5 bits: 0-9, a-v ; 6 bits: 0-9, a-z, A-Z, "-", "," session.hash_bits_per_character = 5
configurationgotchahexadecimallanguagesphpphp.iniprogrammingsession
If you wish for a particular file to be handled with a mode that isn't already associated with its extension, you may put a header like this anywhere in the file:
-*- mode: outline; mode: auto-fill -*-
Alternatively, you can update your ~/.emacs to use modes based on file extension or filename. For example, to use html-mode for files ending in .tpl:
(setq auto-mode-alist
(cons '("\\.tpl$" . html-mode) auto-mode-alist))
You can also configure Emacs to use a specific major and minor mode together for a given file extension. This example defines my-mode to load outline-mode (a major mode) and auto-fill-mode (a minor mode) for files ending in .foo:
(defun my-mode ()
(outline-mode)
(auto-fill-mode))
(setq auto-mode-alist
(append '(("\\.foo$" . my-mode))
auto-mode-alist))
configurationdot-emacseditorselispemacs
Set the PROMPT1 variable using psql prompt escape sequences:
\set PROMPT1 '[%n@%M:%/]=%# '
commandsconfigurationescapepostgresqlpsqlvariables
If you find yourself having to log into various systems with long strange names and usernames that aren't your own, check into ~/.ssh/config. Adding a Host block for each system you need to log into will give you a short name to use as well as let you set the user (and various other things - check out man ssh_config):
Host cs HostName cs.really.long.name.example.com User mrxinu
At this point you can type ssh cs and log right in.
commandsconfigurationsshssh_config
Set this variable in your ~/.psqlrc to stop on error when psql is used to run non-interactive scripts (e.g. cat file | psql ...):
\set ON_ERROR_STOP 1
Or use it from the command line:
$ psql ... -v ON_ERROR_STOP=1 ...
commandsconfigurationdebugginginteractivepipepostgresqlpsqlpsqlrc
If you want to take your site down for maintenance, but leave your webmail portal active on Sundays, you could put this in either your <VirtualHost> block or in an .htaccess file for your site:
RewriteEngine on
RewriteCond %{TIME_WDAY} 0
RewriteRule !^/mail.* https://path/to/your/maint/page.html
apacheconfigurationhtaccessmod_rewriterewritevirtualhost
If an NFS mount is frozen because the endpoint is unavailable, you can try a "lazy umount" on the mount to let the kernel take care of cleaning it up, rather than letting user-space processes wait on it:
# umount -l /path/to/mount
Additionally, you can use the NFS "soft" option when mounting the share to prevent hard locking of this kind; see nfs(5). Thanks to Kevin Turner for this tip.
brokenconfigurationfilesystemfrozengotchalazymountnfssoft
If you need to discover on which paths a binary depends, you can sometimes run strings on it and grep for everything starting with a slash:
# strings /usr/sbin/named | grep ^/ /lib/ld-linux.so.2 /etc/named.conf /etc/rndc.key /etc/lwresd.conf /etc/resolv.conf /var/run/named/named.pid /var/run/named/lwresd.pid /dev/null
binaryconfigurationgrepprocessshellstrings
Some virtual mapping goodness:
<VirtualHost *> ServerName cprogrammer.org ServerAlias cprogrammer.org *.cprogrammer.org # See the docs for the %-specs; %1 maps to the first part of the # domain (a.b.c.d.e -> a, a.b.c -> a) VirtualDocumentRoot /users/%1/public_html VirtualScriptAlias /users/%1/public_html/cgi-bin/ </VirtualHost>
apacheconfigurationmappingneatvirtualhost
This caption config line will add a "caption" to the bottom of the screen which will highlight the currently selected screen and show you a list of all the rest. Add it to your ~/.screenrc:
caption always " | %-w%{= BW}%50>%n %t%{-}%+w |%<"
captionconfigurationscreenscreenrc
This file is essentially the same as the UNIX hosts file:
C:\Windows\System32\Drivers\etc\hosts
configurationdnshostswindows
Put your .ttf font file into ~/.fonts/ and re-run fc-cache and ttmkfdir in ~/.fonts/.
configurationfontttfx11