Wednesday, January 23, 2008

Unix Commands.. SCP, TAR,GZIP etc

Creating a TAR file in Unix.

What is a TAR File..?

Tar is most commonly used pack/unpack program in unix. Used for packaging files be sent across machines in a network.

Use 'c' command to package tar and 'x' command to unpack tar

Ex: if you want to create a tarfile from files A B C.. here is the command

tar cf g.tar A B C

Note: Always make sure you specify the file name before specifying the file names. Or unix will over write the first file mentioned. ex:

tar cf A B C. File 'A' will be overwritten.

Options in Tar: 'c' : Create command
'v' displays/echos the files being archived
'f' is the file name.

Unpack a Tar File:

tar xf
tar xf g.tar

Compressing a tar file..

gzip and bzip are used to compress the tar file. Compressed tar file In many ways both reduce network transfer time and to save space on the disk.


Command to compress tar:

gzip g.tar

the file will be renamed g.tar.gz

saved a significant amount of time using gzip file compred to transferring regular tar file. took 2.14 mins using .gz format and ~7 mins using regular .tar.

Cut down my waiting/turn around time here... :)

to uncompress the gzip file use..

gzip -d g.tar.gz

will create a file called g.tar

and now to unpackage tar use

tar xc g.tar

yay ..!!!!! I did QA deployment today using all the commands..

SCP: Secure file transfer from one unix box to another.

What is SCP: Copies a single file or a folder with multiple files using secure protocol over TCP/IP (the network) from one computer to another

Syntax:

scp username@location of the remote server:path to be copied to

$ scp suneetha.sh sunny@cmcad54323:/cri_staging/omen/discovery/QA
Next line will prompt u for pwd

$ scp suneetha.sh sunny@cmcad54323:/cri_staging/omen/discovery/QA
sunny's Password:
Could not chdir to home directory /home/u496798: No such file or directory
suneetha.sh 100% |*****************************| 551 00:00

using regular FTP, you'll have to first copy the file to ur local and then copy to the other server..its a 2 step process. Using scp u can eliminate it and directly connect to remote server.. Its cool try it out sometime. :))

Happy Reading :)

No comments: