Monday, December 19, 2011

Basic UNIX Commands - 1

Unix Commands

Note: You can use these commands at the Unix system prompt.

| more

the pipe symbol (|), located above the backward slash (\) key, and the word more can be used after Unix listing commands (such as ls or cat filename) to display information one screen at a time (ls |more or cat filename |more). Press Enter or the Spacebar to scroll forward.

banner word

displays the word or words you enter after the banner command in large print. For example, the command banner summer will display the word summer.

cal

displays a calendar for the current month

cal year

displays a calendar for a specific year. For example, the command cal 1999 will display a calendar for 1999.

cal month year

displays a calendar for a specific month and year. For example, the command cal 10 1999 will display a calendar for October 1999.

cat filename

displays the contents of a file

cat filename filename > new file

copies one or more files to a newly created file

cat filename >> destination file

adds one file to another file

cd

moves back to your home directory

cd directory

changes the current or working directory to another directory

cd ..

moves back one directory

cp filename newfilename

makes a copy of a file with a new name. To copy the file to another directory, use the command: cp filename directoryname or cp filename directoryname/newfilename

chmod

changes the read, write, and execute permissions of specified files and the search permissions of specified directories. For example, the command chmod 711 directorypath gives public access to that directory. The command chmod 644 filename also gives public access to the listed file. You must be in the directory where the file is stored.

chfn

allows you to change the information displayed about you when someone uses the finger command with your userID

finger userID

displays login information about the userID indicated

fmt filename > newfilename

sets the width of a file. Filename is the file you wish to format, and newfilename is the filename you wish to give the formatted file. If you bring a file into a mail message, and the lines do not wrap, but instead show dollar signs at the end, this command will set the width to wrap.

getacl filename

displays a list of all the people who read from, write to, and/or execute a particular file in your account. (For more info on this command, see the ACL document.)

head filename

displays the first ten lines of a file

head -# filename

displays the specified number of lines from the top of the file. For example, the command head -8 budget displays the first eight lines from the file titled budget.

history | more

displays of list of the last forty commands issued at the Unix prompt

kill -9 process#

kills a process. (Use ps command to list current processes.)

ls

lists directory contents and file information

ls -a

lists all files including hidden files

ls -F

lists files and subdirectories

ls -R

lists the chain of directories starting from the current directory

ls -s

lists the name and size of each file in a directory

man command

displays information from the online Unix reference manual about a specific command. For example, the command man cd displays information about changing directories.

man -k keyword

displays the commands relevant to a keyword. For example, the command man -k directory displays the commands for working with directories.

mesg n

sets your account to reject talk requests

mesg y

sets your account to accept a talk requests (default)

mkdir directoryname

adds a new directory

more filename

displays a file--one screen at a time

mv oldfilename newfilename

changes the name of a file

mv "filenamewithspace" newfilename

renames a file that has a space or unacceptable character in the filename. For example, the command mv "new budget" newbudget changes the name of the file from new budget to newbudget.

mv filename directoryname/

moves a file to another directory. Directoryname is the destination directory for the file.

passwd

initiates the process for changing your password

pico filename

creates a file using the pico editor

print -Pambler29 filename

sends the file to the Ambler SIC printer

print -Phsc filename

sends the file to the HSC campus printer

print -Ppaley filename

sends the file to the Paley SIC printer

print -Pvm filename

sends the file to the Main campus printer

ps

lists the active processes running in your account. (See the kill command to end a process.)

pwd

displays the current working directory

rm filename

deletes a file in a directory

rm filename1 filename2

deletes more than one file at a time

rmdir directoryname

deletes an empty directory

rm -r directoryname

deletes a directory and the subdirectories and files in the directory

setacl -u user:userID permissions file

assigns rights to allow another person access to a file. In this command, userID is the login ID of the person to whom you want to assign access; permission can be r (read), w (write), and/or x (execute); and file is the name of the file. (For more info on this command, see the ACL document.)

tail filename

displays the last ten lines of a file

tail filename -#

displays the specified number of lines from the bottom of the file. For example, the command tail budget- 8 displays the last eight lines from the file titled budget.

talk userID

initiates a talk request with someone who has an account on the same system

talk userID@system-name

initiates a talk request with someone who has an account on a different system

vi filename

creates a file using the vi editor

webster word

provides the entry from Webster's 7th Dictionary for a word. The entry includes definitions, pronunciation, and derivation.

whatquota

identifies the amount of disk space currently in use in your Unix account

whatquota -mail

