Ashish Sharma https://www.linuxtechi.com Fri, 12 Jul 2019 13:23:53 +0000 en-US hourly 1 https://www.linuxtechi.com/wp-content/uploads/2020/02/cropped-linuxtechi-favicon-32x32.png Ashish Sharma https://www.linuxtechi.com 32 32 Linux curl command examples – Part 1 https://www.linuxtechi.com/linux-curl-command-examples-part-1/ https://www.linuxtechi.com/linux-curl-command-examples-part-1/#respond Thu, 16 Mar 2017 05:22:41 +0000 http://www.linuxtechi.com/?p=5099 curl is a command line tool used to transfer data  to/from a server. The tool supports various protocols such as : DICT, FILE, FTP, FTPS, GOPHER, HTTP,  HTTPS,  IMAP,  IMAPS,  LDAP,  LDAPS,  POP3, POP3S,  RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP. ... Read more

The post Linux curl command examples – Part 1 first appeared on LinuxTechi.]]>
curl is a command line tool used to transfer data  to/from a server. The tool supports various protocols such as : DICT, FILE, FTP, FTPS, GOPHER, HTTP,  HTTPS,  IMAP,  IMAPS,  LDAP,  LDAPS,  POP3, POP3S,  RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP.

Examples of Curl command:

Of the more than 100 command line options Curl offers, here, in this tutorial, we will cover some of the basic yet useful ones.  All the examples are tested on Ubuntu 16.04 and curl version 7.50.3

Example:1 Download and store output in a file

Using the tool, you can download data represented by a URL and store that in a file. Here’s how you can use the tool to download a URL data:

$ curl [url]

For example:

$ curl  http://www.cricbuzz.com

The above command will display the downloaded data as output on your terminal. To store the output in a file, run the following command:

$ curl [url] > [name-of -output-file]

$ curl http://www.cricbuzz.com > cricbuzz.html

Keep in mind that Curl will display a progress meter on the terminal regardless of how it is being executed.

Here is the output of above command:

curl-command-storefile

Alternatively, you can also use the -o option to save the output (downloaded data) to a specific file.

$ curl -o  [name-of-output-file]  [url-name]

For example:

$ curl -o cricbuzz.html http://www.cricbuzz.com

Similarly, there also exists a -O option (‘O’ in caps) that lets you save the downloaded  data in a file with name same as that of the remote file.

$ curl -O [url]

For example:

$ curl -O https://curl.haxx.se/docs/manpage.html

The above command will save the downloaded data in a file named ‘manpage.html’.

Example:2 Silent Curl command output

If you don’t want Curl to display progress details and errors in output, then you can use the -s option.

For example, consider the following case in which Curl throws an error:

$ curl https://lti.com

curl-command-silent

To mute errors like these, use the -s option.

$ curl -s [url]

For example:

$ curl -s  https://lti.com

Here is the output:

curl-command-silent-s

As you can see, no error is shown in the output.

In case you want Curl to only display errors and not any other details (like the progress details it displays by default), use the -S option along with the -s option.

For example:

$ curl -s -S https://www.lti.com

curl-command-with-s-S-option

Example:3 Download multiple files

Using the tool, you can download multiple files through a single command.

$ curl -o/O [url1]  -o/O [url2]

For example:

$ curl  -O  https://curl.haxx.se/docs/manpage.html  -O https://curl.haxx.se/docs/manual.html

Needless to say, when you will use the ‘-o’ option, you’ll have to provide a file name in the command to store the output.

Example:4 Handle URL redirects using curl command

Suppose, you provide a URL to the Curl command, but the web page doesn’t exist (say, it has been moved to some other location). In that case, you can use the -L command line option, which will make curl redo the request on the new place.

For example, consider a case where-in Curl gives an error like ‘page moved‘.

curl-command-withoutL

But if you access the web page through a Web browser, you observe a redirect. Now, to make sure Curl also handles this redirect, use the -L command line option.

$ curl -L [url]

For example:

$ curl -L uber.com

Here is the output:

curl-command-with-L

Example:5 Information about the url using the -v/–trace option

If you want, you can retrieve detailed information about a Curl operation. This feature can be accessed using the -v option.

Lines starting with ‘>‘ and ‘<‘ display the header data which is sent and received respectively by Curl, and * means additional information provided by the tool.

$ curl -v [url]

For example:

$ curl -v https://curl.haxx.se/docs/manpage.html

Here is the output:

curl-command-verbose

If you are not satisfied with the details you got using the -v option and want to access more information, then use the –trace option.

$ curl –trace [file-in-which-you-want-to-store-output] [url]

For example:

$ curl --trace info  https://curl.haxx.se/docs/manpage.html

Here is the output:

curl-command-trace

Read Also : 12 Useful wget Command Practical Examples in Linux

Example:6 Lookup word-meaning using DICT protocol with curl command

Using the tool, you can search for a word on the terminal using dict protocol. A dictionary server dict.org url is passed to it. There are around 77 dictionaries supported by dict.org server.

To list all the supported dictionaries on your terminal, run the following command:

$ curl dict://dict.org/show:db

Here is the output:

curl-command-showalldict

Now, to search a word in a specific dictionary, use the following command:

$ curl dict://dict.org/d:[word-to-be-searched]:[dictionary-name]

For example:

$ curl dict://dict.org/d:command:gcide

Note: gcide is a short name for a dictionary named “The Collaborative International Dictionary of English”.

Here is the output:

curl-command-singledictsearch

If you want search a word in all the dictionaries, run the following command:

$ curl dict://dict.org/d:[word-to-be-searched]:*

For example:

