Archive for the ‘bash’ Category

How to convert a PDF to a “2 pages per sheet” PDF?

October 24, 2017 Leave a comment

Having a “1 page per sheet” PDF, how to convert it to a “2 pages per sheet” PDF?

I found the solution here. The answer is here. In short: install the package “pdfjam“, and use “pdfnup“, which is part of the package.

$ pdfnup input.pdf
Categories: bash Tags: , , ,

How to download files in parallel?

October 10, 2017 1 comment

So far I’ve mostly used wget to download files. You can collect the URLs in a file (one URL per line), and pass it to wget: “wget -i list.txt“. However, wget fetches them one by one, which can be time consuming. Is there a way to parallelize the download?

Use Aria2 for this purpose. It’s similar to wget, but it spawns several threads and starts to download the files in parallel. The number of worker threads has a default value, but you can also change that. Its basic usage is the same:

aria2c -i list.txt
Categories: bash Tags: , , , ,

How to extract .7z files?

October 10, 2017 Leave a comment

You have a .7z archive and you want to extract it.


7za e archive.7z
Categories: bash Tags: ,

How to randomize the lines of a file?

October 10, 2017 Leave a comment

You have a text file and you want to mix up its lines, i.e. you want to randomize the order of lines.


sort --random-sort input.txt
Categories: bash Tags: ,

Re-run a command in the terminal every X seconds

October 1, 2017 Leave a comment

You want re-execute a command in the terminal every X seconds. For instance, you copy a lot of big files to a partition and you want to monitor the size of the free space on that partition.

A naive and manual approach to the problem mentioned above is to execute the commands “clear; df -h” regularly, say every 2 seconds.

A better way is to use the command “watch“. Usage:

watch -n 2 df -h

That is: execute “df -h” every two seconds. watch will also clear the screen and print the result to the top. You can quit with Ctrl + c.

Tip from here.

Categories: bash Tags: ,

Setting the number of open files

September 29, 2017 Leave a comment

I installed Neo4j and when I started the server, I got a warning message: “Max 1024 open files allowed, minimum of 40 000 recommended.”

How to increase the number of open files?

With “ulimit -n” you can check the current value of the number of open files. By default, it’s 1024. To increase this value, follow these steps:

Open /etc/security/limits.conf and add these lines:

root   soft    nofile  40000
root   hard    nofile  40000
jabba  soft    nofile  40000
jabba  hard    nofile  40000

Here, instead of “jabba” use your account name. I use my Linux box under the user name “jabba”.

Open /etc/pam.d/su and add this line:

session    required

Restart your machine so that these changes take effect. Re-run “ulimit -n“; now it should display 40000.

Categories: bash Tags: , ,