Thursday, December 28, 2017

Zipping and Unzipping Files in UNIX

There are several methods of archiving files and retrieving archives. I recommend using the “zip” function to compress your files for its ease of use and portability. (Files zipped in Unix can be extracted using various tools on various platforms including Windows).
Below I have provided various “unzip” methods. The “right” unzip method depends upon the method used to zip the file. You can tell the zip method by the file extension (e.g., .zip.tar.gz, etc.)

Zipping Files Using ZIP

This Unix program is compatible with the zip program for Windows and most other operating systems. To zip files, first have the files uploaded to your server, then log into your account with SSH. Navigate to the directory where the files are that you want to zip (for instance by typing cd www then cd sounds to move to your/www/sounds directory). Then type:
zip myzip file1 file2 file3
This puts the files named file1file2, and file3 into a new zip archive called myzip.zip.

Unzipping Files

Please note that the unzip method you use is defined by the filename you are trying to unzip. For example, if you are trying to unzip a file called file.tar – you would use the method described in “tar“. Files ending in .gzip or .gz need to be extracted with the method described in “gunzip“.

Zip

If you have an archive named myzip.zip and want to get back the files, you would type:
unzip myzip.zip
Typing zip or unzip by itself will give you a usage summary, showing nearly all the options available.

You can compress whole directory using the following command:
zip -r squash.zip dir1

Tar

To extract a file compressed with tar (e.g., filename.tar), type the following command from your SSH prompt:
tar xvf filename.tar
Basically, this command means that you will see the file “explode”, so don’t worry when you see your screen scrolling wildly. It also means that you will see any errors in the archive.

Compress / zip it with command tar -cvzf new_tarname.tar.gz folder-you-want-to-compress
In this example, compress a folder named “scheduler”, into a new tar file “scheduler.tar.gz”.
$ tar -cvzf scheduler.tar.gz scheduler

Gunzip

To extract a file compressed with gunzip, type the following:
gunzip filename_tar.gz
then if you receive no errors, type:
tar xvf filename_tar

Sunday, December 24, 2017

Linux crontab command

The crontab (short for "cron table") is a list of commands that are scheduled to run at regular time intervals on your computer system. The crontab command opens the crontab for editing, and lets you add, remove, or modify scheduled tasks.
The daemon which reads the crontab and executes the commands at the right time is called cron. It's named after Kronos, the Greek god of time

Command syntax

crontab [-u user] file
crontab [-u user] [-l | -r | -e] [-i] [-s]
Options
fileLoad the crontab data from the specified file. If file is a dash ("-"), the crontab data is read from standard input.
-u userSpecifies the user whose crontab is to be viewed or modified. If this option is not given, crontab opens the crontab of the user who ran crontab. Note: using su to switch users can confuse crontab, so if you are running it inside of su, always use the -u option to avoid ambiguity.
-lDisplay the current crontab.
-rRemove the current crontab.
-eEdit the current crontab, using the editor specified in the environment variable VISUALor EDITOR.
-iSame as -r, but gives the user a yes/no confirmation prompt before removing the crontab.
-sSELinux only: appends the current SELinux security context string as an MLS_LEVELsetting to the crontab file before editing or replacement occurs. See your SELinux documentation for detailed information.
Find more details here: ucrontab

Wednesday, December 20, 2017

Install Git in linux centos

Once you log in you can use the following command to install Git:
Note: you need root or sudo permission to perform this.
yum install git
You can  uninstall using the yum remove command 
yum remove git
yum clean all

Tuesday, December 12, 2017

Curl- Useful commands

Multiple Header:

Usage: curl -H “Host:localhost” -H “Content-Type:text/xml” http://www.mysite.com


Url/Param Encoding

curl -v -H 'Authorization: ESA YW40VFVmQlhyZmFlSmtCSjplejMyOXFDZTRkektOMnNp' -X GET 'http://10.40.19.8/ext/consumer/rmsj/int/1.0/item/search' -x 218.251.242.132:80 -G --data-urlencode 'itemName="'

Notice : -G --data-urlencode 'itemName="'


Http request with Proxy: (small -x)


An HTTP proxy is a proxy that the client speaks HTTP with to get the transfer done. curl will,
by default, assume that a host you point out with -x or --proxy is an HTTP proxy, and
unless you also specify a port number it will default to port 3128 (and the reason for that
particular port number is purely historical).

If you want to request the example.com web page using a proxy on 192.168.0.1 port 8080, a
command line could look like:


curl -x 192.168.0.1:8080 http:/example.com/



Request method (big -X)

The first line of the request includes the method - sometimes also referred to as "the verb".
When doing a simple GET request as this command line would do:

curl http://example.com/file

…the initial request line looks like this:

GET /file HTTP/1.1
You can tell curl to change the method into something else by using the -X or --request
command-line options followed by the actual method name. You can, for example, send a

DELETE instead of GET like this:

curl http://example.com/file -X DELETE

This command-line option only changes the text in the outgoing request, it does not change
any behavior. This is particularly important if you, for example, ask curl to send a HEAD with
-X , as HEAD is specified to send all the headers a GET response would get but never
send a response body, even if the headers otherwise imply that one would come. So, adding
-X HEAD to a command line that would otherwise do a GET will cause curl to hang, waiting
for a response body that won't come.

When asking curl to perform HTTP transfers, it will pick the correct method based on the
option so you should only very rarely have to explicitly ask for it with -X . It should also be
noted that when curl follows redirects like asked to with -L , the request method set with -
X will be sent even on the subsequent redirects.



HTTP POST ( -d or --data)

POST is the HTTP method that was invented to send data to a receiving web application,
and it is how most common HTML forms on the web works. It usually sends a chunk of
relatively small amounts of data to the receiver.

When the data is sent by a browser after data have been filled in a form, it will send it "URL
encoded", as a serialized name=value pairs separated with ampersand symbols ('&'). You
send such data with curl's -d or --data option like this:

curl -d 'name=admin&shoesize=12' http://example.com/

When specifying multiple -d options on the command line, curl will concatenate them and
insert ampersands in between, so the above example could also be made like this:

curl -d name=admin -d shoesize=12 http://example.com/

If the amount of data to send isn't really fit to put in a mere string on the command line, you
can also read it off a file name in standard curl style:

curl -d @filename http://example.com

Content-Type

POSTing with curl's  -d  option will make it include a default header that looks like Content-
Type: application/x-www-form-urlencoded . That's what your typical browser will use for a
plain POST.
Many receivers of POST data don't care about or check the Content-Type header.
If that header is not good enough for you, you should, of course, replace that and instead
provide the correct one. Such as if you POST JSON to a server and want to more accurately
tell the server about what the content is:

curl -d '{json}' -H 'Content-Type: application/json' https://example.com


5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...