For example
find /Users/xxx/Desktop/directory|grep customtext$|awk ‘{print “sed -i -e ‘\”s/aaa/bbb/g’\” ” $1}’|sh
Archive for the ‘Linux/Unix’ Category
edit content of multiple files in place on Linux
Posted in Linux/Unix on October 16, 2018| Leave a Comment »
add a remote host to ~/.ssh/know_hosts
Posted in Linux/Unix on March 15, 2018| Leave a Comment »
ssh-keyscan -H remote-host-domain-or-ip >> ~/.ssh/known_hosts
run system process from java
Posted in JAVA/J2EE, Linux/Unix on October 18, 2017| Leave a Comment »
working example:
String [] cmd ={“/bin/sh”,“-c”,“sleep 60;nohup ls -l /Users/zcai/Downloads > /Users/zcai/Downloads/tmp.txt &”};
ProcessBuilder builder = new ProcessBuilder(cmd);
Tomcat startup, 8443 or 8080 address already in use
Posted in JAVA/J2EE, Linux/Unix on January 15, 2014| Leave a Comment »
delete ^M characters at end of lines in vi
Posted in Linux/Unix on August 20, 2013| Leave a Comment »
:%s/.$//
Tomcat not working for port 80 under Linux (Ubuntu)
Posted in Linux/Unix on February 28, 2013| 1 Comment »
By default, tomcat listens on port 8080, which is specified in the following file./var/lib/tomcat7/conf/server.xml
<Connector port=”8080″ protocol=”HTTP/1.1″
connectionTimeout=”20000″
URIEncoding=”UTF-8″
redirectPort=”8443″ />
If you want tomcat to listen on a port other than 8080, you just need to make change to the file to modify 8080 to other number, save the file and restart tomcat. However, if you want tomcat to listen on port 80, it will work, that is bacause only root user can visit port numbers below 1024.
Here is the solution to set tomcat listening on port 80: Forward port 80 to port 8080
sudo iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8080
sudo iptables-save > ~/my_iptables.rules
or if you have saved the iptables, you can restore it:
sudo iptables-restore < ~/my_iptables.rules
curl and wget
Posted in Linux/Unix on November 20, 2012| Leave a Comment »
curl is similar with wget, and the difference is that wget save the web page and curl display the content of the web page on the screen.
For example,
curl ifconfig.me will show your ip address on the screen through the web site ifconfig.me
configure a virtual internal network and use a Ubuntu as the gateway to access internet
Posted in Linux/Unix on November 19, 2012| Leave a Comment »
Problem:
There is an internal network without internet access, and I want each node of the internal network to be able to access internet.
Solution:
Use one node of the internal network as the gateway. On the gateway node, there are two network interface cards: eht0 and eth1. eth0 connects the internal network and eth1 connects internet. Configure the route table on the gateway node to forward packets from eth0 to eth1.
Example:
Set up 9 Ubuntu virtual machine under Virtualbox with the following hostnames and ip addresses:
ubuntu1 192.168.10.1
ubuntu2 192.168.10.2
ubuntu3 192.168.10.3
ubuntu4 192.168.10.4
ubuntu5 192.168.10.5
ubuntu6 192.168.10.6
ubuntu7 192.168.10.7
ubuntu8 192.168.10.8
ubuntu100 192.168.10.100 (used as gateway)
Configure gateway
set up two network interface cards (Adapter1 and Adapter2) on ubuntu100 192.168.10.100:
Adapter1 connects internal network
configure gateway route table:
sudo sh set_gateway.sh
sudo iptables-save
————————————————————————-
refer to: http://www.debian-administration.org/articles/23
zhengqiu@ubuntu100:~/Desktop$ more set_gateway.sh
#!/bin/sh
PATH=/usr/sbin:/sbin:/bin:/usr/bin
#
# delete all existing rules.
#
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
# Always accept loopback traffic
iptables -A INPUT -i lo -j ACCEPT
# Allow established connections, and those not coming from the outside
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state –state NEW ! -i eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o eth0 -m state –state ESTABLISHED,RELATED -j ACCEPT
# Allow outgoing connections from the LAN side.
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
# Masquerade.
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
# Don’t forward from the outside to the inside.
iptables -A FORWARD -i eth1 -o eth1 -j REJECT
# Enable routing.
echo 1 > /proc/sys/net/ipv4/ip_forward
————————————————————————–
configure the two network cards on the gateway server 192.168.10.100:
restart network
$sudo /etc/init.d/networking restart
Configure node
on each node, configure network interface and nameserver like the example on ubuntu5 192.168.10.5 below:
On each node of the internal network, you will be able to access the internet.
Linux: difference between su and su –
Posted in Linux/Unix on November 16, 2012| Leave a Comment »
without the dash (su anatherusername), only change the UID and username of the system
with the dash (su – anotherusername), change the UID and username of the system, and also inherit the user environment.
Run a program automatically as a non-privileged user on Ubuntu boot
Posted in Linux/Unix on November 16, 2012| Leave a Comment »
The post takes mongoDB shard server as an example to demostrate running a program automatically as a non-privileged user on Ubuntu boot. Every time you reboot the system the mondod shard server starts automatically.
sudo mkdir -p /mongodb/data/shard12
sudo mkdir -p /mongodb/logs
#add a user named mongodb
sudo adduser mongodb
sudo chown -R mongodb:mongodb /mongodb
sudo vi /etc/init.d/run_mongod_shardsvr.sh (add the following two lines in this file)
#!/bin/bash
su – mongodb -c “/home/zhengqiu/mongodb-linux-x86_64-2.2.1/bin/mongod -shardsvr -replSet shard1 -port 27017 -dbpath /mongodb/data/shard12 -logpath /mongodb/logs/shard12.log -fork &”
sudo chmod +x sudo vi /etc/init.d/run_mongod_shardsvr.sh
#asign the script to detault runlevel
sudo update-rc.d run_mongod_shardsvr.sh defaults
reboot the system and the output of the script shown on the screen