2010/10/24

Make Monday first day on gnome calendar applet

Thanks to Stefanie for this quick customization of the pop-up calendar in gnome. Switching Monday to be the first day in the week is nice!


locale


Next, edit the applicable locale file (for me, en_US, use the result of the previous command if not en_US):

Edit this file:


/usr/share/i18n/locales/en_US


Locate the following line and change the value to 2 (for Monday):


first_weekday 2

sudo locale-gen

killall gnome-panel

2010/10/09

Using Find

Throughout my use of linux I keep meaning to spend time to learn find, as it always seems to have useful, powerful applications. I never do seem to get around to it... Finally learned this useful little example though, using xargs and a command:

ACT ON FIND RESULTS - The cool thing is that if the results contain filenames with weird characters (like a space) xargs will separate items based on a null terminator instead of any white space.
find . -name pattern -print0 | xargs --null ls -alh
CASE INSENSITIVE
find . -iname pattern -print0 | xargs --null ls -alh

2010/10/01

Display/Set Networking

NETWORK
route -n
route add default gw address interface
ifconfig interface address up
ip route list

CONNECTIONS
netstat -punta
netstat --program --udp --numeric --tcp --all

2010/09/22

Alien packages, installing .deb

alien - Converts between Red Hat rpm, Debian deb, Stampede slp, Slackware tgz, Solaris pkg, and lsb packages (from man page).

CONVERT
alien [--to-deb] package.rpm
INSTALL
dpkg -i package.deb

Without specifying --to-deb or any other output type, it should default to the .deb format.

Startup services

To deactivate a service at boot, for example, apache2: 'sudo update-rc.d -f
apache2 remove'. To activate it: 'sudo update-rc.d apache2 install
defaults'. (From debian-hints, fortune.)
  
    ENABLE
    update-rc.d -f apache2 remove
    DISABLE
    update-rc.d apache2 install defaults

2010/09/20

Save changes when not editing as root


Thanks to Kate Pauls for this one!

:w !sudo tee %


Sometimes you end up editing a file when not root. Some people are always logged in as root but, if you're a sudoer as I try to be most of the time, sometimes you forget you didn't intend to make changes before opening a root owned file in vi just to view it and end up wanting to make changes.

2010/09/14

GNOME


GNOME GNU Network Object Model Environment. An alternative to KDE. I love it. Below I'm merely listing things I need in gnome and can't imagine functioning without (or without knowing). Well... gksu doesn't come up very often.

CUSTOMIZE - menus, prefs, compiz settings
alacarte
gconf-editor (see ~/.gconf and ~/.gconfd)
ccsm
QUICKSILVER - Just like on my Mac
gnome-launch-box
ROOT GUI
gksu command

2010/09/10

Automated text editing


Well, sort of automated; there's no decision-making being made for the human.

