Wednesday, January 31, 2007

Windows:
Adding line numbers to a word document: (This is not bullets and numbers. This is just in the view. In the printed document they are not shown.)
1. Go to File -> Page Setup and click the Layout tab.
2. Under Preview, click in the “Apply To” box and select “Whole Document”.
3. Click the “Line Numbers” button.
4. Click the “Add Line Numbering" check box.
5. Click “Restart Each Page” and click OK.
Each line of text will be numbered (except those in tables, footnotes, endnotes, text boxes, frames, and headers and footers), starting with number 1 on each page. If you want the numbering to be continuous and not start at 1 on each page, then in step 5, click the “continuous” box.
In some cases, you may not want certain paragraphs numbered. For example, highlighted notes for the reader that are not intended for the final document. To prevent Word from numbering those lines, follow these steps before turning on Line Numbering in Page Setup.
1. Highlight the paragraphs that you do not want numbered.
2. Go to Format -> Paragraph and click on the “Line And Page Breaks” tab.
3. Click the “Suppress Line Numbers” check box and click “OK”.
(This will also work when formatting an email in outlook)

Linux:

Use the “pr” utility to format text files so they are more suitable for viewing or for printing to a printer. The "pr"takes a file and breaks it up into pages, adding a header to each page.
For example, “pr” would convert a file that contains 150 lines into a file that contains three pages of text that you could then send to the printer.
By default, each page contains 66 lines of text. You can change this by using the -l switch.
The default header at the top of each page is the filename. You can customize this using the –h switch.
For example:
$ pr -h "My Homework" filename.txt
Rather than using "filename.txt" as the header, this will format the filename.txt file and use "My Homework" as the centered heading on each page.
pr” prints to standard output so it can be piped into another tool such as “more”, “less” or to redirect it to the “lpr” tool to print the file. If you want to keep the resulting output in a file, you need to redirect it.
For example:
$ pr filename.txt > newfilename.txt
Use the man pages or “pr –-help” to find all the available parameters such as formatting into columns, changing page width etc….
Bonus Tip:
To add the line numbering (like in the windows tip above) when using “vi” :
When in vi, press “Esc” and then “: set nu”

Feel free to leave a comment at the "comment" link below.

Sunday, January 28, 2007

Windows:


Network diagnostics tool.


Start --run-- netsh diag gui


Will open up the network diagnostics tool. You can set the parameters of what to check and then run the check. You can then save the output to a file and email the file to your admin or network guru to make it easier to troubleshoot a network problem.

Bonus Tip: (hey, I should charge extra for all the bonus tips)

