You are on page 1of 16

Atomicity

By this, we mean that either the entire transaction takes place at once or doesn’t happen at all.
There is no midway i.e. transactions do not occur partially. Each transaction is considered as one
unit and either runs to completion or is not executed at all. It involves following two operations.
—Abort: If a transaction aborts, changes made to database are not visible.
—Commit: If a transaction commits, changes made are visible.
Atomicity is also known as the ‘All or nothing rule’.
Consider the following transaction T consisting of T1 and T2: Transfer of 100 from account X to
account Y.

If the transaction fails after completion of T1 but before completion of T2.( say,
after write(X) but before write(Y)), then amount has been deducted from X but not added to Y.
This results in an inconsistent database state. Therefore, the transaction must be executed in
entirety in order to ensure correctness of database state.

Consistency
This means that integrity constraints must be maintained so that the database is consistent before
and after the transaction. It refers to correctness of a database. Referring to the example above,
The total amount before and after the transaction must be maintained.
Total before T occurs = 500 + 200 = 700.
Total after T occurs = 400 + 300 = 700.
Therefore, database is consistent. Inconsistency occurs in case T1 completes but T2 fails. As a
result T is incomplete.

Isolation
This property ensures that multiple transactions can occur concurrently without leading to
inconsistency of database state. Transactions occur independently without interference. Changes
occurring in a particular transaction will not be visible to any other transaction until that
particular change in that transaction is written to memory or has been committed. This property
ensures that the execution of transactions concurrently will result in a state that is equivalent to a
state achieved these were executed serially in some order.
Let X= 500, Y = 500.
Consider two transactions T and T”.
Suppose T has been executed till Read (Y) and then T’’ starts. As a result , interleaving of
operations takes place due to which T’’ reads correct value of X but incorrect value of Y and sum
computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
This results in database inconsistency, due to a loss of 50 units. Hence, transactions must take
place in isolation and changes should be visible only after a they have been made to the main
memory.

Durability:
This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored in and written to disk and they persist even is system
failure occurs. These updates now become permanent and are stored in a non-volatile memory.
The effects of the transaction, thus, are never lost.
The ACID properties, in totality, provide a mechanism to ensure correctness and consistency of a
database in a way such that each transaction is a group of operations that acts a single unit,
produces consistent results, acts in isolation from other operations and updates that it makes are
durably stored.
This article is contributed by Avneet Kaur. If you like GeeksforGeeks and would like to
contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to
contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and
help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information
about the topic discussed above.

A conformed dimension is a dimension that has exactly the same meaning and content when being
referred from different fact tables. A conformed dimension can refer to multiple tables in multiple data
marts within the same organization.

cd command in Linux/Unix
cd is a Linux command to change the directory/folder of the terminal's shell.
You can press the tab button in order to auto complete the directory name.
 cd syntax
 cd examples

cd syntax
$ cd [directory]

cd command examples
Change to home directory (determined by $HOME environment variable):
$ cd

Also change to home directory:


$ cd ~

Change to root directory:


$ cd /

Change to parent directory:


$ cd ..

Change to subdirectory Documents:


$ cd Documents

Change to subdirectory Documents/Books:


$ cd Documents/Books

Change to directory with absolute path /home/user/Desktop:


$ cd /home/user/Desktop

Change to directory name with white space - My Images:


$ cd My\ Images
Or
$ cd "My Images"
Or
$ cd 'My Images'

See also
 cat command
 cp command
 gcc command
 ls
 CD Command Examples
1. Write a unix/linux cd command to change to home directory?

Just simply type cd command on the unix terminal and then press the enter key. This will
change your directory to home directory.

 > pwd

 /usr/local/bin


Now i am in the /usr/local/bin directory. After typing the cd command and unix window,
you will go to your home directory.

 > cd

 > pwd

 /home/matt


Here pwd command displays the present working directory.

2. Write a unix/linux cd command to go back to one directory?

The cd .. changes the directory to its parent directory by going back one level. The
space between the cd and .. is must.

 > pwd

 /var/tmp

 > cd ..

 > pwd
 /var


3. Write a unix/linux cd command to go back to two directories?

The cd ../../ takes you back to two directories. You can extend this cd command to go
back to n number of directories.

 > pwd

 /usr/local/bin

 > cd ../../

 > pwd

 /usr


