Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Sunday 10 November 2013

JPEG To PDF With Imagemagick

ImageMagick is an awesome toolkit with several powerful features for image creation and manipulation. You can use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bezier curves. Here, I will show how you can use ImageMagick suite to convert JPEG to PDF quickly.

First make sure imagemagick suite is installed in your system.

Ubuntu/Debian
$ sudo apt-get install imagemagick


CentOS/Fedora
$ sudo yum install imagemagick


Below are some of the examples of using convert which is a part of ImageMagick to convert Jpeg to PDF.

Single Image
$ convert image.jpg image.pdf


Multiple Images
$ convert 1.jpg 2.jpg 3.jpg output.pdf


Resize and Convert
$ convert -resize 80% image.jpg image.pdf


Negate and Convert
$ convert -negate image.jpg image.pdf


You can actually use different available switches to get your output as expected. I usually use PdfTk in conjunction with this technique to work in different scenarios and it really works great. I hope this helps :)


Read more...

Wednesday 30 January 2013

Search Text Over Multiple PDF Files In Linux

You can use the old grep command or the small script using the pdftotext command to search text over multiple pdf files but we are talking about a simple utility that lets us to search text in PDF files.

The pdfgrep tool lets you perform grep style search over multiple pdf files easily from the terminal. It depends upon the poppler package and under ubuntu, you can just type the command below to install pdfgrep.

samar@\Techgaun:~$ sudo apt-get install pdfgrep


Once pdfgrep is installed, you can perform any kind of search like you would do while using the grep command. Enjoy grepping the PDF files :)


Read more...

Tuesday 29 January 2013

Swasthani.com Swasthani Ripper

Yesterday I came to know that I can listen Swasthani online at this site, www.swasthani.com and I decided to write a swasthani audio downloader. Since it would be useful for everyone, here is the script.

From the site itself, Sri Swasthani Brata Katha is a very popular ritual observed in Nepal in the Poush month (January – February) during winter. Goddess Sri Swasthani, known to grant wishes of her devotees, is worshipped for the whole month of Poush. The Swasthani Brat Katha (story) is recited everyday. The month long telling of the tales are dedicated to the Goddess and the stories that are mainly narrated are those of Swasthani Devi, Lord Shiva and other Gods.

#!/bin/bash
###############################################
# Swasthani.com Swasthani Ripper       #
# Samar @ http://www.techgaun.com       #
###############################################
if [[ ! -f /tmp/swasthani.txt ]]
then
 wget http://www.swasthani.com/ -O - | egrep '<li class="leaf( first| last)?"><a href="/swasthani/' | grep -o '<a .*href=.*>' | sed -e 's/<a /\n<a /g' | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' > /tmp/swasthani.txt
fi

while read -r line
do
 wget "http://www.swasthani.com$line" -O - | egrep 'data="soundFile=http://www.swasthani.com/system/files/' | cut -d\" -f6 | cut -d= -f2 | wget -nc -i -
done </tmp/swasthani.txt


Save the above file as swasthani, then chmod for executable permission and run it. If you have problem copying above code, you can check the Swasthani Downloader at GitHub. Enjoy listening Swasthani, geeks :)


Read more...

How To Check Which Groups You Belong To

In this post, you will get to know about a simple command that lets you know what groups the particular user belongs to. Users and groups are the one of the several concepts employed in the Linux systems for access control.

From the man page, the groups command does is:
Print group memberships for each USERNAME or, if no USERNAME is specified, for the current process (which may differ if the groups database has changed).

So if you are interested in finding what group a particular user is in, run the command as below. Replace samar with your USERNAME and you are good to go:

samar@Techgaun:~$ groups samar

samar : samar adm cdrom sudo vboxusers ....


I hope this proves useful :)


Read more...

Saturday 27 October 2012

Accelerate Your Softwares Update Speed Using Apt-fast

Long ago, I had posted about apt-fast script which used axel to create multiple HTTP connections and increase the download speed of software updates and packages. In this post, you will get the details for installing apt-fast from PPA. apt-fast is a shellscript wrapper for apt-get and aptitude that can drastically improve apt download times by downloading packages in parallel, with multiple connections per package.

As a pre-requisite, we will first install axel, a simple yet very useful command line download accelerator. Alternatively, you can also use aria accelerator with apt-fast.

samar@samar-Techgaun:~$ sudo apt-get install axel


Then you will have to add a PPA for apt-fast, update the database, and install apt-fast.

samar@samar-Techgaun:~$ sudo add-apt-repository ppa:apt-fast/stable
samar@samar-Techgaun:~$ sudo apt-get update
samar@samar-Techgaun:~$ sudo apt-get install apt-fast


You need to configure few options afterwards as below:







For manual installation and grabbing the source code, check the GitHub.

Once you install apt-fast, you can install softwares and perform updates from the repos using the command below:

samar@samar-Techgaun:~$ sudo apt-fast install package_name


I hope this becomes useful :)


Read more...

Linux Cat Command Examples

Sunday 21 October 2012

Enable Auto Correction Of Path In Bash

While using the cd command, its normal to make mistakes while typing the directory path. You can enable auto-correction while typing directory path by enabling a particular shell option.

Minor spelling mistakes will be corrected automatically if the particular shell option cdspell using the SHell OPTions command invoked with shopt command.

When you enable the cdspell shell option, the errors checked for are missing characters, repeated characters, and transposed characters. Once the error is encountered, the corrected path is printed and directory is changed successfully.

samar@samar-Techgaun:~$ shopt -s cdspell
samar@samar-Techgaun:~$ cd Desktp
Desktop
samar@samar-Techgaun:~/Desktop$ cd ../Deskotp/
../Desktop/
samar@samar-Techgaun:~/Desktop$ cd ../Desktoop
../Desktop
samar@samar-Techgaun:~/Desktop$


The line shopt -s cdspell enables the auto-correction while using cd command. The session above shows some of the corrections performed once we enabled the cdspell shell option.

If you want to turn on this particular setting, then add the appropriate line using the command below:

samar@samar-Techgaun:~$ echo "shopt -s cdspell" >> ~/.bash_profile


I hope this counts as useful tips to beginner linux guys ;)


Read more...

Tuesday 16 October 2012

Practical ls Command Examples For Fun & Profit

The power of linux lies in the shell through which we can perform complex job in no time. While the directory listing command 'ls' seems to be very simple command, the linux shell provides the power to use switches and pipes to do anything from terminal. Check out this list with practically useful examples using ls.

Display all files including hidden files/folders

ls -a


Display one file/folder per line

ls -1


Count number of files & folders

ls -1 | wc -l


Human readable file sizes (eg. Mb or Gb)

ls -lh


Alphabetically sort the listing

ls -X


Only list the folders in current directory

ls -d */
ls -p | grep /




Display folders in current directory consisting certain patterns

ls -l D* | grep :$
ls -l *a* | grep :$


List files by descending order of modification time

ls -lt
ls -l --sort=time #alternative long version


List files by descending order of creation time

ls -lct


List files in reverse order

ls -ltr
ls -l --sort=time --reverse #alternative long version


List files in descending order of file size

ls -lSh
ls -lh --sort=size
ls -lSh1 *.avi #find largest AVI file
rm `ls -S1 | head -1` #delete largest file in current folder


List files in ascending order of file size

ls -lShr
ls -lh --sort=size --reverse #alternative long version


Display directories in recursive manner

ls -R


Display the files/folders created today

ls -l --time-style=+%F | grep `date +%F`


Display the files/folders created this year

ls -l --time-style=+%y | grep `date +%y`


Any more example that fires up in your mind? Feel free to share over here ;)


Read more...