Difference between revisions of "Linux Tips"

From LPTMS Wiki
Jump to: navigation, search
m
m (Miscellaneous)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Using ssh==
+
== Related pages ==
  
* 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:
+
* [[Using ssh]]
ssh-keygen -t dsa
+
* [[Transferring files]]
Then, you have the two new files in the ssh directory
+
* [[Working with compressed files]]
id_dsa
 
id_dsa.pub
 
Copy the public key id_dsa.pub on the .ssh/authorized_keys file of the distant computer. Now it should work for you!
 
  
* you want to execute a single command on a distant computer without connecting to the computer.
+
== Miscellaneous ==
  
* ssh tunnels... (to be done)
+
=== Moving and editing on a line ===
  
==Handling batch jobs==
+
Works for emacs, and also for the terminal command line which particularly useful for the everyday life
* if you want to send a job on a computer and logout without killing the job:
+
* go towards next(previous) word
  :> nohup ./job
+
Esc-f, Esc-b
 +
* go to the end(beginning) of a line
 +
Ctrl-e, Ctrl-a  
 +
* Cut text towards end of line and put it into the kill ring
 +
Ctrl-k
 +
* Kills next(previous) word and put it into the kill ring
 +
Esc-d, Esc-Backspace
 +
* Paste what is in the kill ring
 +
  Ctrl-y
  
==Transferring files==
+
=== History of commands ===
  
* the ''scp'' command:
+
* a useful command : '!''com''' recalls the last command which first letters are ''com''. For instance:
:> scp server:directory here
+
  !a
* if you do some regular updates, there is no ''-update'' option to ''scp''. Then, better use the ''rsync'' command. For instance with
+
will call ''acroread file.pdf'' if this was the last command starting with 'a'.
  :> 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==
+
* another way to find a command in the history is to pipe the ''history'' command to ''grep'':
Linux usually provides a couple of command piping gzip
+
history|grep acroread
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:
 
<source lang="bash">
 
#!/bin/bash
 
PATH=${GZIP_BINDIR-'/bin'}:$PATH
 
  
usage="Usage: $0 [OPTIONS]... [FILES]...
+
===Handling batch jobs===
Like 'tail', but operate on the uncompressed contents of any compressed FILEs.
+
* if you want to send a job on a computer and logout without killing the job:
 
+
nohup ./job
Options are the same as for 'tail'."
 
 
 
case $1 in
 
--help)    exec echo "$usage";;
 
-h)        exec echo "$usage";;
 
esac
 
 
 
options=""
 
files=""
 
for i in $@; do
 
str="$i"
 
if test -f $i && [ ${str:(-3)} = ".gz" ]; then
 
    files=$files"$i "
 
else
 
    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"
 
    fi
 
fi
 
done
 
 
 
for file in $files; do
 
    echo "==>"$file"<=="
 
    exec gzip -cd $file | tail $options
 
done
 
</source>
 
  
== The coma to point conversion in French environment ==
+
=== 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:
 
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:

Latest revision as of 16:23, 9 December 2011

Related pages

Miscellaneous

Moving and editing on a line

Works for emacs, and also for the terminal command line which particularly useful for the everyday life

  • go towards next(previous) word
Esc-f, Esc-b
  • go to the end(beginning) of a line
Ctrl-e, Ctrl-a 
  • Cut text towards end of line and put it into the kill ring
Ctrl-k
  • Kills next(previous) word and put it into the kill ring
Esc-d, Esc-Backspace
  • Paste what is in the kill ring
Ctrl-y

History of commands

  • a useful command : '!com' recalls the last command which first letters are com. For instance:
!a

will call acroread file.pdf if this was the last command starting with 'a'.

  • another way to find a command in the history is to pipe the history command to grep:
history|grep acroread

Handling batch jobs

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

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:

LC_NUMERIC=en_US
export LC_NUMERIC

this will make the job without too many side effects.