Krishna Logo
New Branches: Irving and Round Rock
Divied
Ria / Kumar @ 1-(877) 864-8462

 

Loading
Latest News
Home Navigation Divied
SQL/UNIX Navigation Divied UNIX/LINUX
Showing 1 - 10 of 16 Previous | 1 | 2 | Next
UNIX/LINUX

  CLICK HERE TO DOWNLOAD THE FILE USE THE BELLOW LINK T...  


2
UNIX
----
To log into any computer on network you need 
1. host name
2. user name
3. password
 
 
putty.exe - it connects to another unix machine in the network.
 
1 bit
8 bit = 1 byte
 
$ - Unix Prompt
 
Permissions of users:
---------------------
Read    - r - 4
write   - w - 2
Execute - x - 1
 
rwx or 421
 
user  - rwx
group - r_x
other - rw_
 
'/' - Root
 
UNIX - Case sensitve. 
all the commands in unix are in small letters
 
1. pwd
gives the path of the folder
 
2. clear
clear the work area
 
3. exit
exits out of the terminal
 
4. cal
gives the calender
 
5. date - display current timestamp
 
  date +%D - date part 
      +%T - time part of timestamp
+%H - hour
+%M - minute
+%S - Second
+%d - day (just day of the month)
+%m - 2 digit month
+%y - 2 digit year
+%Y - 4 digit year
+%b - abbreviated month
+%B - Fullname of the month
+%a - Abbreviated weekday 
+%A - Abbreviated Full Name Weekday
 
6. logname - displays the username
 
7. hostname - displays the hostname(server name)
 
8. man - similar to help
 
9. ls - displays all the directories and files in your current working directory
 
   ls -R  - display all the directories, files and subdirectories in your current working directory
      -l  - long list 
      -r  - reverse order
      -lr - long list in reverse order
      -t  - timestamp wise
      -lt
      -ltr or -lrt
      -a  - all files including hidden files 
      -P* - display directories starting with P
 
10. passwd - change the password
 
11. history - It will display all unix commands you used till date
    ! - can be used to get the previous commands
        !
 
12 mkdir - make a directory
   mkdir
 
13. cd -- change directory
    cd ..       - takes one step back 
    cd ../..    - 2 steps back
    cd f1/f2/f3 - 3 steps forward 
    cd ../f1    - 1 step back and 1 step forward
    cd /        - comes out of the home folder
    cd -        - Takes you to the last working directory
 
14. touch - creates a empty file with the current timestamp
       touch
    touch -t - changes the file to a specific time
       touch -t yymmddhhmm  
       - yymmddhhmm - yearmonthdatehourmin
 
15. cat - Displays content of a existing file or create a new file
cat - display content of the file 
cat > - creates a newfile or opens up a existing file for editing and all the existing data in 
  that file will be overwrited by the new file
cat >> - adds the data to the existing data or creates a new file
cat > - File1 data will be overwritten to File 2 data
cat >> - File 1 data will be added to the File 2 data 
 
16. cp - copies files and copied files have new timestamp
cp -p - copies files with the same timestamp
cp -i - will ask the permission to be over written or not
 
17. mv - rename the file
mv oldfilename newfile
 
18. chmod - change the permissions of a file
read    - 4
write   - 2
execute - 1
 
read - r user - u all - a
write - w group - g
execute - x others - o
 
+ Add permission
- Remove permission
= Assign Permission
 
     user group others
7    5   4
$ chmod 754 pr1
 
pr1 r-x rwx r--   ----> permissions
 
$ chmod u+w pr1
pr1 rwx rwx r--   ----> permissions
 
$ chmod g-w pr1
pr1 rwx r-x r--   ----> permissions
 
$ chmod u=rwx pr1
$ chmod u=rwx,g=rx pr1
 
19. rm - removes files
rm
rm * - removes all the files starting with that letter
 
20. rmdir - removes directories
rmdir -  removes empty directory 
rm -r - removes directory and the content inside it
rm -ir - asks for confirmation
 
21. file - displays what type of file 
$ file
 
22. head - displays number of lines from top
$ head -5 - displays first 5 lines
 
23. tail - displays number of lines from bottom
$ tail -3 - displays last 3 lines
 
24. link - links one file to another file. 
- you can always link to new file you cannot link to existing file.
$ link
 
25. find - finds the files and directories 
$ find . -name '' -print
. - specifies the working folder
-name - syntax that says we are searching a name
- specifies the name you are searching in the folder 
-print - prints the output in the window 
or
 
$ find /home/krishnatraining1 -name '' -print
 
$ find . -name '' -type f -print --> displays files with this name
$ find . -name '' -type d -print --> displays directories with this name
$ find . '*.txt' -print --> displays all the .txt files in the working folder
$ find . '*.jpeg' -print 
 
26. comm - compares two files and displays the common values in one line and unmatched records in another line
 
$ comm
 
 
27. cmp - compares both the files and returns no data if both the files are equal.
 
$ cmp  
 
28. sort - will sort the data in the file
 
$ sort     - Ascending
$ sort -r  - Descending
$ sort -n  - Sorting on the numbers
$ sort -t ';' -k2 - sorting delimeted files
    -k2 - specifes sorting on columns
$ sort -k2 - if the file is a tab delimited file
 
29. wc - counts of lines, words or letters(characters)
 
$ wc -l - Count of lines in the file
$ wc -w - Count of Words in the file
$ wc -c - Count of characters(letters) in the file
 
30. FTP - File Transfer Protocol
 
30. $ ftp - Command to log into the remote server
   ftp cd  - when logged in remote server 'cd' will change folders in remote server
31. ftp lcd - when logged in remote server 'lcd' will change folders in local server
32. ftp lpwd - displays the local machine path
33. ftp put - copies files from local to remote server 
34. ftp get - copies files from remote to local machine
35. ftp bye - logging out of remote server
 
$ pwd
- /home/main
$ ftp userx/password @ xyz
ftp pwd
- /x
ftp cd y/z
ftp pwd
- /x/y/z
ftp lcd b/b1
ftp put customer.txt
ftp cd ../..
ftp lcd ../b2
ftp get x.txt
ftp cd y/z
ftp lcd ../../c/c1
ftp get z.txt
ftp bye
 
36. diff - compare two files and display difference in details. It gives no output if both the files are equal
 