$ curl dict://dict.org/d:command:*

curl-command-dictionary

Conclusion

We’ve just scratched the surface here as Curl offers a bucket load of features that you can access through the various command line options. Try out the examples explained in this tutorial, and wait for the second part of this tutorial series.

Linux curl command examples – Part 2

The post Linux curl command examples – Part 1 first appeared on LinuxTechi.]]>
https://www.linuxtechi.com/linux-curl-command-examples-part-1/feed/ 0
How to use 7zip Compression tool from Linux Terminal https://www.linuxtechi.com/7zip-compression-tool-linux-terminal/ https://www.linuxtechi.com/7zip-compression-tool-linux-terminal/#comments Fri, 24 Feb 2017 03:02:27 +0000 http://www.linuxtechi.com/?p=5016 7-Zip (http://www.7-zip.org/) is a file archiver with highest compression ratio.The tool supports various archive formats such as LZMA2, XZ, ZIP, Zip64, CAB, RAR, ARJ, GZIP, BZIP2, TAR, CPIO, RPM, ISO, most file system images and DEB formats. Developer claims that the compression ratio in the ... Read more

The post How to use 7zip Compression tool from Linux Terminal first appeared on LinuxTechi.]]>
7-Zip (http://www.7-zip.org/) is a file archiver with highest compression ratio.The tool supports various archive formats such as LZMA2, XZ, ZIP, Zip64, CAB, RAR, ARJ, GZIP, BZIP2, TAR, CPIO, RPM, ISO, most file system images and DEB formats. Developer claims that the compression ratio in the new 7z format is 30-50% better than the ratio in Zip formats.

In this article, we will walk through the practical examples of 7zip utility and their usage.All the below examples have been tested on Ubuntu 16.04 LTS/16.10 and Linux Mint 18 , and the 7zip version we have used is 9.20

Installation

The 7zip utility is not pre-installed on your Ubuntu systems. You have to install it in your system using the following commands.

$ sudo apt-get install p7zip-full

NOTE:In case, you want to use 7zip with rar files, then you’ll have to install the following package as well.

$ sudo apt-get install p7zip-rar

Usage/Functions

In this section, we will discuss the usage of the 7zip tool and the basic features it provides.

Basic syntax of 7zip:

$ 7z [adeltux] [-] [SWITCH] <ARCHIVE_NAME> <ARGUMENTS>..

We will be using the files displayed in the following screenshot for performing various operations using 7zip.

ls-command-output

Create new archive/ add files to existing archive

Using the tool, you can package the files in a .7z file. This feature can be accessed using the ‘a’ function letter.

Here’s how you can use this feature:

$ 7z a [archived-filename] [names-of-files-to-be-archived]

For example:

$ 7z a testfiles.7z *

add-files-in7zip-compressed-file

Now to check, whether the archive file is created or not, you can use the ‘ls‘ command.

add-ls-7zip-command

As you can see in the screenshot above that a .7z archive file (testfiles.7z) has been created. Of course, you can also create/update, say, a .zip file this way.

List contents of archive

You can use the ‘l’ function letter for listing the contents of an archived file.

$ 7z l [archived-filename]

For example:

$ 7z l testfiles.7z

Here is the list of files in testfiles.7z archived file.

listdelete-7zip-command

Delete files from an archive

Using the tool, you can also delete a file from an archive file, something which you can do using the ‘d’ function letter.

$ 7z d [archived file] [name-of-file-to-be-deleted]

For example, to delete testfile1, we can use the following command:

$ 7z d testfiles.7z testfile1

delete-file-from-7zip-compressed-file

Extracting files from archive file

With the help of 7zip, you can extract files from an already existing archive. This feature can be accessed using the ‘e’ function letter.

$ 7z e [archived-file]

For example, suppose we want to extract the ‘testfiles.7z’ archive.

ls-extract-7zip

Here’s how that can be done:

$ 7z e testfiles.7z

extract-7zip-file

Updating existing archived files

If you want, you can add new files to a previously created archived file, or you can even update the contents of existing files in the archive. This is made possible using the ‘u’ function letter.

$ 7z u [archived-file] [name-of-new-or-updated-file]

For example, here is the directory structure in which we will perform some update operations.

directorystructure-linux

Let’s say we have already created an archive of the ‘dir1’ directory. And now, due to some modifications in, let’s say, file1, file2 and file3, we want to update the archive.

So, instead of individually adding the modified files again (using the ‘a’ function letter) to the archive, we can perform the operation in a single run by using the following command.

$ 7z u dir1.7z

update-7zipfile-linux-command-line

Testing integrity of archived files

Using the tool, you can also check the integrity of an already existing archive file. Testing integrity is very important, as it tells, whether the contents are properly archived or not.

Sometimes, due to a hardware problem, RAM problem, or heating problem, your files may get affected and the archive isn’t created properly. To check whether the archive is corrupted or not, you can use the ‘t’ function letter.

$ 7z t [archived-file]

For example:

$ 7z t testfiles.7z

Here is the output

integrity-check-7zip-linux

Above output shows that the contents of the archive are not corrupted.

Conclusion

7 zip tool happens to be one of the best tools for archiving files. It’s available for both Windows and Linux, although only a command line port is available for the latter platform, so a good option for those Linux users whose work involves playing with files on the command line.

What we’ve discussed in this tutorial are only basic features. There are also several advanced options available. Head to the tool’s man page (man 7z) for more information and details.

The post How to use 7zip Compression tool from Linux Terminal first appeared on LinuxTechi.]]>
https://www.linuxtechi.com/7zip-compression-tool-linux-terminal/feed/ 4