Linux / Unix


Linux / Unix26 Jul 2007 09:59 am

A little of the magical stuff that makes vi such a useful tool for editing text files and such.

By now everyone knows / starts up the search function, but did you know it can also do a search and replace? (more on that in a moment)

A quick review of some advanced search functions;

/s
would move the cursor to the first instance of ’s’ in the text, hit n to repeat the last command (in this case search for s)… not very efficient in most cases so read on.

/[a-z]s
is a little more specific, the search will look for any instance of s but preceded by a litter a - z. Try different combinations and you will find the pattern matching can be very precise with only a few keystrokes. This is not pico or nano, so case is sensitve.

/[^c]tem
will search for any tem preceded by any character other than a c.

/^[A-Z].*\. *$

will search for any line that begins with a capital letter and ends with a period and any number of blanks

All of the above patterns can be used to as part of search and replace (or find and replace for this coming from windoze) pattern matching.

:s/search_string/replacement_string/g

This command replaces every search_string on the current line with replacement_string. Omitting the g (global) flag at the end of the command will cause only the first occurrence of search_string to be altered. Often you may wish to confirm each replacement. This can be done with the confirm flag c. The confirm flag should be placed after or in place of the g flag. Suppose I had the following line:

Give a young man a hammer… and he’ll find something to bash

and typed

:s/find something to bash/bash something to bits/

I would be left with

Give a young man a hammer… and he’ll bash something to bits

Any command that begins with a “:” is called a line mode command and performs its duty on the line the cursor is currently on. However, you can override vi’s default of operating only on the current line by preceding them with a range of line numbers. For example, if I wanted to replace guy with gal on lines 32 through 56 I would type

:32,56s/guy/gal/g

Omitting the g would cause only the first occurrence of guy in each line to be replaced. The “.” and “$” play a special role in this sort of designation. “.” indicates the current line, and “$” indicates the last line of the file. Therefore, if I wanted to delete1 from the current line to the end of the file I would enter:2

:.,$d

I could even do something like:

:.,/Fred/d

which would delete from the current line to the next line that contained Fred.

One other shortcut that might be worth mentioning is that 1,$ and % both indicate all the lines in the file. Therefore,

:1,$s/search_string/replacement_string/g

and

:%s/search_string/replacement_string/g

do exactly the same thing.

—————————–
The marketing companies working for different businesses are also sponsoring affiliate program marketing to promote their products and services. The computers software are used to build effective websites and now with a lot of companies are offering free web hosting services to the customers to promote online trading. The internet phone is used to by the buyers and the sellers to talk at cheap rates. The online backup uses a script to follow step by step procedures to streamline the processes.

Linux / Unix25 Apr 2007 02:51 pm

Wildacrd replace in Unix

Way back when the limited wildcard replace in DOS was as simple as using a ? to represent a single character for renaming, moving, copying, or whatever you wanted to do to a file..

For example;

CODE:
  1. copy 117691???.txt test117691???.txt

would search the current directory and match any filename with 117691(any 3 chatacters).txt and copy them to test117691(same 3 characters).txt.

On Unix or Linux, it just doesn't work, but alas the key is a simple for loop, tested in bash and ksh shells;

CODE:
  1. for file in 117691????.job; do cp $file test${file%?????}; done

This command gives the same results as the old DOS method, a little more typing but with a little thought it becomes a very powerful command.

Linux / Unix21 Jul 2006 09:02 am

Having multiple servers to entertain me and for website and application development, I found that entering passwords continually while switching from machine to machine very tiring. This enables cron jobs to run backups, and a mryiad of other automated tasks via an encrypted connection, thus not exposing my passwords over the network, some of which crosses wireless segments using such thigns as FTP, instead scp keeps things nice and garbled for anyone thinking to listen in.

This is not only for Linux, but all Unix type boxes and even Windows! Yes, I said windows! I'll publish another article to explain how to accomplish this one a windows machine.

Here's a quick and dirty tutorial of how to set up shared SSH keyss to authenticate to each server automagically, no more entering passphrases!

Login to the first server (harry in this example) and create your key