$ diff
a - added 
c - changed
d - deleted
 
37. printenv - Prints all the environmental variables
 
$ printenv
 
38. echo - displays the text 
 
$ echo
 
39. sleep - it allows the system to sleep for specified time 
 
$ sleep 5s - seconds
$ sleep 5m - minutes
$ sleep 5h - hours
$ sleep 5& - sleep process running in background
 
40. ps - it shows all the processes running and gives the information related that process - PID (Process ID)
 
$ ps
 
41. fg - it brings the process to foreground
   
$ fg % ProcessID
 
42. bg - it brings the process to background 
 
$ bg % ProcessID
 
43. kill - completly kills the process - force kill until the root
 
$ kill -9 ProcessID
 
44. nohup - no hangup, makes the process run on the server
 - process runs in background
$ nohup ProcessID
 
45. cut - to displays specific columns
- can be used for all the delimiters
 
$ cut -f c1,c2...
 - by default this command will execute for tab delimited file
$ cut -f c1,c2,.. -d ';'
 - for a ';' delimited file
 
46. gzip - will compress the file (similar to winzip)
- original file will be replaced with the zipped file
 
$ gzip  
 
47. gunzip - will uncompress the file
 
$ gunzip
 
48. zcat - display the contents of a compressed file (zipped)
 
$ zcat
 
49. more - allows you to read long documents
 
$ more
enter - next line
space - next page
q     - quit 
 
50. less - allows you to read the documents in smaller compressed window
 
$ less
enter - next line
space - next page
q     - quit 
 
51. grep - globally searches the complete file for a word or a phrase and prints
 
$ grep 'search_phrase'
- will display all the lines that has the search_phrase
 
$ grep -w 'search_phrase'
- will display all the lines considering search_phrase as a word.
 
$ grep -i 'search_phrase'
- Makes the search case sensitive independent
 
$ grep -v 'search_phrase'
- Displays all the lines that doesn't have the search+phrase
 
$ grep -n 'search_phrase'
- Displays all the line that has the search_phrase with the line numbers
 
$ grep '^I'
- displays all the lines starting with 'I'
 
$ grep -i '^I'
- displays all the lines starting with 'I' and makes it case sensitve independent
 
$ grep 'I$'
- displays all the lines ending with 'I'
 
$ grep '^IS$'
- all the lines starts and ends with 'IS'
 
$ grep '^$'
- Displays the null value lines
 
$ grep '^..$'
- Display any line that has two characters
 
52. mail - helps to email the recepient
 
$ mail -s 'HELLO' abc@abc.com --> subject
$ mail -c  --> cc
$ mail -b  --> bcc
$ mail -a  --> attach a file
 
53. split - it helps to split the big file into multiple small files
 
$ split
- by default it splits the lines in 1000 lines interval
 
$ split -l2000
 
$ split -d
- display number instead of alphabets
 
54. whoami - shows the current user name
 
$ whoami
 
55. uname - gives the processor and computer details
 
$ uname
$ uname -a
 
56. uniq - this is a unix untility that collapes or merges identical rows into a single row
         - Always provide sorted input into the uniq command
 
$ uniq
$ uniq -i - removes case sensitivity
$ uniq -c - count of each row
$ uniq -d - display duplicate rows
$ uniq -u - diaplay only unique rows
 
 '|' - pipe operator --> can be used to give input for the next statement
 ';' --> it seperates the commands
 
57. sed - stream editor
 
$ sed -n r1,r2..p
- displays the lines r1, r2
 
$ sed s/is/was/g
- replaces the existing string with a new string
 
UNIX CLASS NOTES

UNIX ---- To log into any computer on network you need  1. host name 2. user name 3. password     putty.exe - it connects to another unix machine in the network.   1 bit 8 bit = 1 byt...  


  download putty.exe file to connect to the unix server using t...  


Location of System logs The "/etc/rsyslog.conf" file defin...  


http://www.ee.surrey.ac.uk/Teaching/Unix/unixintro.html


6

 

UNIX Introduction

What is UNIX?

UNIX® License PlateUNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since. By operating system, we mean the suite of programs which make the computer work. It is a stable, multi-user, multi-tasking system for servers, desktops and laptops.

UNIX systems also have a graphical user interface (GUI) similar to Microsoft Windows which provides an easy to use environment. However, knowledge of UNIX is required for operations which aren't covered by a graphical program, or for when there is no windows interface available, for example, in a telnet session.

Types of UNIX

The Linux PenguinThere are many different versions of UNIX, although they share common similarities. The most popular varieties of UNIX are Sun Solaris, GNU/Linux, and MacOS X.

Here in the School, we use Solaris on our servers and workstations, and Fedora Linux on the servers and desktop PCs.

The UNIX operating system

The UNIX operating system is made up of three parts; the kernel, the shell and the programs.

The kernel

The kernel of UNIX is the hub of the operating system: it allocates time and memory to programs and handles the filestore and communications in response to system calls.

As an illustration of the way that the shell and the kernel work together, suppose a user types rm myfile (which has the effect of removing the file myfile). The shell searches the filestore for the file containing the program rm, and then requests the kernel, through system calls, to execute the program rm on myfile. When the process rm myfile has finished running, the shell then returns the UNIX prompt % to the user, indicating that it is waiting for further commands.

The shell

The shell acts as an interface between the user and the kernel. When a user logs in, the login program checks the username and password, and then starts another program called the shell. The shell is a command line interpreter (CLI). It interprets the commands the user types in and arranges for them to be carried out. The commands are themselves programs: when they terminate, the shell gives the user another prompt (% on our systems).

The adept user can customise his/her own shell, and users can use different shells on the same machine. Staff and students in the school have the tcsh shell by default.

The tcsh shell has certain features to help the user inputting commands.

Filename Completion - By typing part of the name of a command, filename or directory and pressing the [Tab] key, the tcsh shell will complete the rest of the name automatically. If the shell finds more than one name beginning with those letters you have typed, it will beep, prompting you to type a few more letters before pressing the tab key again.

History - The shell keeps a list of the commands you have typed in. If you need to repeat a command, use the cursor keys to scroll up and down the list or type history for a list of previous commands.

 

Files and processes

Everything in UNIX is either a file or a process.

A process is an executing program identified by a unique PID (process identifier).

A file is a collection of data. They are created by users using text editors, running compilers etc.