4. Write a unix/linux cd command to change the directory using the absolute path?

In case of changing directory using absolute path you have to specify the full directory
path. Absolute path directories always start with a slash (/). An example is changing your
directory to /usr/bin from your home directory.

 > cd /usr/bin


5. Write a unix/linux cd command to change the directory using the relative path?

In relative path, you have to specify the directory path relative to your current directory.
For example, you are in /var/tmp directory and you want to go to /var/lib directory, then
you can use the relative path.

 > pwd
 /var/tmp

 > cd ../lib

 > pwd

 /var/lib


Here the cd ../lib, first takes you to the parent directory which is /var and then changes
the directory to the lib.

6. Write a unix/linux cd command to change back to previous directory.

As an example, i am in the directory /home/matt/documents and i changed to a new


directory /home/matt/backup. Now i want to go back to my previous directory
/home/matt/documents. In this case, you can use the cd - command to go back to the
previous directory.

 > pwd

 /home/matt/documents

 > cd /home/matt/backup

 >pwd

 /home/matt/backup

 > cd -

 > pwd

 /home/matt/documents
 No comments:

 Po

cp command syntax
Copy from source to dest
$ cp [options] source dest

cp command options
cp command main options:
option description

cp -
archive files
a

cp -
force copy by removing the destination file if needed
f

cp -
interactive - ask before overwrite
i

cp -
link files instead of copy
l

cp -
follow symbolic links
L

cp -
no file overwrite
n

cp -
recursive copy (including hidden files)
R

cp -
update - copy when source is newer than dest
u

cp -
verbose - print informative messages
v

cp command examples
Copy single file main.c to destination directory bak:
$ cp main.c bak

Copy 2 files main.c and def.h to destination absolute path directory /home/usr/rapid/ :
$ cp main.c def.h /home/usr/rapid/
Copy all C files in current directory to subdirectory bak :
$ cp *.c bak

Copy directory src to absolute path directory /home/usr/rapid/ :


$ cp src /home/usr/rapid/

Copy all files and directories in dev recursively to subdirectory bak:


$ cp -R dev bak

Force file copy:


$ cp -f test.c bak

Interactive prompt before file overwrite:


$ cp -i test.c bak
cp: overwrite 'bak/test.c'? y

Update all files in current directory - copy only newer files to destination directory bak:
$ cp -u * bak

cp code generator
Select cp options and press the Generate Code button:
Options

cribe the usage and functionality of the command “rm –r *” in UNIX?


Ans) The command “rm –r *” is a single line command to erase all files in a directory with its subdirectories.
 “rm” – Is for deleting files.
 “-r” – Is to delete directories and subdirectories with files within.
 “*” – Is indicate all entries.
 Q #10) What is the UNIX command to list files/folders in alphabetical order?
 Ans) The ‘ls –l’ command is used to list down files and folders in alphabetical order. When you use ‘ls –lt’ is list
down files /folders sorted with modified time.
Q #18) What is the behavioral difference between “cmp” and “diff” commands?
Ans) Both commands for file comparison.
Cmp – Compare given two files with byte by byte and display the first mismatch.
Diff – Display changes that need to done to make both file identical.
Q #19) What are the duties of following commands?
Ans) chmod, chown, chgrp
 chmod – Change the permission set of the file.
 chown – Change ownership of the file.
 chgrp – Change group of the file.
 Q #32) What is the UNIX command to make a new directory?
 Ans) “mkdir directory_name” is used to create a new directory.
 Command
 #45) What is called piping?
 Ans) “piping” is used to combine two or more commands together. The output of the first command work as the
input of the second command, and so on. Pipe character ( | ) is represent piping.
 Q #46) What is the process to count the number of characters and line in a file?
 #46) What is the process to count the number of characters and line in a file?
 Ans) “wc – c filename” command can use to retrieve the number of characters in a file and “wc –l filename”
command can use to retrieve the number of lines in a file.


 Above command returns the number of characters in README.txt file.


 Above command returns the number of characters in README.txt file.

 UPDATE: Added more common


 Filename manipulation commands along with their description is enlisted below in table:
Command Description

cat filename Displays contents of the file

cp source destination Used to copy source file into the destination

mv old name new name Move/rename and old name to the new name

