Feb 08
Imagine you have a pdf-file you want to make ocr-recognition. Take a scenario where you want to automatically let your linux pc do the job, e.g. in a folder.
I choose tesseract-ocr as ocr-programm. Easy to install and use and ok for my use. Unfortunately it takes only tif as input file type so that we have to convert the pdf to tif first.
To create a tif file with Ghostscript from pdf:
1
| gs -q -r300 -dBATCH -dNOPAUSE -sDEVICE=tiff24nc -sOutputFile=Dokument2.tif Dokument1.pdf |
Now start OCR-recognition with tesseract-ocr (maybe you have to install it).
1
| tesseract Dokument2.tif doc.txt -l deu |
-l deu means “Deutsch” for German language recognition.
-r300 means 300 DPI
Now it is easy to create a script which will automatically check a folder for new files and start ocr etc.
E.g. you can create a shell-script and start this shell script via cronjob. Maybe I will write an example here later.
Tagged with: Linux • ocr • pdf • tif
Jan 16
If you want to printout or save info from manpages simply type:
1
| man -t man | ps2pdf - > man.pdf |
Tagged with: Linux • man • pdf • Shell
Dez 20
If you want to download a file with curl type the following code into bash:
1
| curl -O http://www.url.de/file.html |
-O means to output to a file and not to stdout, normally the screen.
What if you need to resume a download of a big file?
1
| curl -C - -O http://www.url.de/file.html |
With -C – you continue downloading the current file. If is important to write -C -. Don’t forget the -
You can also set a referrer and the user agent.
1
| curl -C - -O -A http://www.url.de -e "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6" http://www.url.de/file.html |
With -A you can set the referrer and -e sets the user agent.
Pretty helpful.
Tagged with: Bash • curl • download • Linux • mac
Dez 14
After unpacking the Kernel Archive to “/usr/src” use the following:
1
2
3
4
| make dep
make clean
make bzImagemake modules
make modules_install |
Tagged with: compile • kernel compilation • Linux
Dez 02
How to send an email with telnet via smtp for testing purposes? Here is an example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| telnet smtp.me.com 25
220 smtp.web.de ESMTP Web.de V4.91#2 Sun, 24 Nov 2009 16:51:20 +0100
helo yourcomputername
250 smtp.web.de Hello yourcomputername [219.99.999.999]
mail from: account@web.de
250 account@web.de is syntactically correct
rcpt to: empfaenger@provider.tld
250 empfaenger@provider.tld verified
data
354 Enter message, ending with . on a line by itself
To: anton@tirol.at;
From: hugo@schlaumeier.de
Subject: Jodelei
Servus!
Greetz,
Peterli
.
250 OK id=18Z6Uc-0001wm-00
Quit
221 smtp.web.de closing connection |
To send mail with auth:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| telnet smtp.me.com 25
220 smtp.web.de ESMTP Web.de V4.91#2 Sun, 24 Nov 2009 16:51:20 +0100
helo yourcomputername
250 smtp.web.de Hello yourcomputername [219.99.999.999]
auth login
334 VXNlcm5hbWU6
<base64 encoded username>
<repeated base64 encoded username>
<base64 encoded password>
<repeated base64 encoded password>
235 Authentication successful
mail from: account@web.de
250 account@web.de is syntactically correct
rcpt to: empfaenger@provider.tld
250 empfaenger@provider.tld verified
data
354 Enter message, ending with . on a line by itself
Subject: Jodelei
Servus!
Greetz,
Peterli
.
250 OK id=18Z6Uc-0001wm-00
Quit
221 smtp.web.de closing connection |
To base64 encode your username or pass, use another linux terminal and type:
1
2
| printf username | base64
printf password | base64 |
If you don’t have base64 on your system try mimencode instead.
Tagged with: email • Linux • send email • send mail via telnet • smtp • telnet
Dez 02
To scroll in screen-mode of linux type the following:
Strg+a then AltGr+8
Now you can scroll up and down. This is called the copy-mode.
Source: http://blog.pregos.info/2009/02/26/scrollen-im-screen/
Tagged with: Bash • Linux • screen • scroll
Nov 30
This is an example from http://www.linux-user.de/ausgabe/2001/07/030-split/split.html:
1
| tar cz /home/user | split -b95m - archiv.tgz.split. |
Put together files with:
1
| cat [dateiname].split.* | tar x |
Tagged with: archive • cat • Linux • split files • tar
Nov 25
To replace a string in all files inside a folder you can create a bash file:
Put inside this file:
1
2
3
4
5
6
| #!/bin/bash
for file in $(ls -1);
do
sed 's/me/you/g' $file > /tmp/dummy.txt;
mv /tmp/dummy.txt $file;
done |
Save it and make it executeable (chmod 777 replace.sh)
In this case the string “me” will be replace with “you” in all files of the actual folder and the files will be overridden.
Another example
Your want to replace the tag <b> with <strong> in all files inside a special folder. Further you want to backup the original files with suffix .old and the new files will be overridden.
Simply type on the console:
1
2
3
4
5
| for file in $(ls -1);
do
mv $file $file.old
sed 's/<b>/<strong>/g' $file.old > $file;
done |
You can modify the script(s). Maybe by adding parameters etc.
Another option is to use sed with -i command or direct editing:
1
2
3
4
| for file in $(ls -1);
do
sed -i 's/text_to_replace/text_replacement/g' $file
done |
Tagged with: Bash • Linux • mac • search and replace • sed
Nov 25
People often underestimate the usefulness of the linux-command screen.
What does screen do? Screen creates a terminal session for the actual user.
Type:
to create a terminal session.
Or type:
1
| screen -S <sessionname> |
where <sessionname> should be replaced with your own name.
Create a new window:
which means (Press Control and a together and after that press c)
Now we created a second window. To list all created windows in the actual session type:
Germans have to press Shift+2 for “.
Now the two created windows will be shown:

Just choose one Window and press enter.
To quit your actual work an detach the session:
To list all active sessions:
You should see a similar picture like the following:

Here you can see the name of the session: 1597.stefan
To restore the session simply type:
Maybe you have to type the complete id with 1597.stefan if there exist another session with the same name.
Tagged with: Bash • Console • Linux • mac • sreen
Nov 19
When switching from Mac to Linux and vice versa, I always have to think a bit about how to use the command top and sort by CPU.
With Linux it is
top
and then press
shift+p
Mac:
top -o cpu
I hope I can remember this
Tagged with: Bash • commands • Linux • mac • top