Examples of files:

  • a document (report, essay etc.)
  • the text of a program written in some high-level programming language
  • instructions comprehensible directly to the machine and incomprehensible to a casual user, for example, a collection of binary digits (an executable or binary file);
  • a directory, containing information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files.

 

The Directory Structure

All the files are grouped together in the directory structure. The file-system is arranged in a hierarchical structure, like an inverted tree. The top of the hierarchy is traditionally called root (written as a slash / )

Unix File Structure

In the diagram above, we see that the home directory of the undergraduate student "ee51vn" contains two sub-directories (docs and pics) and a file called report.doc.

The full path to the file report.doc is "/home/its/ug1/ee51vn/report.doc"

Starting an UNIX terminal

To open an UNIX terminal window, click on the "Terminal" icon from Applications/Accessories menus.

Gnome Menus

 

An UNIX Terminal window will then appear with a % prompt, waiting for you to start entering commands.

Unix Terminal window

 

UNIX COMMANDS

  UNIX Introduction What is UNIX? UNIX is an operating system which was first developed in the 1960s, and has been under constant development ever since. By operating system, we mean the suite of programs which make the computer w...  


PUTTY DOWNLOAD LINK http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe Introduction to the UNIX Operating System What is UNIX? Files and processes The Directory Structure Starting an UNIX terminal &nbs...  


8

Awk command

awk -- it allows the user to manipulate files that are structured as columns of data and strings, JUST SEE THE FIRST EXAMPLE U WILL GET IDEA

Example 1:
Assume you want to process a file called file 'dimensions' that has the following content:

12 8
15 24
9 12

Assume you want to generate a file 'area' that has the same content as the file 'dimensions', but has one more column that contains the product of the two numbers on each line:

12 8 96
15 24 360
9 12 108

The following command would accomplish that:

awk '{print $0, $1*$2}' dimenions > area

 awk -- it allows the user to manipulate files that are structured as columns of data and strings. (--continued after the ads...)

Once you understand the basics of awk you will find that it is surprisingly useful. You can use it to automate things in ways you have never thought about. It can be used for data processing and for automating the application of Linux / Unix commands. It also has many spreadsheet-type functionalities.

There are two ways to run awk:

  1. A simple awk command can be run from the command line.
  2. More complex tasks should be written as awk programs ("scripts") to a file. Examples of each are provided below. A simple awk command is of the form

% awk 'pattern {action}' input-file > output-file

meaning: take each line of the input file; if the line contains the pattern apply the action to the line and write the resulting line to the output-file.

If the pattern is omitted, the action is applied to all lines:

% awk '{action}' input-file > output-file

By default, awk works on files that have columns of numbers or strings that are separated by white space (tabs or spaces), but the -F option can be used if the columns are separated by another character. awk refers to the first column as $1, the second column as $2, etc. The whole line referred to as $0.

Example 1:

Assume you want to process a file called file 'dimensions' that has the following content:

12 8
15 24
9 12

Assume you want to generate a file 'area' that has the same content as the file 'dimensions', but has one more column that contains the product of the two numbers on each line:

12 8 96
15 24 360
9 12 108

The following command would accomplish that:

awk '{print $0, $1*$2}' dimenions > area

The term {print $0, $1*$2} means: first print the whole line ($0), then print the product of the number in column 1 ($1) and the number in column 2 ($2).

Example 2:

If you want the output file to contain only those lines on which the first number is less than the second number, you would use the following command:

awk '$1 < $2 {print $0, $1*$2}' dimenions > area2

The contents of file area2 would then be:

15 24 360
9 12 108

Example 3:

The following command does exactly the same as the command in Example 2, but it illustrates how awk can be combined with other Unix commands:

cat dimenions | awk '$1 < $2 {print $0, $1/$2}' > area2

Used by itself, the command 'cat dimenions' simply prints the contents of file 'dimenions' to the sceen. However, if a command is followed by a '|' (called "pipe"), the contents goes as input to command to the right of the '|'.

Example 4:

Assume you have hundreds of files you want to move into a new directory and rename them by appending a .new to the filenames. Assume all the files have names that start with "data", they need to be moved to ../newdata, and need to have a '.new' appended to the name. Use the following command to accomplish this:

ls data* | awk '{print "mv "$0" ../newdata/"$0".new"}' | csh

ls data* lists the filenames. This output list is then "piped" into awk. Since there is no pattern specified, awk proceeds to print something for each line. For example, if the first two lines from 'ls data*' produced data1 and data2, respectively, then awk would print:

mv data1 ../newdata/data1.new
mv data2 ../newdata/data2.new

These are Unix commands that are executed by piping them into the "csh" command ("csh" is an operating system shell).

More complex awk scripts need to be run from a file. The syntax for such cases is:

cat file-1 | awk -f script-1.awk > file-2

where file-1 is the input file, file-2 is the output file, and script-1.awk is a file containing awk commands. awk scripts that contain more than one line need to be run from files. The following example is an awk-script that would saved in a file (e.g, script-1.awk) and executed by the above command.

Example 5:

The following awk-script prints frequency a histogram of the first column of the input file (assumed to contain numbers):

($1 > 0.1) && ($1 <= 0.2) {num_b = num_b+1}
($1 > 0.2) && ($1 <= 0.3) {num_c = num_c+1}
($1 > 0.3) && ($1 <= 0.4) {num_d = num_d+1}
($1 > 0.4) && ($1 <= 0.5) {num_e = num_e+1}
($1 > 0.5) && ($1 <= 0.6) {num_f = num_f+1}
($1 > 0.6) && ($1 <= 0.7) {num_g = num_g+1}
($1 > 0.7) {num_h = num_h+1}
END {print num_a, num_b, num_c, num_d, num_e, num_f, num_g, num_h}

Note that each line contains an instruction of the form pattern {action}. All instructions are executed sequentially. The "pattern" 'END' is satisfied when the end of the input file is reached.

Other useful awk-variables are:
· NF: number of columns;
· NR: the current line that awk is working on;
· BEGIN: satisfied before anything is read;
· length: number of characters in a line or a string;

awk also provides looping capability, a search (/) command, a substring command, and formatted printing. It provides the logical operators || (or) and && (and) that can be used in specifying patterns. You can define variables and assign values to them.

 

AWK COMMAND IN UNIX

