33篇 shell related articles

ubuntu: Read-only file system

文件系统挂了,变成只读模式。supervisor无法启动,就连ping 域名时无法解析dns,想要修改/etc/resolve.conf,只读也写不进去。
试下往临时目录写也是这:

touch /tmp/aaa.txt
touch: cannot touch '/tmp/aaa.txt': Read-only file system
More ~

CRLF to LF

You can use vim programmatically with the option -c {command} :

Dos to Unix:

vim file.txt -c "set ff=unix" -c ":wq"

Unix to dos:

vim file.txt -c "set ff=dos" -c ":wq"

"set ff=unix/dos" means change fileformat (ff) of the file to Unix/DOS end of line format

":wq" means write file to disk and quit the editor (allowing to use the command in a loop)

More ~

使用iptables进行端口转发

使用iptables进行端口转发,如下,需要访问原主机的27017端口,但是没开放,只开放了5000-6000之间的端口,因此 需要映射 一个5027端口去访问27017 这个mongodb。

iptables -t nat -A PREROUTING  -p tcp --dport 5027 -j DNAT --to-destination :27017

列表:

iptables -t nat --list

删除
PREROUTING 后跟的index 索引从1开始

iptables -t nat --delete PREROUTING 2
More ~

for a-z in bash shell

for x in {a..z}
do
    echo "$x"
    mkdir -p path2/${x}
    mv path1/${x}*.ext path2/${x}
done

One line with upper case example:

for letter in {A..Z} ; do wget http://www.abc.com/Letter_${letter}_Cap.gif;done;
More ~