rm filename Remove/delete filename

Touch filename Changing modification time

In [-s] old name new name Creates soft link on old name

Is –F Displays information about file type


ow is cmp command different from diff command?
‘cmp’ command is basically used for byte by byte comparison of two files to determine the first mismatch byte. This
command does not use the directory name and displays the first encountered mismatched byte.
Whereas, ‘diff’ command’ determines the changes that are to be performed on the files in order to make the two files
identical. In this case, directory names can be used.
Syntax: $grep pattern file(s)
Some of the options that are used along with grep command are enlisted below:

 -v: prints line that does not match the pattern.


 -n: print matched line and line number.
 -l: print file names with matching lines.
 -c: prints only the count of matching lines.
 -i: matches either uppercase or lowerca
Sample Commands
1. Replacing or substituting string : Sed command is mostly used to replace the text in a file. The below simple sed command replaces the word
“unix” with “linux” in the file.
2. $sed 's/unix/linux/' geekfile.txt

Output :

linux is great os. unix is opensource. unix is free os.


learn operating system.
linux linux which one you choose.
linux is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

Here the “s” specifies the substitution operation. The “/” are delimiters. The “unix” is the search pattern and the “linux” is the replacement string.
By default, the sed command replaces the first occurrence of the pattern in each line and it won’t replace the second, third…occurrence in the line.

3. Replacing the nth occurrence of a pattern in a line : Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line.
The below command replaces the second occurrence of the word “unix” with “linux” in a line.
4. $sed 's/unix/linux/2' geekfile.txt

Output:
unix is great os. linux is opensource. unix is free os.

learn operating system.


unix linux which one you choose.
unix is easy to learn.linux is a multiuser os.Learn unix .unix is a powerful.

5. Replacing all the occurrence of the pattern in a line : The substitute flag /g (global replacement) specifies the sed command to replace all
the occurrences of the string in the line.
6. $sed 's/unix/linux/g' geekfile.txt

Output :
linux is great os. linux is opensource. linux is free os.

learn operating system.


linux linux which one you choose.

linux is easy to learn.linux is a multiuser os.Learn linux .linux is a powerful.

7. Replacing from nth occurrence to all occurrences in a line : Use the combination of /1, /2 etc and /g to replace all the patterns from the
nth occurrence of a pattern in a line. The following sed command replaces the third, fourth, fifth… “unix” word with “linux” word in a line.
8. $sed 's/unix/linux/3g' geekfile.txt

Output:
unix is great os. unix is opensource. linux is free os.
learn operating system.
unix linux which one you choose.
unix is easy to learn.unix is a multiuser os.Learn linux .linux is a powerful.

9. Parenthesize first character of each word : This sed example prints the first character of every word in paranthesis.
10. $ echo "Welcome To The Geek Stuff" | sed 's/\(\b[A-Z]\)/\(\1\)/g'

Output:

(W)elcome (T)o (T)he (G)eek (S)tuff

11. Replacing string on a specific line number : You can restrict the sed command to replace the string on a specific line number. An example
is
12. $sed '3 s/unix/linux/' geekfile.txt

Output:
unix is great os. unix is opensource. unix is free os.
learn operating system.
linux linux which one you choose.
unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

The above sed command replaces the string only on the third line.

13. Duplicating the replaced line with /p flag : The /p print flag prints the replaced line twice on the terminal. If a line does not have the search
pattern and is not replaced, then the /p prints that line only once.
14. $sed 's/unix/linux/p' geekfile.txt

Output:
linux is great os. unix is opensource. unix is free os.

linux is great os. unix is opensource. unix is free os.


learn operating system.
linux linux which one you choose.
linux linux which one you choose.
linux is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
linux is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

15. Printing only the replaced lines : Use the -n option along with the /p print flag to display only the replaced lines. Here the -n option
suppresses the duplicate rows generated by the /p flag and prints the replaced lines only one time.
16. $sed -n 's/unix/linux/p' geekfile.txt

Output:
linux is great os. unix is opensource. unix is free os.
linux linux which one you choose.
linux is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

If you use -n alone without /p, then the sed does not print anything.

17. Replacing string on a range of lines : You can specify a range of line numbers to the sed command for replacing a string.
18. $sed '1,3 s/unix/linux/' geekfile.txt