Awk command awk -- it allows the user to manipulate files that are structured as columns of data and strings, JUST SEE THE FIRST EXAMPLE U WILL GET IDEA Example 1: Assume you want to process a file called file 'dimensions' that h...  


9

Unix commands

Man ual command.
man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example.

  • man ls will explain about the ls command and how you can use it.
  • man -k pattern command will search for the pattern in given command.

Banner command.
banner prints characters in a sort of ascii art poster, for example to print wait in big letters. I will type
banner wait at unix command line or in my script. This is how it will look.

 

#    #    ##       #     #####

#    #   #  #      #       #

#    #  #    #     #       #

# ## #  ######     #       #

##  ##  #    #     #       #

#    #  #    #     #       #

 


Cal command
cal command will print the calander on current month by default. If you want to print calander of august of 1965. That's eightht month of 1965.
cal 8 1965 will print following results.

August 1965

S  M Tu  W Th  F  S

1  2  3  4  5  6  7

8  9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31


Clear command

clear command clears the screen and puts cursor at beginning of first line.


Calendar command
calendar command reads your calendar file and displays only lines with current day.
For example in your calendar file if you have this

12/20   Test new software.

1/15    Test newly developed 3270 product.

1/20    Install memory on HP 9000 machine.

On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.


Nohup command.
nohup command if added in front of any command will continue running the command or process even if you shut down your terminal or close your session to machine. For exmaple, if I want to run a job that takes lot of time and must be run from terminal and is called update_entries_tonight .
nohup update_entries_tonight will run the job even if terminal is shut down in middle of this job.


Tty command
Tty command will display your terminal. Syntax is
tty options

Options

  • -l will print the synchronous line number.
  • -s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)


File Management commands.


Pwd command.
pwd command will print your home directory on screen, pwd means print working directory.

/u0/ssb/sandeep

is output for the command when I use pwd in /u0/ssb/sandeep directory.


Ls command
ls command is most widely used command and it displays the contents of directory.

options

  • ls will list all the files in your home directory, this command has many options.
  • ls -l will list all the file names, permissions, group, etc in long format.
  • ls -a will list all the files including hidden files that start with . .
  • ls -lt will list all files names based on the time of creation, newer files bring first.
  • ls -Fxwill list files and directory names will be followed by slash.
  • ls -Rwill lists all the files and files in the all the directories, recursively.
  • ls -R | more will list all the files and files in all the directories, one page at a time.

Mkdir command.
mkdir sandeep will create new directory, i.e. here sandeep directory is created.


Cd command.
cd sandeep will change directory from current directory to sandeep directory.
Use pwd to check your current directory and ls to see if sandeep directory is there or not.
You can then use cd sandeep to change the directory to this new directory.


Cat command
cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).


Head command.
head filename by default will display the first 10 lines of a file.
If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so forth.


Tail command.
tail filename by default will display the last 10 lines of a file.
If you want last 50 lines then you can use tail -50 filename.


More command. more command will display a page at a time and then wait for input which is spacebar. For example if you have a file which is 500 lines and you want to read it all. So you can use

more filename


Wc command
wc command counts the characters, words or lines in a file depending upon the option.

Options

  • wc -l filename will print total number of lines in a file.
  • wc -w filename will print total number of words in a file.
  • wc -c filename will print total number of characters in a file.

