Tuesday, January 10, 2012

Copy & Delete


Copy (cp):
               Copies file and directories.
               If copying from one destination to other, the path could be either absolute or relative.

                  E.g:
                           Absolute path: cp /users/sr1/a.txt /users1/sr2
                           Relative path: cp a.txt ../sr2 (assuming the directory structure to be same as above)


        Attributes:

  • -f: if an existing destination file cannot be opened, remove it and try again
  • -i: prompt before overwrite
  • -l: link files instead of copying
  • -R: copy directories recursively
  • -r: remove each existing destination file before attempting to open it (contrast with --force)
  • -s: make symbolic links instead of copying
  • -u: copy only when the SOURCE file is newer than the destination file or when the destination file is missing

Delete (rm):


        Removes files and directories.

     Attributes

  •         
  • -d: unlink FILE, even if it is a non-empty directory (super-user only)
  • -f: forcefully remove the file, no prompt if non-existing file
  • -i: prompt before any removal
  • -r, -R: remove the contents of directories recursively 

E.g: for removing all files in a directory and directory itself

   rm -rf directoryname
   
Note: rm -rf  * is most disastrous command in unix as it delete all the files in the directory and sub directories.

Monday, January 9, 2012

LS command - Listing files and directories

One of the most important and frequently used command in UNIX is LS.

The ls command lists all files in the directory that match the name. LS could be used for listing a particular directory using absolute (ls /users/sr1) or relative path (ls . for listing current directory, ls .. for listing one directory up). The following are the attributes that are commonly used with LS

-a: Displays all files including hidden file)
-b: Displays nonprinting characters in octal.
-c: Displays files by file timestamp.
-d: Displays only directories.
-F: Flags filenames if they are link, directory or normal file (/ if file is directory, * if normal file, @if link)
-g: Displays the long format listing, but exclude the owner name.
-i: Displays the inode for each file.
-l: isplays the long format listing.
-m: Displays the names as a comma-separated list.
-n: Displays the long format listing, with GID and UID numbers.
-o: Displays the long format listing, but excludes group name.
-r: Displays files in reverse order.
-R: Displays subdirectories as well (recursive printing)
-t: Displays newest files first. (based on timestamp)
-u: Displays files by the file access time.
-x: Displays files as rows across the screen.
-1: Displays each entry on a line

Tuesday, January 3, 2012

Lets get started with UNIX

Unix is all about the command, command attributes and redirecting them. Lets get started with a list of command which are used in unix most commonly and frequently.
Unix Regular Commands
  • ls
  • mkdir
  • cp
  • cd
  • cat
  • find
  • mv
  • rm
  • find
  • sort
  • uniq
  • sed
  • exec
  • grep
  • ps
  • df
  • du
  • who
  • cmp
  • diff
  • head
  • tail
  • useradd
  • userdel
  • v i

We would go on with examples, hands on and attributes of each command one by one.

P.S. These are the commands frequently used by me at workstation. I know there would be a lot of more commands. Friends are requested to update and comment as and when they think it is required as I am trying to make it as a common learning forum for all of us.

Setup on home machine for unix and oracle

For learning unix and oracle, the first challenge I faced was - "What are the essential s/w". Being a windows fan, I was not in a mood to install mandrake or red hat linux (conservation of disk space). Finally i zeroed on installing the following s/w
  • Cygwin NT 6.1 - unix simulator
  • Oracle 11gr2
  • Toad 9.1 - Oracle tool
The installation went smooth and all connection were set automatically between cygwin and oracle. In short within an hour I was all set to start hands on on unix on my home machine.