Output:
linux is great os. unix is opensource. unix is free os.
learn operating system.
linux linux which one you choose.

unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.

Here the sed command replaces the lines with range from 1 to 3. Another example is

$sed '2,$ s/unix/linux/' geekfile.txt

Output:
unix is great os. unix is opensource. unix is free os.

learn operating system.


linux linux which one you choose.

linux is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful

Here $ indicates the last line in the file. So the sed command replaces the text from second line to last line in the file.

19. Deleting lines from a particular file : SED command can also be used for deleting lines from a particular file. SED command is used for
performing deletion operation without even opening the file
Examples:
1. To Delete a particular line say n in this example
20. Syntax:
21. $ sed 'nd' filename.txt
22. Example:
23. $ sed '5d' filename.txt

2. To Delete a last line

Syntax:
$ sed '$d' filename.txt

3. To Delete line from range x to y

Syntax:
$ sed 'x,yd' filename.txt

Example:
$ sed '3,6d' filename.txt

5. To Delete from nth to last line

Syntax:
$ sed 'nth,$d' filename.txt
Example:

$ sed '12,$d' filename.txt

6. To Delete pattern matching line

Syntax:

$ sed '/pattern/d' filename.txt


Example:
$ sed '/abc/d' filename.txt

SED command in Linux | Set 2


This article is contributed by Akshay Rajput and Mohak Agrawal. If you like GeeksforGeeks and would
like to contribute, you can als
select a.Emp_Name, a.Company, a.Join_Date, a.Resigned_Date,
a.RowNumber
from
(select Emp_Name
,Company
,Join_Date
,Resigned_Date
,ROW_NUMBER() over (partition by Emp_Name, Company, Join_Date
,Resigned_Date
order by Emp_Name, Company, Join_Date
,Resigned_Date) RowNumber
from Emp_Details) a
where a.RowNumber > 1

Following code is useful to delete duplicate records. The table must have identity column, which will be used to identify the duplicate records.
Table in example is has ID as Identity Column and Columns which have duplicate data are DuplicateColumn1, DuplicateColumn2 and
DuplicateColumn3.

DELETE
FROM MyTable
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM MyTable
GROUP BY DuplicateColumn1, DuplicateColumn2, DuplicateColumn3)

$ ls -l
-rw-r----- 1 ramesh team-dev 9275204 Jun 13 15:27 mthesaur.txt.gz

 1st Character – File Type: First character specifies the type of the file.
In the example above the hyphen (-) in the 1st character indicates that this is a normal file. Following are the
possible file type options in the 1st character of the ls -l output.
 Field Explanation
 – normal file
 d directory
 s socket file
 l link file
 Field 1 – File Permissions: Next 9 character specifies the files permission. Each 3 characters refers to the read,
write, execute permissions for user, group and world In this example, -rw-r—– indicates read-write permission for
user, read permission for group, and no permission for others.
 Field 2 – Number of links: Second field specifies the number of links for that file. In this example, 1 indicates
only one link to this file.
 Field 3 – Owner: Third field specifies owner of the file. In this example, this file is owned by username ‘ramesh’.
 Field 4 – Group: Fourth field specifies the group of the file. In this example, this file belongs to ”team-dev’
group.
 Field 5 – Size: Fifth field specifies the size of file. In this example, ‘9275204’ indicates the file size.
 Field 6 – Last modified date & time: Sixth field specifies the date and time of the last modification of the file.
In this example, ‘Jun 13 15:27’ specifies the last modification time of the file.
 Field 7 – File name: The last field is the name of the file. In this example, the file name is mthesaur.txt.gz.

4. Display File Size in Human Readable Format Using ls -lh


Use ls -lh (h stands for human readable form), to display file size in easy to read format. i.e M for MB, K for KB, G for
GB.
$ ls -l

-rw-r----- 1 ramesh team-dev 9275204 Jun 12 15:27 arch-linux.txt.gz*

Display Directory Information Using ls -ld


When you use “ls -l” you will get the details of directories content. But if you want the details of directory then you can
use -d option as., For example, if you use ls -l /etc will display all the files under etc directory. But, if you want to
display the information about the /etc/ directory, use -ld option as shown below.

$ ls -l /etc

total 3344

-rw-r--r-- 1 root root 15276 Oct 5 2004 a2ps.cfg