Batch Replace, Text Replace in each file from forums.devshed.com
For every file of type f in certain directory [what's type f?]:
find /path/to/start/from/ -type f | xargs perl -pi -e 's/applicationX/applicationY/g'
For every file in current working directory:
ls -1|xargs perl -pi -e 's/10.200.8.6/10.200.8.21/'

Batch Add to end of line from unix.derkeiler.com
I needed to add (the "-a" string") to a specific line in each file, this did the trick! The $ indicates the end of line, but I don't know how it works beyond that... Obviously, I need to spend more time learning sed!
cat branchoperations.selectstaffing.com.cfg|sed '/service_description/s/$/-a/'
Adapted to:
ls -1|xargs sed -i '/service_description/s/$/ SelectIIS6-A/'

Text editing with vi


vi VIsual mode in ex. Today's letter d in the below (ex?) commands is brought to you by the word delete. I still haven't really checked out emacs, though I suppose I should.

GLOBAL DELETE - Search and destroy lines matching pattern
:g/pattern/d 
INVERSE GLOBAL DELETE - Search and destroy lines not matching pattern
:v/pattern/d
SED - Sed substitute
:%s/old/new/g
READ - Read in output from command
:r!command
OPTIONS
:set all


There are also some things left for me to play with involving global commands. Thanks to this post and the associated comments, Christopher Suter suggets using commands and macros:

:%g/.../normal O//

:%g/.../normal @q

2010/08/13

Simple file backup

cp - Copy files and stuff; since tar and rsync are sometimes overkill.
    This is, by far, the simplest way to backup and archive files. Also see ln for symbolic and hard links.

BASIC
cp file backupFile
SHORTHAND - This uses a shell trick to copy file to file-backup
cp file{,-backup}
RECURSIVE
cp -r folder destination
PRESERVE - Retain file permissions, attributes, and user and group IDs (I think)
cp -p file file2
VERBOSE
cp -v file file2

2010/08/05

Remote Desktop

rdesktop Remote DESKTOP connection client. For linux, this tool replaces mstsc.

    I can't seem to fully escape Windows. Yet. 
    It's like the end of the Universe: I can't escape it... Yet. But I will find a way eventually.
    In the meantime, I still don't have to have it installed on my local computer.
CONSOLE - /admin or /console argument in mstsc
rdesktop -0 hostname
AUTHENTICATION - (Is there a way to specify the local computer as the domain?)
rdesktop -uUserName -pPassWord -dWindowsDomain hostname
SEAMLESS - Full Screen
rdesktop -A hostname
CACHING - Persistent bitmap caching to disk to speed up performance.
rdesktop -P hostname
COLOR DEPTH
rdesktop -a <8, 15, 16 or 24>

2010/06/19

Screen hardstatus


Screen is one of the best programs ever made for linux. This is my current hardstatus line, always a work in progress. My .screenrc:

backtick 1 1 1 $HOME/.screen_custom/sys_status.sh

hardstatus on
hardstatus alwayslastline
hardstatus string '%{= kg}[ %{y}%H %{g}][%= %{=kw}%?%-Lw%?%{y}(%{W}%n*%f%t%?(%u)%?%{y})%{g}%?%+Lw%?%?%= %{g}][%{y}%Y-%m-%d %{W}%c %{g}]'
caption always "%{wK} %1`"

As can be seen in the first line, it includes a script I've placed in a custom folder:

#!/bin/sh
uptime | sed 's/.*average: //'

Although, it's a bit redundant with multiple windows open.

I also need to see if there's a way to put the -H 1000000 option I like to use in my .screenrc instead of specifying it when being invoked.

Network Manager applet disappeared!


Usually, I can use the applet in the upper part of the screen to connect to a wireless network. This is the applet for the Network Manager in GNOME. In the above picture the access point labeled "dlink" can be seen. Recently, this useful little applet had completely disappeared.

As embarrassing as this is, it took me several days and many pointless searches until I finally stumbled on a fix:

ps aux|grep nm-applet

I then ran kill -9 on that pid and then issued the following command after hitting ALT-F2.

nm-applet --sm-disable

Fixed! The little applet had been restored to my notification area. Yay! I still have no idea what the --sm-disable option is. I also don't know if it's a problem to have multiple users logged in or if that was the actual cause of the problem.

This had recently disappeared from my login leaving me only with my battery status, bluetooth applet, sound control and such. Logging into another account on my computer, the applet would show up properly; I thought this might be a user account issue or some problem with my gconf preferences, though I no longer believe this to be true.

This was never a big deal since Ubuntu automatically connects to the open (unprotected) Wi-Fi network in my neighbor's house so it's only been more of a nuisance than anything else.

The fun part of this little adventure occurred when I was finally motivated enough to find a fix. While at a friend's house recently and being unable to use the applet (either in my own login where it had disappeared or in the other user account, a guest account, where it did show up but would seem to be unresponsive, even after a reboot) to connect to his Wi-Fi, I had to tether my Droid to my laptop in order to search the web until I found the right command to invoke the Network Manager applet. I had only just recently followed instructions on setting up the tethered link to my phone. (Thank you, Shannon!)

Archiving files

tar - archive utility (Tape ARchive).
  
For faster and more frequent use, gzip (Gnu ZIP) is generally a better choice but bzip2 can create a significantly smaller sized file. Using lzma (Lempel-Ziv-Markov chain Algorithm) provides even more compression but takes even more time than bzip2. Flags -v for verbose to show what is happening and -f for file since we're not actually using a tape drive in the '80s.
 
CREATE
tar cfv archive.tar file1 file2 ...
EXTRACT - Look at TF options below!
tar xvf archive.tar
COMPRESSION (BZIP2)
tar cfvj archive.tar.bz2 file1 file2 ...
COMPRESSION (GZIP)
tar cvfz archive.tar.gz file1 file2 ...
COMPRESSION (LZMA) - Don't forget the leading dash for standard options!
tar --lzma -cvfz archive.tar.lzma file1 file2 ...
LIST - Will indicate extraction paths that will be created!
tar tf archive.tar
PRESERVE - retain file permissions down to unique user and group IDs
tar cfvp archive.tar file1 ...
ABSOLUTE PATHS - Retain leading /
tar cfvP archive.tar /absolute/path/file1 ...
REMOVE FILES - Automatically delete original files after archiving
tar --remove-files -cvfz archive.tar.gz file1 file2 ...
 
There are also some other cool features worth mentioning: Files can be searched for within archives with the -t (or --list) flag by passing a second argument and additional files can be added to archives with the -r (--append or --update) flag and passing the filenames as additional arguments. Files in an archive can be replaced with current versions with -N (--newer), I believe, in the same way as used with -r.
 
This wonderful tool was originally implemented for use with archiving data to magnetic tapes. Appeared in Version 7 of Bell (AT&T?) Unix in 1979 (cool!) and one of my most favorite, often-used tools. Beyond the ability to package a multitude of files into one file, tar can also preserve file permissions, date and time information and directory structures.
 
The usual convention for file extensions for archived files are .tar.gz (.tgz), .tar.bz2 (.tbz or .tbz2 or .tb2) and .tar.lzma (.tlz). The gzip format has replaced the old .z archive (invoked with the -Z flag these days) format usually used by piping to the compress compression utility.

2010/06/07

Installing fonts

To install a font (TrueType only, I believe), copy the font file to the directory below and then rebuild the font cache with the following command. Alternatively, one could copy the font to ~/.fonts (would the font only be available to that user then?).
 
DIRECTORY
/usr/share/fonts/
  
COMMAND
sudo fc-cache -f -v
  
This worked with a TrueType font provided by my company's marketing department, the same font used on all the company's signs and branding. Of course, I had to restart Scribus for it to show up in the list of available fonts.

Starting over

I'm redoing this blog. My goal is to post random notes about Ubuntu linux that are useful to... well... really only myself. My hope is to record all of the random tidbits of information I should save for my own computing life, especially in regards to using Ubuntu, such as...
  • favorite screen hardstatus line
  • quick howtos for samba, vncserver, named
  • useful command line tools
  • needed third-party software, where and how to get them (flash, AdobePDF)
  • why zsh is better than bash
  • bluetooth stuff
  • nagios stuff
  • etc.
A lot of these will undoubtedly apply to any linux flavor, however, since I primarily only use Ubuntu I am titling this blog "Kinji's Ubuntu Notes." A lot of these posts will be specific to Ubuntu. Since this is live and on the web and will probably be crawled by Google spiders, I also hope one or two posts may be helpful to other users out there, other people still just discovering Ubuntu and the wonders of linux, as I am.