File command.
File command displays about the contents of a given file, whether it is a text (Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of current month and I have resume1.doc file which is a binariy file in microsoft word. I will get
file resume.doc

resume1.doc:    data

file cal.txt

cal.txt:        ascii text


Cp command.
cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory.
cp oldfile newfile
If I want to copy oldfile to other directory for example /tmp then
cp oldfile /tmp/newfile. Useful options available with cp are -p and -r . -p options preserves the modification time and permissions, -r recursively copy a directory and its files, duplicating the tree structure.


Rcp command.
rcp command will copy files between two unix systems and works just like cp command (-p and -i options too).
For example you are on a unix system that is called Cheetah and want to copy a file which is in current directory to a system that is called lion in /usr/john/ directory then you can use rcp command
rcp filename lion:/usr/john
You will also need permissions between the two machines. For more infor type man rcp at command line.


Mv command.
mv command is used to move a file from one directory to another directory or to rename a file.

Some examples:

  • mv oldfile newfile will rename oldfile to newfile.
  • mv -i oldfile newfile for confirmation prompt.
  • mv -f oldfile newfile will force the rename even if target file exists.
  • mv * /usr/bajwa/ will move all the files in current directory to /usr/bajwa directory.

Ln command.
Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called coolfile in /usr/local/bin directory then you can enter this command.
ln mycoolfile /usr/local/bin/coolfile

Some examples:

  • ln -s fileone filetwo will create a symbolic link and can exist across machines.
  • ln -n option will not overwrite existing files.
  • ln -f will force the link to occur.

Rm command.
To delete files use rm command.

Options:

  • rm oldfile will delete file named oldfile.
  • rm -f option will remove write-protected files without prompting.
  • rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.

Rmdir command.
rmdir command will remove directory or directories if a directory is empty.

Options:

  • rm -r directory_name will remove all files even if directory is not empty.
  • rmdir sandeep is how you use it to remove sandeep directory.
  • rmdir -p will remove directories and any parent directories that are empty.
  • rmdir -s will suppress standard error messages caused by -p.


Comparison and Searching


Diff command.
diff command will compare the two files and print out the differences between.
Here I have two ascii text files. fileone and file two.
Contents of fileone are

This is first file

this is second line

this is third line

this is different    as;lkdjf

this is not different
filetwo contains

This is first file

this is second line

this is third line

this is different    xxxxxxxas;lkdjf

this is not different
diff fileone filetwo will give following output

4c4

< this is different    as;lkdjf

---

> this is different    xxxxxxxas;lkdjf


Cmp command.
cmp command compares the two files. For exmaple I have two different files fileone and filetwo.
cmp fileone filetwo will give me

fileone filetwo differ: char 80, line 4
if I run cmp command on similar files nothing is returned.
-s command can be used to return exit codes. i.e. return 0 if files are identical, 1 if files are different, 2 if files are inaccessible.
This following command prints a message 'no changes' if files are same
cmp -s fileone file1 && echo 'no changes' .

no changes


Dircmp Command.
dircmp command compares two directories. If i have two directories in my home directory named
dirone and dirtwo and each has 5-10 files in it. Then
dircmp dirone dirtwo will return this

Dec  9 16:06 1997  dirone only and dirtwo only Page 1

./cal.txt                                   ./fourth.txt

./dohazaar.txt                              ./rmt.txt

./four.txt                                  ./te.txt

./junk.txt                                  ./third.txt

./test.txt


Grep Command
grep command is the most useful search command. You can use it to find processes running on system, to find a pattern in a file, etc. It can be used to search one or more files to match an expression.
It can also be used in conjunction with other commands as in this following example, output of ps command is passed to grep command, here it means search all processes in system and find the pattern sleep.
ps -ef | grep sleep will display all the sleep processes running in the system as follows.

ops 12964 25853  0 16:12:24 ttyAE/AAES  0:00 sleep 60

dxi 12974 15640  0 16:12:25 ttyAH/AAHP  0:00 sleep 60

ops 12941 25688  0 16:12:21 ttyAE/AAEt  0:00 sleep 60

ops 12847 25812  0 16:11:59 ttyAH/AAH6  0:00 sleep 60

ops 12894 25834  0 16:12:12 ttyAE/AAEX  0:00 sleep 60

dxi 13067 27253  2 16:12:48 ttyAE/ABEY  0:00 sleep 1

ops 13046 25761  0 16:12:44 ttyAE/AAE0  0:00 sleep 60

dxi 12956 13078  0 16:12:23 ttyAG/AAG+  0:00 sleep 60

ops 12965 25737  0 16:12:24 ttyAE/AAEp  0:00 sleep 60

ops 12989 25778  0 16:12:28 ttyAH/AAHv  0:00 sleep 60

ssb 13069 26758  2 16:12:49 ttyAH/AAHs  0:00 grep sleep

pjk 27049  3353  0 15:20:23 ?           0:00 sleep 3600

Options:

  • -b option will precede each line with its block number.
  • -c option will only print the count of matched lines.
  • -i ignores uppercase and lowercase distinctions.
  • -l lists filenames but not matched lines.

other associated commands with grep are egrep and fgrep. egrep typically runs faster. for more information type man egrep or man fgrep in your system.


Find command.
Find command is a extremely useful command. you can search for any file anywhere using this command provided that file and directory you are searching has read write attributes set to you ,your, group or all. Find descends directory tree beginning at each pathname and finds the files that meet the specified conditions. Here are some examples.

Some Examples:
find $HOME -print will lists all files in your home directory.
find /work -name chapter1 -print will list all files named chapter1 in /work directory.
find / -type d -name 'man*' -print will list all manpage directories.
find / -size 0 -ok rm {} ; will remove all empty files on system.

conditions of find

  • -atime +n |-n| n will find files that were last accessed more than n or less than -n days or n days.
  • -ctime +n or -n will find that were changed +n -n or n days ago.
  • -depth descend the directory structure, working on actual files first and then directories. You can use it with cpio command.
  • -exec commad {} ; run the Unix command on each file matched by find. Very useful condition.
  • -print print or list to standard output (screen).
  • -name pattern find the pattern.
  • -perm nnnfind files whole permission flags match octal number nnn.
  • -size n find files that contain n blocks.
  • -type c Find file whole type is c. C could be b or block, c Character special file, d directory, p fifo or named pipe, l symbolic link, or f plain file.

Text processing


Cut command.
cut command selects a list of columns or fields from one or more files.
Option -c is for columns and -f for fields. It is entered as
cut options [files]
for example if a file named testfile contains

this is firstline

this is secondline

this is thirdline

Examples:
cut -c1,4 testfile will print this to standard output (screen)

ts

ts

ts

It is printing columns 1 and 4 of this file which contains t and s (part of this).

Options:

  • -c list cut the column positions identified in list.
  • -f list will cut the fields identified in list.
  • -s could be used with -f to suppress lines without delimiters.

Paste Command.
paste command merge the lines of one or more files into vertical columns separated by a tab.
for example if a file named testfile contains

this is firstline

and a file named testfile2 contains

this is testfile2

then running this command
paste testfile testfile2 > outputfile
will put this into outputfile

this is firstline       this is testfile2

it contains contents of both files in columns.
who | paste - - will list users in two columns.

Options:

  • -d'char' separate columns with char instead of a tab.
  • -s merge subsequent lines from one file.

Sort command.
sort command sort the lines of a file or files, in alphabetical order. for example if you have a file named testfile with these contents

zzz

aaa

1234

yuer

wer

qww

wwe

Then running
sort testfile
will give us output of

1234

aaa

qww

wer

wwe

yuer

zzz

Options:

  • -b ignores leading spaces and tabs.
  • -c checks whether files are already sorted.
  • -d ignores punctuation.
  • -i ignores non-printing characters.
  • -n sorts in arithmetic order.
  • -ofile put output in a file.
  • +m[-m] skips n fields before sorting, and sort upto field position m.
  • -r reverse the order of sort.
  • -u identical lines in input file apear only one time in output.

Uniq command.
uniq command removes duplicate adjacent lines from sorted file while sending one copy of each second file.
Examples

sort names | uniq -d will show which lines appear more than once in names file.

Options:

  • -c print each line once, counting instances of each.
  • -d print duplicate lines once, but no unique lines.
  • -u print only unique lines.

Awk and Nawk command.
awk is more like a scripting language builtin on all unix systems. Although mostly used for text processing, etc.
Here are some examples which are connected with other commands.
Examples:
df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1000000}' Will give total space in your system in megabytes.
Here the output of command df -t is being passed into awk which is counting the field 1 after pattern "total" appears. Same way if you change $1 to $4 it will accumulate and display the addition of field 4
which is used space.
for more information about awk and nawk command in your system enter man awk or man nawk.


Sed command.
sed command launches a stream line editor which you can use at command line.
you can enter your sed commands in a file and then using -f option edit your text file. It works as
sed [options] files

options:

  • -e 'instruction' Apply the editing instruction to the files.
  • -f script Apply the set of instructions from the editing script.
  • -n suppress default output.

for more information about sed, enter man sed at command line in your system.


