CLI workaround for Windows XP : Using TAIL
Shell Tips
October 21, 2006 | COMMENTS

If you are an addict of the command line interface whateve the OS you use, you probably already had difficulties to administrate some Windows XP box remotely. Tips ! Get the [Windows Server 2003 Resource Kit tools][1] on you could install lot of usefull tools and especially tail !

# display help

tail /?

# display last ten lines of a file


# display last thirty lines of a file

tail -30 FILENAME

# keep accessing file, displaying new lines as necessary.

tail -f FILENAME

System Requirements

Supported Operating Systems: Windows Server 2003; Windows XP

  • 30 MB of free disk space
  • Windows XP
  • Windows XP SP1
  • Windows Server 2003 family
Removing ^M in imported Windows files
Shell Tips
October 9, 2006 | COMMENTS

When you import file from Windows OS (or even from old Macintosh OS) you most likely have the ^M at the end of each line. Systems based on ASCII or a compatible character set use either LF (Line Feed, 0x0A, n) or CR (Carriage Return, 0x0D, r) individually, or CR followed by LF (CR+LF, 0x0D 0x0A, rn). Below is a quick list of OS using which convention :

  • LF : UNIX and UNIX-Like systems, Linux, AIX, Xenix, Mac OS X, BeOS, Amiga, RISC OS...
  • CR+LF : CP/M, MP/M, DOS, OS/2, Microsoft Windows (all versions)
  • CR : Commodore machines, Apple II family and Mac OS through version 9

The different newline conventions often cause text files that have been transferred between systems of different types to be displayed incorrectly. For example, files originating on Unix or Apple Macintosh systems may appear as a single long line on a Windows system. Conversely, when viewing a file from a Windows computer on a Unix system, the extra CR may be displayed as ^M at the end of each line or as a second line break.
You can convert with editors relatively small files. For larger files on Windows NT/2000/XP you can use the following command:

TYPE unix_file | FIND "" /V > dos_file

On Unix, a DOS/Windows text file can be converted to Unix format by simply using the tool dos2unix or by removing all ASCII CR characters with the command "tr".

tr -d &#8216;\r&#8217; < inputfile > outputfile

You can add an alias to your shell startup script to create easy to remember variations of the tr command for each purpose.

Using bash as an example, edit .bashrc and add these lines.

alias cvtCR="tr '\r' '\n'"
alias cvtCRLF="tr -d '\r'";

You now have two new commands that you can type from the command line.
To try the commands out right away, without opening a new terminal, you
need to tell bash to re-read it’s startup file by typing

source .bashrc

Now you are ready to try out the new commands.

To convert an old MAC file you would type
cvtCR < MACFILE > UNIXFILE This will read a file named MACFILE and create a file named UNIXFILE that has all of the r’s converted to n’s For DOS files, you just want to remove the darn r’s so in cvtCRLF the -d tells tr to delete them. If you wan to update a sample file you can use you favorite editor : VI !


Becarefull, you get the cariage return symbols by the keystroke CTRL+V+ENTER.

How to manage an idle ssh connection ?
Shell Tips
October 5, 2006 | COMMENTS

You probably already have an idle ssh connection that you can’t leave because of a tcp timeout somewhere on the network or a bad command that you executed. What to do with this idle session ? Easy, just use the exit sequence ~.(tilde and a period) then you could open a new session properly.

Moving quickly from anywhere with $CDPATH
Tips Shell
September 27, 2006 | COMMENTS

Do you know the environment variable $CDPATH? This variable let you define some path where to look for a directories when moving with the command CD. You can define multiple path in this variable. This can be usefull if you have some directories that you access more frequently than the others. As this variable define the order how you move from a directory to another, I suggest you to keep the "." directory in first position of your variable declaration. Of course, you can set this variable in your .bashrc

nicolas@grimm:~$ export CDPATH=.:/:~/  
nicolas@grimm:~$ cd usr<br />
/usr<br />
nicolas@grimm:/usr$ cd Desktop<br />
How will be interpreted a command
Tips Shell
September 27, 2006 | COMMENTS

You probably have set some personnal alias or function on your box. Most common is probably dir, ls, ll... If you forgot how you define your alias or function, the easiest way for get back the definition isn't to read your numerous .bashrc but using some bash built-in command : type or command.

type: usage: type [-afptP] name [name ...]
command: usage: command [-pVv] command [arg ...]

Command is generally used for running command with arguments ignoring any shell function named command. Instead of Type that describe a command, for each name, indicate how it would be interpreted if used as a command name. But both can be used, here is some examples :

[root@host ~]# alias -p
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
[root@host ~]# command -v rm
alias rm='rm -i'
[root@host ~]# command -V rm
rm is aliased to `rm -i'
[root@host ~]# type rm
rm is aliased to `rm -i'