Posts Tagged ‘cli’

tree command

September 7, 2019 Leave a comment

You want to visualize the tree structure of the current directory.

You need the “tree” command. Under Manjaro it was not installed by default, but of course it could be installed easily with the package manager.

$ tree
├── greetings
│   ├──
│   └──

1 directory, 3 files

If you want to ignore a subdirectory, use the “-I” option:

$ tree -I target
├── Cargo.lock
├── Cargo.toml
├── src
│   ├── greetings
│   │   ├──
│   │   └──
│   └──
└── src.old

3 directories, 6 files

Categories: linux Tags: , , ,

reddit from the terminal

September 7, 2015 Leave a comment

There is a command line interface for Reddit called “rtv” (reddit terminal viewer). It’s written in Python, so you can install it with pip.

Here is a short youtube video on how to use it.

Categories: bash, linux, python Tags: , ,

open a terminal in a specified folder

From a script I want to launch a terminal that opens in a specified folder.

Thanks to #linux, I got two solutions:

A1) I use konsole, which has an option for this:

konsole --workdir /tmp

It will open a terminal in the /tmp directory.

A2) Change directory to the specified folder and launch the terminal:

cd /tmp; konsole

If you want to do it from a script, the idea remains the same.

B) If you want to execute a command automatically in the opening terminal, use this:

konsole -e mc

C) Set the title of Konsole to a specified text:

konsole -p tabtitle='NVIM server'

Find more info here.

Categories: bash, linux Tags: , ,

a terminal-based YouTube player

November 2, 2014 Leave a comment

mps-youtube is a terminal-based YouTube player and downloader. If you use YouTube a lot for listening music, then you must give it a try.


Categories: python Tags: , , ,

Manipulate your PDFs with pdftk

February 21, 2011 Leave a comment

If PDF is electronic paper, then pdftk is an electronic staple-remover, hole-punch, binder, secret-decoder-ring, and X-Ray-glasses. Pdftk is a simple tool for doing everyday things with PDF documents.” (source)

Pdftk is a great command-line tool to manipulate your PDF files.


sudo apt-get install pdftk

The following examples are taken from here.

Merge Two or More PDFs into a New Document

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

or (Using Handles):

pdftk A=1.pdf B=2.pdf cat A B output 12.pdf

or (Using Wildcards):

pdftk *.pdf cat output combined.pdf

Split Select Pages from Multiple PDFs into a New Document

pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf

Encrypt a PDF using 128-Bit Strength (the Default) and Withhold All Permissions (the Default)

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foopass

Same as Above, Except a Password is Required to Open the PDF

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz

Same as Above, Except Printing is Allowed (after the PDF is Open)

pdftk mydoc.pdf output mydoc.128.pdf owner_pw foo user_pw baz allow printing

Decrypt a PDF

pdftk secured.pdf input_pw foopass output unsecured.pdf

Join Two Files, One of Which is Encrypted (the Output is Not Encrypted)

pdftk A=secured.pdf mydoc.pdf input_pw A=foopass cat output combined.pdf

Uncompress PDF Page Streams for Editing the PDF Code in a Text Editor

pdftk mydoc.pdf output mydoc.clear.pdf uncompress

Repair a PDF’s Corrupted XREF Table and Stream Lengths (If Possible)

pdftk broken.pdf output fixed.pdf

Burst a Single PDF Document into Single Pages and Report its Data to doc_data.txt

pdftk mydoc.pdf burst

Report on PDF Document Metadata, Bookmarks and Page Labels

pdftk mydoc.pdf dump_data output report.txt

pdftk uses the iText Java library ( to read and write PDF. The author compiled this Java library using GCJ ( so it could be linked with a front end written in C++.” (from the man)

Update (20110611)
You can also “explode” a PDF, i.e. split it into a set of individual pages:

pdftk file.pdf burst

Related links

Command line scripting in PHP

February 17, 2011 Leave a comment

When talking about command line scripting, most people think of Python or Perl. But it’s good to know that you can do something similar with PHP too!

Example (hello.php):

   # /etc/php5/cli/php.ini
   # The configuration file for the CLI version of PHP.

   print "Hello, World!\n";

You can execute it with “./hello.php” or “php hello.php“.

Notice that the command line version of PHP uses a different php.ini file.

Consult this page to learn more.

Categories: php Tags:

Command line calculator with Python

February 10, 2011 3 comments


You use the command line terminal a lot and sometimes you need a simple calculator. Is one available in command line?


Of course. It’s called Python interpreter :) Python is usually available everywhere and its command line interpreter is a perfect calculator too.


C:~> python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 45 + 98
>>> _ + 7
>>> _ / 2.0

Cannot be any simpler. As you can see, the special variable ‘_‘ (underscore) gets the value of the previous computation. Division between two integers returns the whole part, thus 7 / 2 is 3. What you need is usually 7 / 2.0, which is 3.5.

You can quit with CTRL+D.


I use this calculator quite often, so I added the following line to my ~/.bashrc:

alias p='python'
Categories: bash, python Tags: ,