‘ Unix ’ category archive

What is GNU?

June 13, 08 by the programmer

The GNU Project was launched in 1984 to develop a complete Unix-like operating system which is free software: the GNU system.

GNU’s kernel wasn’t finished, so GNU is used with the kernel Linux. The combination of GNU and Linux is the GNU/Linux operating system, now used by millions. (Sometimes this combination is incorrectly called Linux.)

There are many variants or “distributions” of GNU/Linux. We recommend the GNU/Linux distributions that are 100% free software; in other words, entirely freedom-respecting.

The name “GNU” is a recursive acronym for “GNU’s Not Unix”; it is pronounced g-noo, as one syllable with no vowel sound between the g and the n.

The above text is quoted from the GNU official site.

So , what is GNU?

GNU is a free Unix-like operating system. They started making the operating system in January 1984. You can read the initial announcement at http://www.gnu.org/gnu/initial-announcement.html.

The Free Software Foundation was founded in October 1985, initially to raise funds to help develop GNU.

By 1990 they managed to finish most of the parts of the operating system except for the kernel. In that time a Unix-like kernel, was developed by Linus Torvalds in 1991 and made free software in 1992. Combining Linux with the almost-complete GNU system resulted in a complete operating system: the GNU/Linux system.

Estimates are that tens of millions of people now use GNU/Linux systems, typically via distributions such as Slackware, Debian, Red Hat, and others.

The GNU General Public License (GPL), the GNU Lesser General Public License (LGPL), and the GNU Free Documentation License (GFDL) were written for GNU, but are also used by many unrelated projects.

To learn more about the GNU and the complete history of development, visit the GNU official site at http://www.gnu.org and you can visit the free software foundation site at http://www.fsf.org/

You can even buy a GNU shirt or adopt a Gnu. :) http://shop.fsf.org/

Whois command in UNIX

June 02, 08 by the programmer

If you want to find out some informations about a domain name and you are running unix than you should use the whois command.

Usage: whois [OPTIONS] [QUERY]

Bellow is the list of the options

–version display version number and patch level
–help display this help
-v, –verbose verbose debug output
-c FILE, –config=FILE use FILE as configuration file
-h HOST, –host=HOST explicitly query HOST
n, –no-redirect - disable content redirection
-s, –no-whoisservers disable whois-servers.net service support
-a, –raw disable reformatting of the query
-i, –display-redirections display all redirects instead of hiding them
-p PORT, –port=PORT use port number PORT (in conjunction with HOST)
-r, –rwhois force an rwhois query to be made
–rwhois-display=DISPLAY sets the display option in rwhois queries
–rwhois-limit=LIMIT sets the maximum number of matches to return

Example: whois google.com

This will return all the available information about the domain google.com

* Note that there are many versions of the whois command so before you use it consult the man page

Display a calendar in UNIX

May 28, 08 by the programmer

If you want to see a calendar in UNIX all you have to do is write the cal command in the terminal.

This is how it’s used:

cal [-options] [[month] year]

DESCRIPTION
Cal displays a simple calendar. If arguments are not specified, the current month is displayed. The options are as follows:

-1 Display single month output. (This is the default.)
-3 Display prev/current/next month output.
-s Display Sunday as the first day of the week. (This is the default.)
-m Display Monday as the first day of the week.
-j Display Julian dates (days one-based, numbered from January 1).
-y Display a calendar for the current year.

A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified

Two parameters denote the month (1 - 12) and year. If no parameters are specified, the current month is calendar is displayed.
A year starts on Jan 1.
The cal command first appeared in Version 6 AT&T UNIX.

Rename file or folder in Unix

May 20, 08 by the programmer

