Linux杂记

此帖子用于记录使用Linux过程中遇到的各种小问题。


1、使用ln命令跨分区链接目录时,报错“目录链接出错”。

答:2.4 kernel以上,可以用mount –bind命令来链接。

 The bind mounts.
              Since Linux 2.4.0 it is possible to remount  part  of  the  file
              hierarchy somewhere else. The call is
                     mount --bind olddir newdir
              or shortoption
                     mount -B olddir newdir
              or fstab entry is:
                     /olddir /newdir none bind

              After  this  call the same contents is accessible in two places.
              One can also remount a single file (on a single file). It's also
              possible  to  use  the  bind mount to create a mountpoint from a
              regular directory, for example:

                     mount --bind foo foo

              The bind mount call attaches only (part of) a single filesystem,
              not possible submounts. The entire file hierarchy including sub‐
              mounts is attached a second place using

                     mount --rbind olddir newdir

              or shortoption
                     mount -R olddir newdir

              Note that the filesystem mount options will remain the  same  as
              those  on  the  original  mount  point, and cannot be changed by
              passing the -o  option  along  with  --bind/--rbind.  The  mount
              options  can be changed by a separate remount command, for exam‐
              ple:

                     mount --bind olddir newdir
                     mount -o remount,ro newdir

              Note that behavior of  the  remount  operation  depends  on  the
              /etc/mtab  file. The first command stores the 'bind' flag to the
              /etc/mtab file and the second command reads the  flag  from  the
              file.  If you have a system without the /etc/mtab file or if you
              explicitly define source and  target  for  the  remount  command
              (then  mount(8)  does  not read /etc/mtab), then you have to use
              bind flag (or option) for the remount command too. For example:

                     mount --bind olddir newdir
                     mount -o remount,ro,bind olddir newdir

2、Linux下如何知道某个端口在运行什么程序?

当我们用netstat -an的时候,我们有时候可以看到类似的输出:

udp 0 0 0.0.0.0:32768 0.0.0.0:*

但是查找/etc/services又没有这个端口的相关说明,怎么办呢?这个是不是黑客程序?有没有办法查看究竟什么程序监听在这个端口?

使用lsof -i :32768就可以看到:

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

rpc.statd 603 root 4u IPv4 953 UDP *:32768

rpc.statd 603 root 6u IPv4 956 TCP *:32768 (LISTEN)

 

原来是rpc的程序。

使用lsof -i :port就能看见所指定端口运行的程序,同时还有当前连接。


3、Ubuntu网络连接中,VPN连接的选项消失,无法新增、修改VPN连接,VPN选项出现之后,要进行配置提示“无法找到用于 org.freedesktop.NetworkManager.pptp 的 VPN 插件服务。”

sudo apt-get install network-manager-openvpn-gnome
sudo apt-get install network-manager-vpnc-gnome

4、添加用户要已存在的组

sudo adduser username groupname

验证用户相关信息

id username

5、Shell中每次读取文件的一行,逐行处理。

#!/bin/bash
while read line
do
echo $line #这里可根据实际用途变化
done < filename #filename 为需要读取的文件名

或者

#!/bin/bash
cat filename| while read line #filename 为需要读取的文件名,也可以放在命令行参数里。
do
echo $line
done


fastcgi问题

(111:connection refused……

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u www-data -g www-data -f /usr/bin/php-cgi

发布者

虚妄的存在感

我尊重你的存在感,但我鄙视你虚妄的存在感。