identifies the mail spool space currently in use in your Unix account

who

identifies the login name, terminal number, date, and login time for each user who is logged on to the Unix system

write userID

allows you to communicate with another user who is logged on to the same system



















































Friday, December 9, 2011

Sorting an Array in C

For sorting an array, we have used the qsort function. This function provides the implementation of quicksort algorithm to sort the elements of an array.

Syntax of the function:
qsort(array, sizeof(array), sizeof(type), comparison_fn).

In the example, we have created a comparison function sort to compare two elements. For this we have passed two parameters (x and y ) which are pointers to elements and will return an int value by comparing them. This method compares each pair of elements. This function can be declared as:
int sort (const void * x, const void * y );

(*(int*)x - *(int*)y)- The parameters x and y checks for each pair of elements considering the elements as x and y. If x is found greater than y, then x goes before y otherwise, x goes after y. In case if x = y, then it remains on the same position.

- This header file stands for standard library which includes functions involving String, Memory, Environment, Sorting and Searching, Math and Multibyte.

Here is the code:

ARRAYSOR.C

#include
#include
#include
int array[] = { 90, 3, 33, 28, 80, 49, 8, 30, 36, 25 };
int sort(const void *x, const void *y) {
return (*(int*)x - *(int*)y);
}
void main() {
clrscr();
int i;
qsort(array, 10, sizeof(int), sort);
for (i=0; i<10; i++) {
printf("%d ", array[i]);
}
getch();
}

Output will be displayed as:

ARRAYSOR.EXE

3 8 25 28 30 33 36 49 80 90


Tuesday, November 1, 2011

DOS / Windows IP Commands

Below, you'll find a list of the most common IP commands for Windows and DOS. These include ipconfig, trace route, netstat, arp, route, hostname, control netconnections, and other popular DOS and Windows IP commands. Display Connection Configuration: ipconfig /all

Display DNS Cache Info: ipconfig /displaydns

Clear DNS Cache: ipconfig /flushdns

Release All IP Address Connections: ipconfig /release

Renew All IP Address Connections: ipconfig /renew

Re-Register the DNS connections: ipconfig /registerdns

Change/Modify DHCP Class ID: ipconfig /setclassid

Network Connections: control netconnections

Network Setup Wizard: netsetup.cpl

Test Connectivity: ping whatismyip.com

Trace Route: tracert

Displays the TCP/IP protocol sessions: netstat

Display Local Route: route

Display Resolved MAC Addresses: arp

Display Name of Computer Currently on: hostname

Display DHCP Class Information: ipconfig /showclassid

NameServer Lookup: nslookup whatismyip.com

Wednesday, October 19, 2011

Migration from IP V4 to IP V6

What is IPv6?

IPv6 (Internet Protocol Version 6) is the latest level of the Internet Protocol (IP), now included as part of IP support in many products including the major computer operating systems. Formally, IPv6 is a set of specifications from the Internet Engineering Task Force (IETF). IPv6 was designed as an evolutionary set of improvements to the current IPv4. Network hosts and intermediate nodes with either IPv4 or IPv6 can handle packets formatted for either level of the Internet Protocol. Users and service providers can update to IPv6 independently without having to coordinate with each other.

How is IPv6 different from IPv4?

The most obvious improvement in IPv6 over IPv4 is that IP addresses are lengthened from 32 bits to 128 bits. This extension anticipates considerable future growth of the Internet and provides relief for what was perceived as an impending shortage of network addresses.