CODE:
  1. root@harry:/root# ssh-keygen -t rsa
  2. Generating public/private rsa key pair.
  3. Enter file in which to save the key (/root/.ssh/id_rsa):
  4. Enter passphrase (empty for no passphrase):   [just hit enter]
  5. Enter same passphrase again:   [just hit enter again]
  6. Your identification has been saved in /root/.ssh/id_rsa.
  7. Your public key has been saved in /root/.ssh/id_rsa.pub.
  8. The key fingerprint is:
  9. ac:0b:bf:3f:30:9a:05:29:d8:2b:27:58:cf:d3:08:9d
  10. root@harry:

Now scp the rsa key to the destination server (case):

CODE:
  1. root@harry:/home/dave# scp /root/.ssh/id_rsa.pub case:.ssh/authorized_keys
  2. root@case's password: [enter root's password]
  3. id_rsa.pub                                    100392     0.4KB/s   00:00

and presto.... you are done, now ssh to case

CODE:
  1. root@harry:/home/dave# ssh root@case
  2. Last login: Fri Jul 21 08:45:20 2006 from harry
  3. Linux 2.4.22.
  4. root@case:~#

root is instantly authenticated from harry because of the shared key.

Now continue to replicate the process for each server/workstation/user that you wish. This can make life much easier for you however there is one drawback, see the note below.

NOTE: once setting this up even changing root's password will not resecure they connection or change the 'key' nor will it stop access from any machine with a shared user and key. In simpler terms much the same way giving away a key to your house, the one who posesses the address and key to the hosue may enter at any time, the only way to disallow access is to change the lock or destroy the key (in our world, the authorized_keys file).

Happy hacking.

-------------------------
Test king has proved itself to the students all over the world by conducting practice tests and training sessions through tests like VCP-101V and 1Y0-327 which are based on the real exam patterns. The Microsoft test number 70-350 is also a popular test among the computer students. Test king also offers training programs for Cisco in tests such as 642-873 and 646-588. Another known test is 642-372 which Cisco students take in order to prepare well for their certifications requirements.

Linux / Unix12 Jul 2006 01:23 pm

Quick and dirty - How to create a "tarball".

By now everyone has seen the wonderfull myproject.tar.gz, I say wonderful as to extract the 'project' or whatever is contained in the tarball can be accomplished with a single command and viola, all the files are extracted with all of thier subdirectories and files in tact, complete with unix permissions.

So you'd like to backup your website or project for distribution, easy enough

tar everything up
[server]$ tar -cf myproject.tar myprojectdir myotherprojectdir
and gzip it
[server]$ gzip myproject.tar
the result is will net you myproject.tar.gz all ready to do as you will with.

Explaination the -cf switch is simply create file, if you like you can use -vcf to display a verbose listing as tar moves along to ensure you are getting the intended files and directories.
myprojectdir myotherprojectdir are just the directories you which to include, this list can be one, two, or more diectories.

gzip will compress your .tar file and leave you with the resulting .gz, so of you want to retain a copy of the .tar be sure to make a copy before gzip.

As mentioned earlier, to extract your shiny new tarball once you have it in the desired directory, you can do this with one command,
[system]$ tar -xzvf myproject.tar.gz

Easy

Geeky Stuff& Linux / Unix07 Jun 2006 08:03 am

How To Determine What Version You Are Running

“What version am I running?” is often the question you need to answer before you can start talking to someone about a problem with your software or about making changes to your software.

You can use the following as a quick reference guide to easily answer the question “What version am I running?” for each component of your software (operating system, database, and application):

What version of HP-UX/Solaris/Linux (and most posix systems) am I running?
To get the version of Unix on your server, go into the korn shell and enter the 'uname' command with an 'a' option.:

>uname -a
HP-UX bmd350 B.10.20 D 9000/831 2011043966 64-user license

This example shows HP-UX running the 10.20 version.

$ uname -a
Linux server01 2.6.11-6mdk #1 Tue Mar 22 16:04:32 CET 2005 i686

Mandrake Linux using 2.6.11 kernel

$ uname -a
SunOS server1 5.10 Generic_118822-23 sun4u sparc SUNW,Sun-Fire-V440

Solaris... you get the idea.