Vi editor.
vi command launches a vi sual editor. To edit a file type
vi filename
vi editor is a default editor of all Unix systems. It has several modes. In order to write characters you will need to hit i to be in insert mode and then start typing. Make sure that your terminal has correct settings, vt100 emulation works good if you are logged in using pc.
Once you are done typing then to be in command mode where you can write/search/ you need to hit :w filename to write
and in case you are done writing and want to exit
:w! will write and exit.

options:

  • i for insert mode.
    • I inserts text at the curson
    • A appends text at the end of the line.
    • a appends text after cursor.
    • O open a new line of text above the curson.
    • o open a new line of text below the curson.
  • : for command mode.
    • to invoke command mode from insert mode.
    • :!sh to run unix commands.
    • x to delete a single character.
    • dd to delete an entire line
    • ndd to delete n number of lines.
    • d$ to delete from cursor to end of line.
    • yy to copy a line to buffer.
    • P to paste text from buffer.
    • nyy copy n number of lines to buffer.
    • :%s/stringA/stringb /g to replace stringA with stringB in whole file.
    • G to go to last line in file.
    • 1G to go to the first line in file.
    • w to move forward to next word.
    • b to move backwards to next word.
    • $ to move to the end of line.
    • J join a line with the one below it.
  • /string to search string in file.
  • n to search for next occurence of string.


Shell and programming

 


Shell programming concepts and commands.
Shell programming is integral part of Unix operating systems. Shell is command line userinterface to Unix operating system, User have an option of picking an interface on Unix such as ksh, csh, or default sh., these are called shells(interface). Shell programming is used to automate many tasks. Shell programming is not a programming language in the truest sense of word since it is not compiled but rather an interpreted language. Unix was written in C language and thus c language is integral part of unix and available on all versions. Shells, like ksh and csh are popular shells on unix although there are 5 or 6 different shells available but I will only be discussing ksh and csh as well as sh. Common features among all shells are job control, for example if I am running a processes which is searching the whole system for .Z files and output is directed to a file named compressedfiles.

example:

  • find / -name *.Z -print > compressedfiles
    then after entering this command hitting

  • key will suspend this job, then entering
  • bg
    at command line will put this job in background, entering
  • fg
    will put this job in foreground. Entering
  • jobs
    at command line will show me all my concurrent jobs that are running.

Other common features

    • > will redirect output from standard out (screen) to file or printer or whatever you like.
    • >> filename will append at the end of a file called filename.
    • < will redirect input to a process or commnand.
    • | pipe output, or redirect output, good for joining commands, i.e. find command with cpio, etc.
    • & at the end of command will run command in background.
    • ; will separate commands on same line.
    • * will match any characters in a file or directories. junk* will match all files with first 4 letters
    • ? will match single characters in a file.
    • [] will match any characters enclosed.
    • () execute in subshell.
    • ` ` to run a command inside another command and use its output.
    • " " partial quote for variables.
    • ' ' full quote for variables.
    • # begin comment (if #/bin/ksh or csh or sh is entered at first line of script it runs script in that shell)
    • bg background execution.
    • break break from loop statements.
    • continue Resume a program loop.
    • Kill pid number will terminate running jobs
    • stop will stop background job.
    • suspend will suspend foreground job.
    • wait will wait for a background job to finish.

Bourne Shell (sh shell).
sh or Bourne shell is default shell of Unix operating systems and is the most simplest shell in Unix systems.

Examples:

  • cd; ls execute one after another.
  • (date;who;pwd)> logifile will redirect all the output from three commands to a filenamed logfile.
  • sort file | lp will first sort a file and then print it.
  • alias [options] [name[='command']] will let you create your own commands. i.e.
    • alias ll="ls -la" will execute `ls -la` command whenever ll is entered.
  • let expressions is syntax of let statement.
    • let i=i+1 will work as a counter with i incrementing each time this statement is encountered.
  • for x[in list] do commands done is syntax for for do loop.
  • function name {commands;} is the syntax of a function which can be called from anywhere in program.
  • if condition1 then commands1 elif condition2 then commands2 ... ... ... else commands3 fi

Ksh shell (Korn).
Ksh or Korn shell is widely used shell.


Csh or C shell
csh is second most used shell.


Echo command
echo command in shell programming.


Line command.
line command in shell programming.


Sleep command.
sleep command in shell programming.


Test Command.
test command in shell programming.


CC compiler (c programming language compiler).
Since Unix is itself written in C programming language, most Unix operating systems come with c compiler called cc.



Communications

 


Cu command.
cu command is used for communications over a modem or direct line with another Unix system.
Syntax is
cu options destination

Options

  • -bn process lines using n-bit characters (7 or 8).
  • -cname Search UUCP's device file and select local area network that matches name.
  • -d Prints diagnostics.
  • -e sends even parity data to remote system
  • -lline communicate on this device (line=/dev/tty001, etc)
  • -n prompts for a telephone number.
  • -sn set transmission rate to n(e.g 1200,2400,9600, BPS)

Destination

  • telno is the telephone number of the modem to connect to.
  • system is call the system known to uucp.
  • aadr is an address specific to LAN.

Ftp command (protocol).
ftp command is used to execute ftp protocol using which files are transferred over two systems.
Syntax is
ftp options hostname

options

  • -d enable debugging.
  • -g disable filename globbing.
  • -i turn off interactive prompts.
  • -v verbose on. show all responses from remote server.

ftp hostname by default will connect you to the system, you must have a login id to be able to transfer the files. Two types of files can be transferred, ASCII or Binary. bin at ftp> prompt will set the transfer to binary. Practice FTP by ftping to nic.funet.fi loggin in as anomymous with password being your e-mail address.


Login command.
login command invokes a login session to a Unix system, which then authenticates the login to a system. System prompts you to enter userid and password.


Rlogin command.
rlogin command is used to log on to remote Unix systems, user must have permissions on both systems as well as same userid, or an id defined in .rhosts file. Syntax is
rlogin options host

options

  • -8 will allow 8 bit data to pass, instead of 7-bit data.
  • -e c will let you use escape character c.
  • -l user will let you to login as user to remote host, instead of same as local host.

Talk command.
talk command is used to invoke talk program available on all unix system which lets two users exchange information back and forth in real time. Syntax is
talk userid@hostname


Telnet command.
Telnet command invokes a telnet protocol which lets you log on to different unix, vms or any machine connected over TCP/IP protocol, IPx protocol or otherwise. Syntax is
telnet hostname


