Bash: How to replace a string in a directory recursively
Combine find, xargs and sed.
find . -name "*.css" | xargs sed -i 's/BEFORE/AFTER/g'
Combine find, xargs and sed.
find . -name "*.css" | xargs sed -i 's/BEFORE/AFTER/g'
Define a function echo_count and count the function name to be called in the script. You can refer to a variable ${TOTAL} .For example,
#!/bin/bash
export TOTAL=$(( $(grep '^echo_count' $0 | wc -l) ))
export COUNT=1
function echo_count () {
echo -n "($(( COUNT++ ))/${TOTAL}) $1"
}
echo
echo_count 'Processing one - Stopping Apache2... '
sudo service apache2 stop
echo 'Done'
echo_count 'Processing two - '
echo 'Apache2 is not working.'
#!/bin/bash
export TARGET_DIR='./' # Current directory
export ORIGINAL_NAME='xxxxx'
export TARGET_NAME='yyyyy'
find "${TARGET_DIR}" -name '*${ORIGINAL_NAME}*' -execdir rename "s/${ORIGINAL_NAME}/${TARGET_NAME}/g" '{}' \;
AWS announced to provide their own internal NTP inside VPC at AWS re:Invent 2017. Here is how to do it:
CentOS
sudo yum erase ntp*; sudo yum -y install chrony; sudo service chronyd start
Debian/Ubuntu
sudo apt-get remove -y ntp*; sudo apt-get -y install chrony; sudo service chronyd start; apt-get autoremove
Add an option -o StrictHostKeyChecking=no into a ssh command:
ssh -o StrictHostKeyChecking=no your_username@example.com
OR
export TARGET_HOST='example.com'
if [ -z `ssh-keygen -F ${TARGET_HOST}` ]; then
ssh-keyscan -H ${TARGET_HOST} >> ~/.ssh/known_hosts
fi
ssh-keygen -R ${TARGET_HOST}
ssh-keyscan -f ~/.ssh/known_hosts ${TARGET_HOST} >>~/.ssh/known_hosts 2>/dev/null
Create a file for swap
======================
Create a file named /swapfile for 4GB size (e.g. Create a file called swapfile under root (/))
$ dd if=/dev/zero of=/swapfile bs=1024K count=4096
Format the swapfile with a mkswap command
======================================
$ mkswap /swapfile
Confirm the current swap file status
==========================
pi@raspberrypi ~ $ swapon -s
Filename Type Size Used Priority
/var/swap file 102396 0 -1
Specification - What I want to do
=================================
I would like to input in-out records at my company automagically by using Raspberry PI and detecting my iPhone's bluetooth signal. That is, I want to make bluetooth proximity checker with my Raspberry PI. The specification is:
Detect Bluetooth signal by Raspberry PI
When I come into my office, the system records the time to come into the office
When I leave from my office, the system records the time to leave out from the office
Integrate Google Sheet to record the time
That is only what I want to do. Think about the spending time to input the in/out time manually. We can reduce our precious 12-20 total hours through a year (Assuming 3-5 min per a day and 240 working days through a year in order to input the records). It can be converted to a half or a day.
Then, OK, Let's see how we can make it!
HTTP/2 has been supported since Apache 2.4.17. I tried sudo a2enmod http2 on this Ubuntu 16.04 host, however it said ERROR: Module http2 does not exist!. Looks I needed to upgrade Apache2 as follows:
sudo add-apt-repository -y ppa:ondrej/apache2
sudo apt-key update
sudo apt-get update
sudo apt-get --only-upgrade install apache2 -y
Select Y (Note that this will overwrite your current configuration; therefore do backup of apache2.conf if necessary.
*** apache2.conf (Y/I/N/O/D/Z) [default=N] ?
The following bash command deletes backup*.tar.gz files in a /var/www/html/backups directory by xargs rm -fr.
find /var/www/html/backups -mtime +2 -name "backup*.tar.gz" | xargs rm -fr