IPv6 describes rules for three types of addressing: unicast (one host to one other host), anycast (one host to the nearest of multiple hosts), and multicast (one host to multiple hosts). Additional advantages of IPv6 are:

  • Options are specified in an extension to the header that is examined only at the destination, thus speeding up overall network performance.
  • The introduction of an "anycast" address provides the possibility of sending a message to the nearest of several possible gateway hosts with the idea that any one of them can manage the forwarding of the packet to others. Anycast messages can be used to update routing tables along the line.
  • Packets can be identified as belonging to a particular "flow" so that packets that are part of a multimedia presentation that needs to arrive in "real time" can be provided a higher quality-of-service relative to other customers.
  • The IPv6 header now includes extensions that allow a packet to specify a mechanism for authenticating its origin, for ensuring data integrity, and for ensuring privacy.

    Are we really running out of IPv4 addresses?

    Recently, the American Registry for Internet Numbers (ARIN) announced that v4 addresses would be history by 2012. Loki Jorgenson, chief scientist with Apparent Networks, said ARIN recently changed its position from being neutral on IPv6 to actively encouraging it.

    Jorgenson agreed with ARIN's estimation and said it could be just under five years before IPv4 addresses run out completely, but that projection is modest and made on the assumption that there won't be an IPv4 usage increase in the meantime. The five-year prediction is based on current usage rates, where ARIN doles out a certain number of IPv4 addresses per year. A usage increase could deplete the pool of addresses much sooner than anticipated.

    "It's a very gray, slushy kind of boundary where [we don't know] how much time that buys us," Jorgenson said, again stressing that it could be some time in 2010 or 2011 when the pool of IPv4 addresses runs dry. Adding to that confusion, he said, is the possibility that companies and agencies that have hoarded an excess of IPv4 addresses could sell them off as the supply dwindles, creating a short reprieve from total depletion.

    In a presentation at the Burton Group Catalyst Conference, John Curran, chairman of ARIN's board of trustees, said that 68% of v4 address space was allocated as of June. Of the remaining 32%, only 19% is openly available, while 13% is unavailable.

    Curran said the dwindling address pool changes past estimations of address depletion. Several years ago, it was estimated that addresses would be gone by 2020 or 2025. About two years ago, that estimation changed to 2017. Now (as Jorgenson mentioned), 2012 seems more likely, Curran said during his presentation. (From IPv6 readiness is key as IPv4 peters out by Andrew Hickey)

    Most recently, the IPv4 address pool drained from the Internet Assigned Numbers Authority (IANA). Learn what the IANA's IPv4 depletion means for enterprises in this tip.

    For more information, read IP address depletion hastens IPv6 adoption by Loki Jorgenson, or read this interview with IPv6 expert Scott Hogg: Does your business network need an IPv6 transition? Who needs IPv6?

    How do I make the transition?

  • Migrating from an existing IPv4 network to an IPv6 network need not be done in one big step, thanks to new technology that provides gateway services between each, such as the BIG-IP IPv6 gateway from F5 Networks. BIG-IP provides a full proxy for traffic between IPv4 and IPv6, allowing all traffic to be translated for consumption by either IPv4 or IPv6 end points. This allows organizations to stage their migration gradually as demand for IPv6 increases. (From How will IPv6 affect application management? by Karl Triebes)
  • Loki Jorgenson said that as v6 devices become available, companies should look into running a dual-stack model: networks that run both on v4 and v6, similar to a half-duplex/full-duplex deployment.
  • Silvia Hagen agreed that many companies will choose a dual-stack model, which will ease the transition, but that will create an additional workload going forward because v4 and v6 will require two separate security concepts and two routing protocols.
  • In your IPv4 to IPv6 transition, learn in this tip how IP formats are used to convert IPv4 addresses to v6 addresses.

    How will IPv6 affect application management?

  • With IPv6, there are significant changes that improve network device management. First, the increase in IP addressing from 32 to 128 bits is accompanied by an increase in the structure and allocation of addresses. The IPv6 address is comprised of a global routing prefix, a subnet ID, and an Interface ID (the portion local to a link within a LAN). The global unique portion of the address space is distributed hierarchically according to the network infrastructure topology through IANA. This allows the global routing table for IPv6 to be small, avoiding some scaling issues common with BGP routing today.
  • Second, there are enough addresses in IPv6 to give perhaps every square inch on the planet Earth a unique IP address. While this enables virtually any device you can imagine to be on the Internet, it poses a potential nightmare for an administrator to manage all the address assignments. Fortunately, IPv6 includes a feature (made of numerous smaller features) called Autoconfiguration of Nodes. This is essentially a next generation replacement of DHCP and ARP that is available in all IPv6 networks and allows you to connect a new device to the network without even minimal configuration. It also makes it much simpler to re-address your network if you change ISPs (and are thus allocated a different global routing prefix), because all you have to do is change the configuration of your router, and your entire network will re-acquire new addresses with the new prefix. This is a huge reduction in the network management burden.
  • With the increased features of IPv6 come some potential management issues. IPv6 provides native support for security, termed IPsec. Encryption may or may not include some of the header information depending on which mode is used to form the VPN, which can reduce the amount of active traffic management that can be applied to the flows between clients and servers. Managing the security policy between the endpoints (IKE) can be tricky as well if you need to implement that yourself; this is one of the main things an IPsec based VPN provides. Of course, IPsec can be strong but brittle in certain remote-access situations such as accessing a corporate network from a mobile device, further adding to the management burden by an IT department trying to provide such services.