How to convert character encoding in text files

Here is how to convert text files from one character encoding to another in GNU/Linux:

#eg1
iconv -f ASCII -t UTF-8//IGNORE file.txt -o output.txt

#eg 2
iconv -f ISO-8859-1 -t UTF-8//TRANSLIT file.txt output.txt

The -f parameter denotes “from” and -t parameter denotes “to” character set.
//IGNORE means the “iconv” will ignore any characters that are not available in the target character set.

While “//TRANSLIT” means the converter will attempt to substitute characters that are not available in the target character set to the closest characters available, failing that, “???” will be replaced in its place.

Most GNU/Linux distribution have iconv preinstalled, if not, please consult your distribution documentation.

How to convert Microsoft Office *.docx files to PDF using Linux in command-line

Here’s how to convert Microsoft Office *.docx files to PDF using Linux in Command Line.
This trick can also be used together with other documents files supported by LibreOffice

First make sure you’ve installed the latest version of LibreOffice for use in command line environment.
Assuming the user is ‘example’ and the filename to convert is ‘doc.pdf’.

libreoffice --headless -convert-to pdf --outdir /home/example/ /home/example/doc.docx

The conversion can also be adapted to PHP or Python using their respective shell_exec or subprocess directive.

Find largest file in Linux server using “du”

Short on diskspace? You can use ‘du’ to find largest files in your linux server using ‘du’ tool.

 

du --total -sh /path/*

Additionally you can also include a ‘threshold’ parameter to list only file larger than the unit which you’ve specified, by using “-t” parameter.

Example, list files larger than 100MB

du --total -sh -t100M /path/*

You can use “M” for megabytes, “G” for gigabytes and “P” for Petabytes. Positive number denotes files must be at least the specified size. Negative number means the files must be at most the specified size.

How to build and use telegram-cli client for Linux

You can actually send Telegram message from command-line interface / bash in Linux using an unofficial telegram-cli client by Vitali Valtman (vysheng)

Obtaining and Compiling telegram-cli

But first, before sending telegram messages, you need to build the client. You may start by installing its dependencies

 sudo git apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make 

Then, you can get the latest telegram-cli client from vysheng GitHub

 git clone --recursive https://github.com/vysheng/tg.git && cd tg

Afterwards, you may configure ‘telegram-cli’ and compile it

./configure
make

Alternative Download
Alternatively, you can download Telegram source code from my server:

  1. https://mypapit.net/pub/telegram-cli/tg.tar.bz2
  2. https://mypapit.net/pub/telegram-cli/tg.tar.xz

 

Running telegram-cli

After finished compiling telegram-cli, you may try and start using telegram.

bin/telegram-cli -k tg-server.pub

For first time use, you may need to key in the authorization code, the code will be sent to your mobile device to allow ‘telegram-cli’ to log as your username.

bin/telegram-cli -u  -k tg-server.pub

In my experience you may need to replace the +[country_code] phone-number with ’00’. so if your phone number includes country code is +60123456789, then you must replace it with 0060123456789 (however, your mileage may vary.

bin/telegram-cli -u 00123456789 -k tg-server.pub

Once the authorization CODE has been entered, you are free to use telegram. Telegram use the concept of ‘peer’ (contact) to send messages instead of phone number. So in order to get a list of your peer, you need to run “contact_list” command.

telegram-cli-contact-list

> contact_list
John_T_Doe
Jane_doe_2
Warrick_Brown
Mark_Nelson

To send message to a peer/contact (for example to Warrick Brown), just type

> msg Warrick_Brown "wassup, dude? want to hang out today?"

To quit, you can type

#telegram-client
> safe_quit

NOTE: IF YOU FAIL TO COMPILE TELEGRAM FROM GITHUB
If you find it difficult or failed to compile telegram-cli from GitHub, then you can download this telegram-cli source code from my server which is tested to compile under Raspbian Jessie, Debian Jessie, Ubuntu 14.04 LTS and Ubuntu 16.04 LTS.

Alternative Telegram source code:

  1. https://mypapit.net/pub/telegram-cli/tg.tar.bz2
  2. https://mypapit.net/pub/telegram-cli/tg.tar.xz