To display a list of commands entered in a current DOS prompt (similar to the "history” command in Unix):

enter in the following command at the DOS prompt:

DOSKEY /history



Linux:


Did you ever ssh into a machine and then get stuck probably due to a break in the connectivity and your ssh client shell is still stuck? Ctrl C and Ctrl D does not seem to get you out of it.

You could open a new console, then ps –ef ¦grep ssh to find the PID of the ssh process and kill it but that is a bit complicated.

Instead, try to type “~.” (You may have to hit Enter). This should kill the ssh session on the client side.

Bonus tip:

nohup” command. (nohup = no hangup). If you need to run a script or command on a remote box but are worried that your ssh / telnet session will disconnect and disrupt your running process, use the nohup command and it will continue to run even if you get disconnected. Standard output is redirected to the “nohup.out "file.

Example: you want to find all files beginning with blabla on the remote box and write the list to the file /tmp/filelist.txt.

You could do

find / -name “blabla*” print >> /tmp/filelist.txt .

This will start a search and could take a long time. If your ssh / telnet session is disconnected, the "find" process will also die.

Instead, type:

nohup find / -name “blabla*” print >>/tmp/filelist.txt & (The & sign puts it in the background).

Now if your ssh / telnet session dies for any reason, your find process will continue. You can then reconnect and see the results in the /tmp/filelist.txt file.


Feel free to send me comments with any hints and tips to enlighten everyone with.

Monday, January 22, 2007

Formatting documents

Windows:
Adding line numbers to a word document: (This is not bullets and numbers. This is just in the view. In the printed document they are not shown.)

1. Go to File -- Page Setup and click the Layout tab.

2. Under Preview, click in the “Apply To” box and select “Whole Document”.

3. Click the “Line Numbers” button.

4. Click the “Add Line Numbering" check box.

5. Click “Restart Each Page” and click OK.

Each line of text will be numbered (except those in tables, footnotes, endnotes, text boxes, frames, and headers and footers), starting with number 1 on each page. If you want the numbering to be continuous and not start at 1 on each page, then in step 5, click the “continuous” box.

In some cases, you may not want certain paragraphs numbered—for example, highlighted notes for the reader that are not intended for the final document. To prevent Word from numbering those lines, follow these steps before turning on Line Numbering in Page Setup.

1. Select the paragraphs that you do not want numbered.

2. Go to Format -- Paragraph and click on the “Line And Page Breaks” tab.

3. Click the “Suppress Line Numbers” check box and click “OK”.

(This will also work when formatting an email in outlook)





Linux:


Use the “pr” utility to format text files so they are more suitable for printing to a printer or viewing. It takes a file and breaks it up into pages, adding a header to each page.

For example, “pr” would convert a file that contains 150 lines into a file that contains three pages of text that you could then send to the printer.

By default, each page contains 66 lines of text. You can change this by using the -l switch.

The default header at the top of each page is the filename. You can customize this using the –h switch.

For example:

pr -h "Tip-o-the-day" filename.txt

Rather than using "filename.txt" as the header, this will format the filename.txt file and use "Tip-o-the-day" as the centered heading on each page.

pr” prints to standard output so it can be piped into another tool such as “more”, “less” or to redirect it to the “lpr” tool to print the file. If you want to keep the resulting output in a file, you need to redirect it.

For example:

pr filename.txt >newfilename.txt

Use the man pages or “pr -–help” to find all the available parameters such as formatting into columns, changing page width etc….

Bonus Tip:

To add the line numbering (like in the above windows tip) when using “vi” :

When in vi, press “Esc” and then ": set nu"

Monday, January 15, 2007

DOS is not dead.

Windows:
Anyone remember DOS? It is still useful today.
To create a few folders with one command, use the “md" command:
Open a command prompt.
md this is more than one folder – will create 6 folders – this, is, more, than, one, folder
now delete them – rmdir this is more than one folder
To create a folder several folders deep, use:
md this\is\more\than\one\folder – will create a folder called this with a folder called is in it etc….
Creating a single folder with spaces in the name requires adding a double-quote at the beginning:
md "this is one folder" – will create one folder called “this is one folder

Bonus tip: At the command prompt, you can use forward slash (unix style) "/" as a folder divider when using the cd command to change your present working directory:
cd Windows/system32/drivers/etc


Linux:
Quick method for copying an entire directory including subdirectories and files to another directory.
(cd /source/directory && tar cf - . )¦(cd /dest/directory && tar xvfp -)

(My friend Richie pointed out that this could be done using:
cp -av /source/directory /destination/directory
I find that using tar will do the job quicker)

Monday, January 8, 2007

When did this windows box boot last?

Windoze:


Ever wonder when a windows box was last booted. In linux we can use “who –b” (in most flavours) but what about windows?

Try from the command prompt:

"net statistics workstation ¦ more "

(the for those unfamiliar "¦" is the "pipe" symbol. It is usualy depicted on the keyboard as two vertical lines one above the other)

The output of this command will show the date and time of last startup of windows. (The rest is mostly irrelevant info unless troubleshooting connections to servers)


Linux:

Did you ever have a file with a weird name including control characters which you could not delete? (ab^Hrd[ or something like that) (It could happen when naming a file you do a backspace which is sometimes input as ^H) You can’t do rm ab^Hrd[ because the shell will read part of the name as a control character.

One way to do it is to use the files inode number.

ls –il will show you the inode number of the files in the directory so you find what the inode number of that file is.

then you just type
find . -inum <inode-number>-exec rm -i {} \;
(Of course, replace <inode-number> with the actual inode number)
You will be asked to confirm the deletion and voila. File deleted.

Monday, January 1, 2007

1.Windows:
Remote desktop from a command line or batch file:

You can script a remote desktop connection, as Windows XP's remote desktop connection has an executable file that can accept command line parameters and be run from a batch file. The remote desktop connection executable file is MSTSC.EXE, and the following are some of the most common parameters:
· /v:<computername>--specifies the name of the computer to connect to.
. /v:<ipaddress> -- specifies the ip address of the computer to connect to.
· /f--starts the connection in a full screen.
· /w:<width>--specifies the width of the remote desktop screen.
· /h:<height>--specifies the height of the remote desktop screen.
· /console—if someone is connected and there are no more valid connections, this will connect to the console session.

For example, to remotely connect to a computer named pinky in a 640 x 480 remote desktop window, you would use the following command:
mstsc /v: pinky /w:640 /h:480

You can type this command line in the Start --> Run dialog box, as well as use it in a batch file.
(This will only work from XP pro and above)

2. Linux:

Resolving netbios name from an ip address
nmblookup –A <ipaddress>
e.g. nmblookup –A 192.168.170.39
will give the netbios name and group (domain) of the windows station with that ip address.