Linux Tips

From LPTMS Wiki
Revision as of 12:09, 19 November 2011 by Roux (talk | contribs)

Jump to: navigation, search

Using ssh

  • you work on a computer and you want to easily connect another distant computer without entering you password at each time. To do so, you must generate a private and a public key on your computer to be put on the .ssh directory on your home, using, for instance, the dsa protocol:
ssh-keygen -t dsa

Then, you have the two new files in the ssh directory


Copy the public key on the .ssh/authorized_keys file of the distant computer

  • you want to execute a single command on a distant computer without connecting to the computer.
  • ssh tunnels... (to be done)

Handling batch jobs

  • if you want to send a job on a computer and logout without killing the job:
:> nohup ./job

Transferring files

  • the scp command:
:> scp server:directory here
  • if you do some regular updates, there is no -update option to scp. Then, better use the rsync command. For instance with
:> rsync -avub -e ssh server:data/*.gz data/

be careful with the slash after directory names, with or without is no exactly the same behavior. Look at man rsync before using it.

Working with zip files

Linux usually provides a couple of command piping gzip

zgreg, zcat, zdiff, zless, zmore, zegrep,...

Here is a simple extension of tail and head for zipped files, that you can call ztail and zhead (example is for tail, replace "tail" with "head" everywhere to get zhead) and add to your own /bin directory:


usage="Usage: $0 [OPTIONS]... [FILES]...
Like 'tail', but operate on the uncompressed contents of any compressed FILEs.

Options are the same as for 'tail'."

case $1 in
--help)    exec echo "$usage";;
-h)        exec echo "$usage";;

for i in $@; do
if test -f $i && [ ${str:(-3)} = ".gz" ]; then
    files=$files"$i "
    if [ ${str:0:1} = "-" ] && [ $str != "-v" ] && [ $str != "--verbose" ]; then
        options=$options"$i "
    elif [ $str != "-v" ] && [ $str != "--verbose" ]; then
        echo -ne "***Warning: $i is neither a regular zip file or a regular option***\n\n"

for file in $files; do
    echo "==>"$file"<=="
    exec gzip -cd $file | tail $options

The coma to point conversion in French environment

if you are working with a configuration of Linux which has not the dot "." as a standard format for floating points data (for instance the coma "," in French), you can add the following two lines in your .bashrc file:


this will make the job without too many side effects.