Labels

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, 11 March 2019

Split multi-paged PDF file in to individual PDF files

You might come across a situation where you have a PDF file with multiple pages and you'd like to split each page in to each PDF file. Sound pretty tedious task right?

It's just as simple as executing a single command. All you gotta do is, make sure you have pdftk (PDF Tool Kit) installed on your Linux machine.

If you do not have the pdftk installed, follow the below steps:

For(Ubuntu/Debian)


sudo apt update

sudo apt install pdftk 

 For(CentOS/Fedora), follow the instructions in the link below to install it:

https://www.pdflabs.com/docs/install-pdftk-on-redhat-or-centos/

Once installed, use the below command to split a single multi-paged PDF file to individual PDF files with each page

$pdftk your_multi-page_file.pdf burst

This will split each page from multi-page PDF file to each individual PDF file.


Similarly, to merge few selected PDF files in to one PDF file, use the following command:

$pdftk file1.pdf file2.pdf cat output mergedfile.pdf

If you want to merge all the PDF files in a specified directory, you may use the wild card character(*) as follows:

$pdftk *.pdf cat output mergedfile.pdf

'*' implies all the files with .pdf extension

You may find few more tips on dealing with PDF files here

Wednesday, 6 March 2019

How to open horizontal and vertical split mode to work with multiple files in VIM

Horizontal split mode

vim -o file1.txt file2.txt

Vertical split mode

vim -O file1.txt file2.txt

Now to switch between these files use Ctrl + W + W to toggle between these files.

By using these commands we can open n number of files.

Saturday, 8 September 2018

Useful and Important commands for Fedora 28

After fresh installlation:

sudo dnf update  

Enable and start SSH:

sudo systemctl start sshd.service

sudo systemctl enable sshd.service

RPM Fusion:

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

Install Vlc:

sudo dnf install vlc

Restart apache:   

systemctl restart httpd  
                       or
service httpd restart
  
Enable apache on startup:

systemctl enable httpd

Allow http connections:

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

Install  php and Mysql(mariadb):

dnf install php-cli
dnf install mariadb mariadb-server
systemctl restart mariadb

finalize mariadb installation

/usr/bin/mysql_secure_installation
dnf install php-mysqlnd (For php-mysql driver)

After doing all these restart apache

systemctl restart httpd

Make a bootable USB DRIVE(pendrive) in Linux

After Ubuntu 12 making a bootable pendrive using startup disk creator has not been smooth and has been difficult to do. Ofcourse this can be used in other linux platforms too.

There is a new software "Ether" that is cross platform, open source tool in the market to burn images to SD card and USB. It’s called Etcher.


Download Etcher AppImage from the link below:

Once downloaded, you need to make it executable. Right click on the downloaded file and go to Properties


And in here, check the “Allow executing file as program” option.

Then double click Etcher, Click on Select image and browse to the location where you have downloaded the ISO. Etcher automatically recognizes the USB drive. You can change it if you have multiple USBs plugged in. Once it has selected the ISO and USB drive, it’ll give you the option to flash the ISO to USB drive. Click on Flash do start flashing the drive with the selected ISO.

By the end of this process you will have a bootable USB drive with your ISO. 

 Reference and Credits: https://itsfoss.com/create-fedora-live-usb-ubuntu/

Monday, 27 August 2018

Crontabs - Job scheduler explained

Open crontab using below command:

 

crontab -e 

 

Its syntax is like below 


* * * * * command/script to be executed/

# Example of job definition:

 

# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

Listing of Cronjobs can be done using below command: 

 

crontab -l 

 

 Examples:  

 

1. Take backup every day midnight.


0 0 * * * /my/path/to/script/backup.sh

2. Start mongo server @reboot


@reboot /usr/bin/mongod


3.  Mysql database backup every sunday


* * * * 0 /usr/bin/mysqldump -u root -p{root123} userdb2 &gt; /home/nagaraju/myfile_$(date +\%Y-\%m-\%d).sql&nbsp;&nbsp; #every week on Sunday<br />

Monday, 27 November 2017

Mongo error "Two many open files", mongod server does'nt start

Solution 1(temporary and tested):

If you're using bash, ulimit -n will only display the soft limit. To get the hard limit, you need to do ulimit -Hn.

On my system, I see this:

$ ulimit -n
1024  

 Set ulimit value to new value as following:
 
 $ ulimit -Hn
4096


ulimit -n <value> (this will only set for current session, better do it in a screen mode and run it in background)

 More info: Here

Solution 2(permanent and not tested):

Modify /etc/security/limits.conf with what you need. Example:

user soft nproc 64000

Restart machine to make the changes effective.

