Showing posts with label Unix. Show all posts
Showing posts with label Unix. Show all posts

Thursday, 8 August 2013

Linux Basics


These commands need to be arranged in term of their usability

1) A function letter does not need to be prefixed with a dash ("-"), and may be combined with other single-letter options.
2) A long function name must be prefixed with a double dash ("--").
3) Some options take a parameter; with the single-letter form these must be given as separate arguments.
 With the long form, they may be given by appending "=value" to the option.

Tar ( Tape archive)

1) A function letter does not need to be prefixed with a dash ("-"), and may be combined with other single-letter options.
2) A long function name must be prefixed with a double dash ("--").
3) Some options take a parameter; with the single-letter form these must be given as separate arguments.
 With the long form, they may be given by appending "=value" to the option.

All 4 below mean the same thing

a) tar --create --file=archive.tar file1 file2
Note -- c for create , f for file
b) tar -c -f archive.tar file1 file2
c) tar -cf archive.tar file1 file2
d) tar cf archive.tar file1 file2

Create archive archive.tar containing files file1 and file2. Here, the c tells tar you will be creating an archive; the f tells tar that the next option (here it's archive.tar) will be the name of the archive it creates. file1 and file2, the final arguments, are the files to be archived

Other useful addition to tar
A - Append ( you can add a file to already present archive file)
t- List contents (Notice T as t of LisT)
d- difference
v-Verbose
X-Extract
u- update (update a already present file in archive if its old copy)
z-zipped
c-Compressed

tar -tvf archive.tar--List the files in the archive archive.tar verbosely
tar -xf archive.tar -- Extract files from archive
tar -xzvf archive.tar.gz -- Extract files from zipped archive

Gzip (GNU zip) and Gunzip (GNU unzip)

Gzip is a compression command and is used to compress(reduce the size of file).So running gzip on 3 files will not combine them into one file.
In order to compress a folder, we need to first use tar and then zip with gzip
Example -
gzip file1 file2 file3 ... this will produce 3 files ,file1.gz, file2.gz and file3.gz with .gz extension.

Compressing a folder
tar cf – test/ | gzip > test.tar.gz

Some File manupulating commands

awk 'BEGIN {start_action} {action} END {stop_action}' filename

Note
1) $1 will print the first column
2) $0 will print the entire line
3) FS field separator
4) OFS - Output field separator variable
5) NF - Number of fileds variable
6) NR - Number of lines


awk '{print $1}' input_file -- Prints first column
awk 'BEGIN {sum=0} {sum=sum+$5} END {print sum}' input_file --Sum of values in 5th block
awk '{ if($9 == "t4") print $0;}' input_file ----notice the semicolon
awk 'BEGIN {FS=":"} {print $2}' input_file
awk 'BEGIN {OFS=":"} {print $4,$5}' input_file
awk '{print NF}' input_file  - tells us number of fields
awk '{print NR}' input_file -- tells us number of records

Cut Command

Cut command in unix (or linux) is used to select sections of text from each line of files. It can be used as substring command by specifying the start and end position to cut. Also it can be used similar to awk command by specifying the delimiter.
Note
d is used for delimeter
f is used for field posistion
c - Cut

cut -c4 file.txt
cut -c4,6 file.txt -- this means only 4th and 6th character. It will apply to all rows
cut -c4-7 file.txt--- Start position and End position.
cut -c10- file.txt ---Start position and no end position
cut -d' ' -f2 file.txt -- Notice no c here, We are picking a field

Important point to remember. Command always use delimeter to find end of a column
Example

logfile.dat
sum.pl
add_int.sh

 cut -d'.' -f1
--- this will give us logfile and others ( sum, add_int)

If we need to find the value after dot. We need to reverse the string and then cut

Reverse

echo "nixcraft" | rev

This will output tfarcxin

Head command in Linux


































Saturday, 6 July 2013

Difference between Linux and Unix

Hi Guys


Linux is free operating system whereas Unix is not free.To understand this completely we need to understand we need some basics below.

Linux have some version which cost some money.Unix does not have any free versions.Unix is used mainly for servers ( Solaris (oracle) ,AIX (IBM) are unix based OS.

Linux is Unix like operating system.Unix was developed by Bell labortories(those that gave you phone and transistor) and linux is based on similar structure so its called Unix like.


An operating system (OS) is a collection of software that manages computer hardware resources and provides common services for computer programs.For hardware functions such as input and output and memory allocation, the operating system acts as an intermediary between programs and the computer hardware.

A Unix kernel — the core or key components of the operating system — consists of many kernel subsystems like process management, memory management, file management, device management and network management.

Its free - You get the code for kernel freely available apart from code from other stuff you can build your system on that

Popular example of systems built on linux are Android(For mobiles ).Red hat,Google chrome OS.

Some other points

Linux and unix are both know to be virus free hardly about 200 virus till date for both of them combined together

Unix OS is mainly used for servers , mainframes.There are different flavours of unix Solaris (Oracle) (Mostly being promoted for datacenters for clouds) ,AIX(IBM),and Apple OSX.

So what are flavours .We are not having ice Cream here ??.

The kernel remains the same and you can build on top of it as you like. Like for ice cream the base may be plain white milk and cream and you can add chocalate or strawberry flavour to it.

Linux for desktop pc.Mobiles (Androids)

Note:-They say using oracle solari as OS for datacentres(servers with oracle db will provide good scalability and great performance as its designed that way .

The black screen most datawarehousing guys see

Please remember telnet does not have a UI in unix .We use putty to connect to unix server(Solaris).For GUI to unix we can use WINSCP a free software.

Because we have command screen for telnet does not mean you have command screen for everything .It has a proper GUI only telnet is command screen.

Some other basic points


In 1969, UNIX was developed by a group of AT&T employees at Bell Labs and Dennis Ritchie. It was written in “C” language and was designed to be a portable, multi-tasking and multi-user system in a time-sharing configuration

Some Linux based OS

 Android,Ubuntu, Fedora, Red Hat, Debian, Archlinux, etc are all linux OS.Google chrome OS is linux based OS.

Some open source softwares

Many of open source softwares are Apache http sever ,JBOSS (its a application server like Apache but supports web services, and java beans), Mozilla , Mysql (database) .You can get the code for these things .


http://cognossimplified.blogspot.com/2013/08/linux-basics.html