You want to rename a file or folder in Unix and you can`t find the command, hmmmm

That happened to me too :)

Unix does not have a command specifically for renaming files, instead, the mv command is used for renaming and moving files and folders.

To change the name of a file in Unix, use the following command syntax

mv old_file.php new_file.php

To change the name of a folder in Unix, use the same syntax as for changing files except that the parameters are folder names.

mv old_folder_name new_folder_name

That’s it,

Lazy Unix programmers :)

Synchronizing folders in Unix with rsync

May 18, 08 by the programmer

Very important think when you are a programmer is to have the ablility and tools to synchronize your code on multiple locations.

For example you can have a development version a test version and a production version of the code, and you will want all of these versions to be synchronized.

One way of doing that in Unix operating systems is by using the rsync command.

Rsync is a free open source project.

In order to use this command you have to install it first. This article will not go into the installation procedure. You will have to download rsync from the official site (http://samba.anu.edu.au/rsync/) and install it on your unix operating system.

Usage examples

Rsync is a very efficient command because it uses a special protocol (rsync remote-update protocol) to synchronize files. It only synchronizes the differences between files, not the all files, which makes it very fast.

The command can be used to synchronize files/folders on a local computer and between remote computers.

The command has the following syntax:

rsync [options] src dest

  • options - see available options bellow
  • src - This is the source path. It can be a local or remote location. This is where the files that your are going to synchronize are located.
  • dest - This is the local or remote destination that you want to be synchronized with the source destination. All the files from the source destination will be copied here, and the source and destination folders will be the same.

You must specify a source and a destination, one of which may be remote.

Perhaps the best way to explain the syntax is with some examples:

rsync *.php foo:src/

this would transfer all files matching the pattern *.php from the current directory to the directory src on the machine foo.

rsync -avz foo:src/my_web_site /data/tmp

this would recursively transfer all files from the directory src/my_web_site on the machine foo into the /data/tmp/my_web_site directory on the local machine. The files are transferred in “archive” mode, which ensures that symbolic links, devices, attributes, permissions, ownerships etc are preserved in the transfer. Additionally, compression will be used to reduce the size of data portions of the transfer.

rsync -avz foo:src/my_web_site/ /data/tmp

a trailing slash on the source changes this behavior to transfer all files from the directory src/my_web_site on the machine foo into the /data/tmp/. A trailing / on a source name means “copy the contents of this directory”. Without a trailing slash it means “copy the directory”. This difference becomes particularly important when using the –delete option.

You can also use rsync in local-only mode.

rsync -avz *.php /home/dev/src/

The above line means synchronize all the php files from the current local directory to the “/home/dev/src/” local directory, and preserve all file/folder attributes.

The most interesting option that rsync has is the ability to use the command only to see what the diffrences are between two destinations. You can do that by sing the -n option.

rsync -navz *.php /home/dev/src/

The above line will only display the differences between the current folder and the “/home/dev/src/” folder, but it will not make any changes. This is very useful if you want to see what files you have worked on or which files were changed.

Available options

There are all the available options in rsync.

 -v, --verbose               increase verbosity
-q, --quiet                 decrease verbosity
-c, --checksum              always checksum
-a, --archive               archive mode
-r, --recursive             recurse into directories
-R, --relative              use relative path names
-b, --backup                make backups (default ~ suffix)
--backup-dir            make backups into this directory
--suffix=SUFFIX         override backup suffix
-u, --update                update only (don't overwrite newer files)
-l, --links                 copy symlinks as symlinks
-L, --copy-links            copy the referent of symlinks
--copy-unsafe-links     copy links outside the source tree
--safe-links            ignore links outside the destination tree
-H, --hard-links            preserve hard links
-p, --perms                 preserve permissions
-o, --owner                 preserve owner (root only)
-g, --group                 preserve group
-D, --devices               preserve devices (root only)
-t, --times                 preserve times
-S, --sparse                handle sparse files efficiently
-n, --dry-run               show what would have been transferred
-W, --whole-file            copy whole files, no incremental checks
--no-whole-file         turn off --whole-file
-x, --one-file-system       don't cross filesystem boundaries
-B, --block-size=SIZE       checksum blocking size (default 700)
-e, --rsh=COMMAND           specify rsh replacement
--rsync-path=PATH       specify path to rsync on the remote machine
-C, --cvs-exclude           auto ignore files in the same way CVS does
--existing              only update files that already exist
--ignore-existing       ignore files that already exist on the receiving side
--delete                delete files that don't exist on the sending side
--delete-excluded       also delete excluded files on the receiving side
--delete-after          delete after transferring, not before
--ignore-errors         delete even if there are IO errors
--max-delete=NUM        don't delete more than NUM files
--partial               keep partially transferred files
--force                 force deletion of directories even if not empty
--numeric-ids           don't map uid/gid values by user/group name
--timeout=TIME          set IO timeout in seconds
-I, --ignore-times          don't exclude files that match length and time
--size-only             only use file size when determining if a file should be transferred
--modify-window=NUM     Timestamp window (seconds) for file match (default=0)
-T  --temp-dir=DIR          create temporary files in directory DIR
--compare-dest=DIR      also compare destination files relative to DIR
-P                          equivalent to --partial --progress
-z, --compress              compress file data
--exclude=PATTERN       exclude files matching PATTERN
--exclude-from=FILE     exclude patterns listed in FILE
--include=PATTERN       don't exclude files matching PATTERN
--include-from=FILE     don't exclude patterns listed in FILE
--version               print version number
--daemon                run as a rsync daemon
--no-detach             do not detach from the parent
--address=ADDRESS       bind to the specified address
--config=FILE           specify alternate rsyncd.conf file
--port=PORT             specify alternate rsyncd port number
--blocking-io           use blocking IO for the remote shell
--no-blocking-io        turn off --blocking-io
--stats                 give some file transfer stats
--progress              show progress during transfer
--log-format=FORMAT     log file transfers using specified format
--password-file=FILE    get password from FILE
--bwlimit=KBPS          limit I/O bandwidth, KBytes per second
--read-batch=PREFIX     read batch fileset starting with PREFIX
--write-batch=PREFIX    write batch fileset starting with PREFIX
-h, --help                  show this help screen

What is the nslookup command?

May 18, 08 by the programmer

NSLOOKUP (Name Server Lookup)

is a command that it is used to query DNS (Domain Name System) servers and is embedded in Windows and Unix operating systems. Although nslookup exists in both UNIX and Windows, there are some differences in the way that it behaves in the two operating systems.

This command can be found in the BIND (Berkeley Internet Name Domain) package, the most commonly used DNS server on the Internet, especially on Unix operating systems.

The nslookup can be used to find various details relating to DNS including IP addresses of a particular computer, MX records for a domain or the NS servers of a domain - all using DNS lookups

The following examples are done on Windows platform.

NSLOOKUP common usage

You can use nslookup command by

  • calling it directly or
  • entering the nslookup shell

Direct usage of nslookup

In this example I will try to find out the IP address of my domain using the nslookup directly without entering its shell.

In order to do that I will write the following :

C:\>nslookup minanov.com
Server: locac dns server domain name
Address:
locac dns server IP Address

Non-authoritative answer:
Name: minanov.com
Address: 64.72.119.195

The first two rows in the command colored with light blue are showing the local network DNS server. This information is not correct.

However the other text bellow non-authoritative answer shows the name of the domain and the IP address of the server.

Using nslookup from it’s shell

Note that nslookup is a command that has a lot of possibilities. By entering in the shell all of this possibilities are available.

To enter the nslookup shell all you have to do is write “nslookup on the command prompt. If you want to find out more about all the possibilities just write “?” in the shell and hit enter. All of the available options will be displayed.

C:\>nslookup
>

Note that there is a more modern version of the nslookup command.

The command that will probably replace nslookup is the “dig” program, also embedded in the BIND package. However the dig command is not embedded in Windows operating systems yet. At least not in Windows XP.

Removing files and directories in unix using RM

May 08, 08 by the programmer

If you want to remove a file or directory in unix you should use the command rm.

The syntax of the rm command is:

rm [-options] [file|directory]

There are more options, but the most used ones are

-r or -R which means recursivly.

-f which means force (Does not ask you for confirmation)

Examples:

If you want to remove a single file you should use

rm filename.ext

if you want to remove a nempty directory you can use

rm directory_name

if you want to remove a directory that is not empty (contains files or other directories) use this command

rm -r directory_name

If you don’t want the command to ask for a confirmation then you can use the -f option in any of the above commands

rm -rf directory_name - Removes the directory “directory_name” and all of its files and other directories inside it without asking for confirmation

Good luck :)