More info: Here

Resolve gedit open issue when opening from remote machine

What happens is  sometimes when we try  to ssh into a system and open gedit in that machine(remote) everything seems fine until we try to  type something or save into that file or even we cannot open other files using Open menu in file tab.

So the solution here is:

Use nautilus/gedit on local machine

1. Open a nautilus file browser window and select "connect to server" from the menu in the top panel.

2. Enter in the server(remote) info (use ssh:// or sftp:// for ssh connections).

3. Enter password and there you go. You will be connected to the remote machine and now your gedit works fine.


Courtesy: this answer from ask ubuntu is where I found the solution.





Monday, 16 October 2017

Creating a backup of installed ubuntu(ISO image)

1. Download Relinux 0.2 from

http://sourceforge.net/projects/re-linux/?source=directory

                                     OR

http://nchc.dl.sourceforge.net/project/re-linux/relinux_0.2.1b1.tar.gz

2. Create a folder "relinux" on Desktop and extract the content from the above link to this folder.

3. To install, simply type this into a Terminal window( Read file relinux/INSTALL on Desktop for instructions):

$ sudo cp -R usr etc /

4. After you have installed it, look at Desktop/relinux/usr/share/doc/relinux/README.

   Type this into a Terminal window to generate the configuration file:
 
$ cp /etc/relinux/relinux.conf ./relinux.conf
 
$ sed -i 's:EXCLUDES="\(.*\)":EXCLUDES="\1 '`readlink -f ./relinux.conf`'":g' ./relinux.conf

5. Install Dependencies for Relinux :

$ sudo apt-get install libdebian-installer4 casper ubiquity ubiquity-frontend-gtk discover-config xresprobe tree dialog

6. Copy the file

Desktop/relinux/etc/relinux/relinux/splash/splash.png to Desktop

Edit relinux.conf for customisation from Desktop/relinux/

Replace the following line

SPLASHIMAGE=/etc/relinux/relinux/splash/splash.png
           
          with

SPLASHIMAGE=/home/ebs/Desktop/splash.png

7. Type the following command in terminal:

$ sudo relinux squashfs ./relinux.conf

8. Type the following command to prepare an iso file.

$ sudo relinux onlyiso ./relinux.conf

Reference Video link : http://ubuntutes.com/wp/index.php/2016/12/31/create-backup-of-installed-ubuntu-12-04-12-10-13-04-as-install-iso-using-relinux/

Monday, 18 September 2017

Most Effective Way To Reset Your Lost Password Or Forgotten Password Of MySQL.

You have to reset the password! steps for mac osx(tested and working) and ubuntu

Stop MySQL

$ sudo /usr/local/mysql/support-files/mysql.server stop


Start mysql in safe mode:

$ sudo mysqld_safe --skip-grant-tables

(above line is the whole command)

This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a  password:

$ mysql -u root

Now:

mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';


$ sudo /usr/local/mysql/support-files/mysql.server start

your new password is 'password'.

Sunday, 6 November 2016

A simple perl script to make a file content unique

This simple perl script does the job of sort -u (of course not in windows)

Script:


 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
37
38
39
#!/usr/bin/perl

use strict;

use warnings;


#File reading code

open(my $in,"<:utf8",$ARGV[0]) or die "Cannot open $ARGV[0]:$!\n";

my @in =<$in>;

close($in);


#declare hash

my %hash=();


#store content in hash

foreach my $in (@in) {

 chomp($in);

 $hash{$in} = 1;

}


#Finally print the hash

foreach my $keys(sort keys %hash){

 print "$keys\n";

}
How to run:

Lets assume that our script is saved as my_unique.pl 


$ perl my_unique.pl <filename>

* Without angular brackets.

Explanation:
Here in Perl hash the duplicate keys are overridden which means only single instance of each line in the file is stored in the hash. Remember that while storing the lines in hash each single line is treated as key so as to remove duplicates. 

Note: Always use strict and use warnings when dealing with Perl code so as to write bug free code.

Linux: How to find duplicate lines count in a file from terminal.

Linux has many commands that are useful to process/analyze a file. In this post I would just explain a simple utility that would just print out the number of times each line is repeated in that file.

So here is the command:

terminal$ sort yourfilename.txt | uniq -c

Here yourfilename.txt can be any file name which I used here for an example.
Suppose the contents of yourfilename.txt be

line1
line1
line2
line3
line1
line3

Output:

3 line1
2 line3
1 line2

Explanation:

The sort command is quite self explanatory over here its output is piped/redirected to uniq. Uniq command requires its input to  be sorted(keep in mind always hard to remember). Uniq -c just prints the count of each line.