Sunday, April 9, 2017

Do things Command-Line way in Ubuntu - part 1

Ubuntu Commands for some useful tasks

Below some useful commands for carrying out tasks in ubuntu via the terminal are mentioned :-

  1. Resize image
  2. Resize pdf
  3. Download mp3 audio from a Youtube video
  4. Convert any video file to lossless "flac" audio format
  5. Convert any video file to "mp3" audio format
 
  • Resize image :

convert -resize 50% -quality 99 IMG_20160623_203259.jpg output.jpg

convert is in package imagemagick

===============

  • Resize pdf :

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

If the -dPDFSETTINGS=/screen setting is too low quality to suit your needs, replace it with -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. Delete the setting altogether for the high quality default, which you can also explicitly call for with -dPDFSETTINGS=/prepress.

source : http://askubuntu.com/questions/113544/how-can-i-reduce-the-file-size-of-a-scanned-pdf-file

Alternate : pdfsam ( The version in ubuntu respository is old , latest version at http://www.pdfsam.org/downloads/ )

============

  • Rotate pdf :

sudo apt-get install pdftk (22 MB approx.)

pdftk in.pdf cat 1-endS output out.pdf

Alternate : pdfsam ( The version in ubuntu respository is old , latest version at http://www.pdfsam.org/downloads/ )

===========

  • Youtube download as mp3

1) To install it right away for all UNIX users (Linux, OS X, etc.), type:
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

2) If you do not have curl, you can alternatively use a recent wget:
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl

3) The command (requires ffmpeg package) : youtube-dl --prefer-ffmpeg --extract-audio --audio-format mp3 --audio-quality 0 "<video_watch_url>"

==========

  • Convert video file to lossless flac format

ffmpeg -i "input.mkv" -vn -sn -acodec flac audio.flac

==========

  • Convert video file to mp3 format

ffmpeg -i "input.mkv" -vn -sn -acodec mp3 audio.mp3