Leeladharan Achar - alias - leelu ~ blogging...hola mi amigos..'s Blog

Posted Feb. 14, 2018   1058 views

Handy Commands

Find in all files recursively for a specific string

find ./ -type f -name "*.*" -exec grep -inH "searchstring" {} \;

to search in all specific file extensions recursively

find ./ -type f -name "*.php" -exec grep -inH "searchstring" {} \;

In a specific directory search for specific file extension and count number of lines in them, ex:

find ./ -type f -name "*.txt" | xargs wc -l

cloning directory from one linux system to another using rsync

A machine ip -

B machine ip -

To do rsync from machine A to B, we should have sshd running on B machine to connect

To install sshd issue below commands on the machine as root

yum install openssh openssh-server openssh-clients openssl-libs 
systemctl enable sshd
systemctl restart sshd.service

To do rsync from a remote machine not in lan, you need to open port 22

Now on LAN to copy directory_of_images folder from machine A to machine B below is the command

login to machine A and from machine A issue below command

rsync -avz --ignore-existing -P /home/leela/directory_of_images/ leela@ 

In this clone suppose you want to exclude few directories present in directory_of_images while cloning to other machine below is the command

suppose if we wanted to exclude directories 2017 & 2016 inside directory_of_images

then create a file exclude_dir.txt and add below content


and save it and run below command from machine A

rsync -avz --ignore-existing -P --exclude-from='/home/leela/exclude_dir.txt' /home/leela/directory_of_images leela@