Vacation command.
vacation command is used when you are out of office. It returns a mail message to sender announcing that you are on vacation. to disable this feature, type mail -F " " .
syntax is
vacation options

Options

  • -d will append the date to the logfile.
  • -F user will forward mail to user when unable to send mail to mailfile.
  • -l logfile will record in the logfile the names of senders who received automatic reply.
  • -m mailfile will save received messages in mailfile.

Write command will initiate an interactive conversation with user. Syntax is
write user tty


 


Storage commands


Compress command.
Compress command compresses a file and returns the original file with .z extension, to uncompress this filename.Z file use uncompress filename command. syntax for compress command is
compress options files

Options

  • -bn limit the number of bits in coding to n.
  • -c write to standard output (do not change files).
  • -f compress conditionally, do not prompt before overwriting files.
  • -v Print the resulting percentage of reduction for files.

Uncompress command.
Uncompress file uncompresses a file and return it to its original form.
syntax is
uncompress filename.Z this uncompresses the compressed file to its original name.

Options

  • -c write to standard output without changing files

Cpio command.
cpio command is useful to backup the file systems. It copy file archives in from or out to tape or disk, or to another location on the local machine. Its syntax is
cpio flags [options]

It has three flags, -i, -o, -p

  • cpio -i [options] [patterns]
    • cpio -i copy in files who names match selected patterns.
    • If no pattern is used all files are copied in.
    • It is used to write to a tape.

cpio -o

    • Copy out a list of files whose name are given on standard output.

cpio -p

    • copy files to another directory on the same system.

Options

    • -a reset access times of input files.
    • -A append files to an archive (must use with -o).
    • -b swap bytes and half-words. Words are 4 bytes.
    • -B block input or output using 5120 bytes per record.
    • -c Read or write header information as Ascii character.
    • -d create directories as needed.
    • -l link files instead of copying.
    • -o file direct output to a file.
    • -r rename files interactively.
    • -R ID reassign file ownership and group information to the user's login ID.
    • -V print a dot for each file read or written.
    • -s swap bytes.
    • -S swap half bytes.
    • -v print a list of filenames.

Examples

    • find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old files to a tape in /dev/rst8
    • cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain "save"
    • find . -depth -print | cpio -padm /mydir will move a directory tree.

Dump command is useful to backup the file systems.
dump command copies all the files in filesystem that have been changed after a certain date. It is good for incremental backups. This information about date is derived from /var/adm/dumpdates and /etc/fstab .
syntax for HP-UX dump is
/usr/sbin/dump [option [argument ...] filesystem]

Options

  • 0-9 This number is dump level. 0 option causes entire filesystem to be dumped.
  • b blocking factor taken into argument.
  • d density of tape default value is 1600.
  • f place the dump on next argument file instead of tape.
  • This example causes the entire file system (/mnt) to be dumped on /dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI.
    • /usr/sbin/dump 0df 6250 /dev/rmt/c0t0d0BEST /mnt
  • for more info type man dump at command line.

Pack command.
pack command compacts each file and combine them together into a filename.z file. The original file is replaced. Pcat and unpack will restore packed files to their original form.
Syntax is
Pack options files

Options

  • - Print number of times each byte is used, relative frequency and byte code.
  • -f Force the pack even when disk space isn't saved.
  • To display Packed files in a file use pcat command
    pcat filename.z
  • To unpack a packed file use unpack command as unpack filename.z .

Tar command.
tar command creates an archive of files into a single file.
Tar copies and restore files to a tape or any storage media. Synopsis of tar is
tar [options] [file]

Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it in file backup.tar.

Functions:

  • c creates a new tape.
  • r append files to a tape.
  • t print the names of files if they are stored on the tape.
  • x extract files from tape.

Options:

  • b n use blocking factor of n.
  • l print error messages about links not found.
  • L follow symbolic links.
  • v print function letter (x for extraction or a for archive) and name of files.

Mt command

Mt command is used for tape and other device functions like rewinding, ejecting, etc. It give commands to tape device rather than tape itself. Mt command is BSD command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]

mt for HP-UX accept following commands

  • eof write count EOF marks.
  • fsf Forward space count files.
  • fsr Forward space count records.
  • bsf Backward space count files.
  • bsr Backward space count records.
  • rew Rewind tape.
  • offl Rewind tape and go offline.
  • eod Seek to end of data (DDS and QIC drives only).
  • smk Write count setmarks (DDS drives only).
  • fss Forward space count setmarks (DDS drives only).
  • bss Backward space count setmarks (DDS drives only).
  • Examples
    • mt -t /dev/rmt/0mnb rew will rewind the tape in this device.
    • mt -t /dev/rmt/0mnb offl will eject the tape in this device.


System Status


At command.
at command along with crontab command is used to schedule jobs.
at options time [ddate] [+increment] is syntax of at command.
for example if I have a script named usersloggedin which contains.

#!/bin/ksh

who | wc -l

echo "are total number of people logged in at this time."

and I want to run this script at 8:00 AM. So I will first type at 8:00 %lt;enter>
usersloggedin %lt;enter>
I will get following output at 8:00 AM

30

are total number of people logged in at this time.

Options:

  • -f file will execute commands in a file.
  • -m will send mail to user after job is completed.
  • -l will report all jobs that are scheduled and their jobnumbers.
  • -r jobnumber will remove specified jobs that were previously scheduled.

Chmod command.
chmod command is used to change permissions on a file.
for example if I have a text file with calender in it called cal.txt.
initially when this file will be created the permissions for this file depends upon umask set in your profile files. As you can see this file has 666 or -rw-rw-rw attributes.

ls -la cal.txt

-rw-rw-rw-    1 ssb      dxidev       135 Dec  3 16:14 cal.txt

In this line above I have -rw-rw-rw- meaning respectively that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next ssb is owner of this file dxidev is the group of this file, there are 135 bytes in this file, this file was created on December 3 at time16:14 and at the end there is name of this file. Learn to read these permissions in binary, like this for example Decimal 644 which is 110 100 100 in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. Similarly, if permissions are 755 or 111 101 101 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. All directories have d in front of permissions. So if you don't want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e.
chmod 600 filename.


Chgrp command.
chgrp command is used to change the group of a file or directory.
You must own the file or be a superuser.
chgrp [options] newgroup files is syntax of chgrp.
Newgroup is either a group Id or a group name located in /etc/group .