What version of IBM AIX am I running?
For those of you running the IBM AIX operating system, to find out what version of the Operating System you are running (including the IBM UniData release), go to the UNIX shell, change directories as shown below and execute the cat command as follows:

# pwd
/usr/ud/bin
-r--r--r-- 1 root dw 173 Feb 28 2003 port.note

# cat port.note
Platform : AIX 4.3.3
Operating System : AIX engine 3 4 000159494C00
Porting Date : Feb 28 2003
UniData Release : 6.0.3 60_030221_4161
Ported by : srcman

#

What version of Windows NT am I running?
To get the version of Windows on your server for all releases of NT4.0, execute the command ‘status’ at TCL within the Universe environment:

>STATUS
You are logged onto XYZ running Windows NT 4.0 (Build 1381 Service Pack 6)

What version of Universe am I running?
To get the version of Universe on your server for all recent releases of Universe, edit the ‘RELLEVEL’ file in your VOC file:

>ED VOC RELLEVEL
0001: X-type - The RELEASE LEVEL of this account
0002: 9.6.1.3
0003: ADMIN
0004:
0005: 9.6.1.3

In this example, the release is 9.6.1.3.

What is my UniVerse Serial Number?
To find the UniVerse Serial Number, enter the CONFIG command at TCL. The Serial Number is the same as the License Number listed on the first line.

>CONFIG

Configuration data for license number 123456789:
User limit = 10

In this example, the UniVerse Serial Number is 123456789

What version of UniData am I running?
To get the version of UniData on your server for all recent releases of UniData, execute ‘VERSION’:

>VERSION
Unidata RDBMS......................3.3.2 Yes
Recoverable File System............1.1 No
Transaction Processing.............1.1 No
UniData OFS/NFA....................1.3 No
UniServer..........................1.3 Yes
UniDesktop.........................1.3 No
USAM Monitor Profile...............1.3 No
USAM Print.........................1.3 No
USAM Batch.........................1.3 No
USAM Journaling....................1.3 No
33265

The actual Version of UniData is 3.3.2.65 (last line).

What version of wIntergrate am I running?
For all releases of wIntegrate, start a session and click on the pull down menu and choose the "About" selection. You will see the version of wIntegrate. Note that wIntegrate98 is the also known as wIntegrate4.x.

What version of Preview am I running?

The easiest way to get your Preview version is to execute the command ‘Preview’ at TCL within the Universe/Unidata environment:

>PREVIEW
PREVIEW v3.0.2
File Name:

This is obviously version 3.0.2. Hit to get out of the file name prompt.

What version of DataFlo am I running?
For those of you who are on DataFlo, it is easy to find out which version of DataFlo you are on. If you are on releases before 5.5, edit the file “WELCOME” in STAT-USER at TCL within the Universe/Unidata environment:

> DataFlo release 5.4 (example shows 5.6 G6):
ED STAT-USER WELCOME
001: \RULER L A A A A CZ
002: ðð D A T A W O R K S C O R P O R A T I O N
003: ððððð+-----------------------------------------+
004: ðð | T H E D A T A W O R K S S Y S T E M |
005: ðð | R E L E A S E 5.4 09-25-92 |
006: ðð | R E V I S I O N G6 06-10-98 |:

The example here is Release 5.4 G6.

For those of you who are on versions of DataFlo that are 5.5 or higher, look at the version record in STAT-TABLES:

>ED STAT-TABLES VERSION
0001: 5.7.8
0002: 10-31-00
0003: 1998/1999/2000

The example here is version 5.7.8.

What version of Kourier am I running?

This list wouldn’t be complete without including how to get your Kourier release. For versions of Kourier that are version 3.0 or higher, the easiest way to get the version is to execute the command ‘KMK.VERSION’ at TCL within the Universe/Unidata environment:

>KMK.VERSION
Kourier by Kore Technologies
Version......: 3.1.1
Release Date.: 05-23-2002:

The example shows the Kourier version is 3.1.1.

« Previous PageNext Page »


BeSEO Entertainment Directory - Layouts Myspace - Loans - Myspace Layouts - Mortgages
X10 Home Security|Dakar's Photos
Listed on BlogShares