-rw-r--r-- 1 root root 2562 Oct 5 2004 a2ps-site.cfg

drwxr-xr-x 4 root root 4096 Feb 2 2007 acpi

-rw-r--r-- 1 root root 48 Feb 8 2008 adjtime

drwxr-xr-x 4 root root 4096 Feb 2 2007 alchemist


$ ls -ld /etc
drwxr-xr-x 21 root root 4096 Jun 15 07:02

Order Files Based on Last Modified Time Using ls -lt


To sort the file names displayed in the order of last modification time use the -t option. You will be finding it handy to
use it in combination with -l option.

$ ls -lt
total 76
drwxrwxrwt 14 root root 4096 Jun 22 07:36 tmp
drwxr-xr-x 121 root root 4096 Jun 22 07:05 etc
drwxr-xr-x 13 root root 13780 Jun 22 07:04 dev
drwxr-xr-x 13 root root 4096 Jun 20 23:12 root
drwxr-xr-x 12 root root 4096 Jun 18 08:31 home
drwxr-xr-x 2 root root 4096 May 17 21:21 sbin
lrwxrwxrwx 1 root root 11 May 17 20:29 cdrom -> media/cdrom
drwx------ 2 root root 16384 May 17 20:29 lost+found
drwxr-xr-x 15 root root 4096 Jul 2 2008 var

7. Order Files Based on Last Modified Time (In Reverse Order)


Using ls -ltr
To sort the file names in the last modification time in reverse order. This will be showing the last edited file in the last
line which will be handy when the listing goes beyond a page. This is my default ls usage. Anytime I do ls, I always use
ls -ltr as I find this very convenient.

$ ls -ltr

total 76
drwxr-xr-x 15 root root 4096 Jul 2 2008 var
drwx------ 2 root root 16384 May 17 20:29 lost+found
lrwxrwxrwx 1 root root 11 May 17 20:29 cdrom -> media/cdrom
drwxr-xr-x 2 root root 4096 May 17 21:21 sbin
drwxr-xr-x 12 root root 4096 Jun 18 08:31 home
drwxr-xr-x 13 root root 4096 Jun 20 23:12 root
drwxr-xr-x 13 root root 13780 Jun 22 07:04 dev
drwxr-xr-x 121 root root 4096 Jun 22 07:05 etc
drwxrwxrwt 14 root root 4096 Jun 22 07:36 tmp

8. Display Hidden Files Using ls -a (or) ls -A


To show all the hidden files in the directory, use ‘-a option’. Hidden files in Unix starts with ‘.’ in its file name.

$ ls -a
[rnatarajan@asp-dev ~]$ ls -a
. Debian-Info.txt
.. CentOS-Info.txt
.bash_history Fedora-Info.txt
.bash_logout .lftp
.bash_profile libiconv-1.11.tar.tar
.bashrc libssh2-0.12-1.2.el4.rf.i386.rpm

It will show all the files including the ‘.’ (current directory) and ‘..’ (parent directory). To show the hidden files, but not
the ‘.’ (current directory) and ‘..’ (parent directory), use option -A.
$ ls -A
Debian-Info.txt Fedora-Info.txt
CentOS-Info.txt Red-Hat-Info.txt
.bash_history SUSE-Info.txt
.bash_logout .lftp
.bash_profile libiconv-1.11.tar.tar
.bashrc libssh2-0.12-1.2.el4.rf.i386.rpm
[Note: . and .. are not displayed here]

9. Display Files Recursively Using ls -R


$ ls /etc/sysconfig/networking

devices profiles

$ ls -R /etc/sysconfig/networking

/etc/sysconfig/networking:

devices profiles

/etc/sysconfig/networking/devices:

/etc/sysconfig/networking/profiles:

default

/etc/sysconfig/networking/profiles/default:

To show all the files recursively, use -R option. When you do this from /, it shows all the unhidden files in the whole
file system recursively.

10. Display File Inode Number Using ls -i


Sometimes you may want to know the inone number of a file for internal maintenance. Use -i option as shown below
to display inone number. Using inode number you can remove files that has special characters in it’s name as
explained in the example#6 of the find command article.
$ ls -i /etc/xinetd.d/

279694 chargen 279724 cups-lpd 279697 daytime-udp

279695

You might also like