Options:

  • -h will change the group on symbolic links.
  • -R recursively descend through directory changing group of all files and subdirectories.

Chown command.
chown command to change ownership of a file or directory to one or more users.
Syntax is
chown options newowner files

Options

  • -h will change the owner on symbolic links.
  • -R will recursively descend through the directory, including subdirectories and symbolic links.

Crontab command.
crontab command is used to schedule jobs. You must have permission to run this command by unix Administrator. Jobs are scheduled in five numbers, as follows.

 Minutes               0-59

                               Hour                   0-23

                               Day of month   1-31

                               month                  1-12

                               Day of week            0-6 (0 is sunday)

so for example you want to schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month. The entry in crontab file will be. * represents all values.

25 22  15 * 0 /usr/local/bin/backup_jobs

The * here tells system to run this each month.
Syntax is
crontab file So a create a file with the scheduled jobs as above and then type
crontab filename .This will scheduled the jobs.


Date command.
Date displays todays date, to use it type date at prompt.

Sun Dec  7 14:23:08 EST 1997

is similar to what you should see on screen.


Df command.
df command displays information about mounted filesystems. It reports the number of free disk blocks. Typically a Disk block is 512 bytes (or 1/2 Kilobyte).
syntax is
df options name

Options

  • -b will print only the number of free blocks.
  • -e will print only the number of free files.
  • -f will report free blocks but not free inodes.
  • -F type will report on an umounted file system specified by type.
  • -k will print allocation in kilobytes.
  • -l will report only on local file systems.
  • -n will print only the file system name type, with no arguments it lists type of all filesystems

Du command.
du command displays disk usage.


Env command.
env command displays all the variables.


Finger command.
finger command.


PS command
ps command is probably the most useful command for systems administrators. It reports information on active processes.
ps options

options.

  • -a Lists all processes in system except processes not attached to terminals.
  • -e Lists all processes in system.
  • -f Lists a full listing.
  • -j print process group ID and session ID.

Ruptime command.
ruptime command tells the status of local networked machines.
ruptime options

options.

  • -a include user even if they've been idle for more than one hour.
  • -l sort by load average.
  • -r reverse the sort order.
  • -t sort by uptime.
  • -i sort by number of users.

Shutdown command.
Shutdown command can only be executed by root. To gracefully bring down a system, shutdown command is used.

options.

  • -gn use a grace-period of n seconds (default is 60).
  • -ik tell the init command to place system in a state k.
    • s single-user state (default)
    • 0 shutdown for power-off.
    • 1 like s, but mount multi-user file systems.
    • 5 stop system, go to firmware mode.
    • 6 stop system then reboot.
  • -y suppress the default prompt for confirmation.

Stty command
stty command sets terminal input output options for the current terminal. without options stty reports terminal settings.
stty options modes < device

options

  • -a report all options.
  • -g report current settings.

Modes

  • 0 hang up phone.
  • n set terminal baud.
  • erase keyname, will change your keyname to be backspace key.

Who command
who command displays information about the current status of system.
who options file
Who as default prints login names of users currently logged in.

Options

  • -a use all options.
  • -b Report information about last reboot.
  • -d report expired processes.
  • -H print headings.
  • -p report previously spawned processes.
  • -u report terminal usage.

Unix commands   download here

COMMONLY USED UNIX COMMANDS

Unix commands Man ual command. man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example. man ls will explain about...  


10

Manipulating Data

select * from dept;

insert into DEPT (DEPTNO,DNAME,LOC) VALUES(66,'development','VIRGINIA')

insert into DEPT VALUES(77,'ELECTRICAL','VIRGINIA')

SELECT * FROM DEPT;

INSERT INTO EMP VALUES(7199,'GREEN','SALESMAN',7782,SYSDATE,2000,NULL,10);

SELECT * FROM EMP WHERE EMPNO=7199

 INSERT INTO EMP VALUES(7186,'GREEN','SALESMAN',7782,TO_DATE('FEB 3,2012','MON DD,YYYY'),2000,NULL,10);

SELECT * FROM EMP WHERE EMPNO=7186

INSERT INTO      dept (deptno, dname, loc)

VALUES                                (&department_id,'&department_name', '&location');

CREATE TABLE MANAGERS1 AS SELECT * FROM EMP WHERE JOB='TEST'

SELECT * FROM MANAGERS1

INSERT INTO MANAGERS1 (EMPNO,ENAME,SAL,HIREDATE) SELECT EMPNO,ENAME,SAL,HIREDATE FROM EMP WHERE JOB='MANAGER'

CREATE TABLE CLERK AS SELECT * FROM EMP WHERE JOB='CLERK'

SELECT * FROM CLERK

SELECT DEPTNO,EMPNO FROM EMP WHERE EMPNO=7782

UPDATE EMP SET DEPTNO=20 WHERE EMPNO=7782

UPDATE EMP SET (JOB,DEPTNO)=(SELECT JOB, DEPTNO FROM EMP WHERE EMPNO=7499) WHERE EMPNO=7698

SELECT JOB , DEPTNO FROM EMP WHERE EMPNO=7698

SELECT * FROM DEPT;

UPDATE EMP SET DEPTNO=55 WHERE DEPTNO=30

SELECT * FROM EMP

SELECT * FROM DEPT;

DELETE FROM DEPT WHERE DNAME='development'

delete from dept where dname='TRAINING'

DELETE FROM DEPT WHERE DEPTNO=60

ROLLBACK

SELECT * FROM DEPT;

ROLLBACK

DELETE FROM DEPT WHERE DEPTNO=66

COMMIT

SAVEPOINT A

SELECT * FROM DEPT

DELETE FROM DEPT WHERE DEPTNO=70

SAVEPOINT B

DELETE FROM DEPT WHERE DEPTNO=50

ROLLBACK B

SELECT * FROM EMP

DELETE FROM EMP

ROLLBACK

SQL PRACTICE DAY 5 – MANIPULATING DATA

Manipulating Data select * from dept; insert into DEPT (DEPTNO,DNAME,LOC) VALUES(66,'development','VIRGINIA') insert into DEPT VALUES(77,'ELECTRICAL','VIRGINIA') S...  


Showing 1 - 10 of 16 Previous | 1 | 2 | Next
Shadow Bottom
   
© 2005 - 2014 Krishna Training.