Linux Tips and Tricks

We collect here some tricks for solving small Linux problems (mostly on Redhat/Centos Linux).

Bash: How to make an ssh remote non-login shell to use /etc/profile.d/*.sh settings?

A user having /bin/bash as the default shell in /etc/passwd has to add this to the ~${HOME}/.bashrc file:

# non-login shell settings
for i in /etc/profile.d/*.sh ; do
    if [ -r "$i" ]; then
        . $i
    fi
done

Bash does not source /etc/profile.d/*.sh files when starting a non-login shell. See http://www.faqs.org/docs/bashman/bashref_63.html.

Bash: How to write a message to all users logged in

Use simply wall command or the w and write commands, for example:

# save list of current user_tty (separated by '_' for post-processing), excluding headers and the current tty (:0)
user_tty_s=`w | grep -v load | grep -v USER | tr -s '[ ]' | cut -d" " -f 1,2 | tr ' ' '_' | grep -v :0`
for user_tty in $user_tty_s;
do
  usertty=`echo $user_tty | tr '_' ' '`
  echo "The system will reboot at 1 p.m.. Please save you work!" |  write $usertty
done

The script can be adapted for other shells.

CentOS5: How to set the default printer?

You have two choices:

  1. Use GNOME Default Printer Tool http://web.mit.edu/rhel-doc/4/RH-DOCS/rhel-sag-en-4/s1-printing-edit.html. In order for users to configure a default printer for themselves only, each user should use the GNOME Default Printer Tool, which can be found by selecting Applications (on the Panel) => Preferences => More Preferences => Default Printer.
  2. tcsh: put the following line (if you want camp4200 as the default printer) in your ~${HOME}/.cshrc:

    setenv PRINTER camp4200

Openoffice: Corrupted ods file: Format Error discovered in the file in sub-document contents.xml at 2,2568(row,col)

Your file.ods file cannot be open because of the above format error. Rename the file.ods into file.zip, unzip it:

mkdir file; cp file.zip file; cd file; unzip file.zip; rm file.zip

Edit contents.xml intelligently: around character number 2568 it contains garbage, and re-create the zip file:

zip -r * file.zip; mv file.zip file.ods

You may need to repeat this operation several times, until all format errors are fixed.

Shell: An intruduction to shell commands

See UnixCommands (good for beginners :), or search internet.

Shell: How to create a tar file and copy it over ssh on the fly?

Here is the command:

tar -zcf - toftelun | ssh root@jordan dd of=/scratch/toftelun.tar.gz

Thunderbird: How to copy Message Filters from one account to another?

  1. Close Thunderbird,
  2. In your profile directory copy the msgFilterRules.dat file from one account subdirectory to another.

Xmgrace: Special characters

The special character mode is enabled and disabled by \c and \C, respectively.

To write 'Å' in xmgrace use: \cE

To write "+-" in xmgrace use: \c1

Example: Lengh in (Å), should be written as: Length in (\cE\C)

IT-wiki: Linux_Tips_and_Tricks (last edited 2011-05-25 08:09:04 by MarcinDulak)