linux 基础操作(二)
查找文件
[root@localhost /]# locate signal
/etc/latrace.d/headers/signal.h
/usr/include/signal.h
/usr/include/asm/signal.h
/usr/include/asm-generic/signal-defs.h
/usr/include/asm-generic/signal.h
/usr/include/bits/signalfd.h
根据名字查找文件
[root@localhost /]# whereis oracle
oracle:[root@localhost /]# find / -name "oracle"
/mnt/oracle
[root@localhost /]#
查看当前登录用户
直接回车是查看所有登录用户信息,只要登录过就会显示出来,加用户名就查看指定的用户。
[root@localhost /]# w
17:45:46 up 1:39, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.110 17:38 2.00s 0.21s 0.04s w
[root@localhost /]# exit
登出
Connection to 192.168.1.103 closed.
[root@localhost /]# w
17:46:48 up 1:37, 3 users, load average: 0.16, 0.44, 0.29
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
beijing :0 :0 17:41 ?xdm? 1:25 0.44s gdm-session-worker [pam/gdm-password]
root pts/0 192.168.1.101 17:36 0.00s 0.31s 0.08s w
beijing pts/1 :0 17:42 4:00 0.13s 0.13s bash
查看使用过的用户
[root@localhost /]# who
beijing :0 2016-05-07 17:41 (:0)
root pts/0 2016-05-07 17:36 (192.168.1.101)
beijing pts/1 2016-05-07 17:42 (:0)
查看当前登录和过去登录的用户信息
[root@localhost /]# last
beijing pts/1 :0 Sat May 7 17:42 still logged in
beijing :0 :0 Sat May 7 17:41 still logged in
root pts/0 192.168.1.101 Sat May 7 17:36 still logged in
(unknown :0 :0 Sat May 7 16:10 - 17:41 (01:31)
reboot system boot 3.10.0-327.el7.x Sat May 7 16:09 - 17:52 (01:43)
查看所有用户最后一次登录时间
[root@localhost /]# lastlog
用户名 端口 来自 最后登陆时间
root pts/0 192.168.1.101 六 5月 7 17:36:48 +0800 2016
bin **从未登录过**
daemon **从未登录过**
adm **从未登录过**
[root@localhost /]#
查看用户所属组
[admin@b4_sw_3552p test]$ groups admin
admin : root
将用户添加到其它组并脱离当前用户组
[root@b4_sw_3552p test]# usermod -g root admin
[admin@b4_sw_3552p test]$ groups admin
admin : root
将用户添加到其它组并保留当前用户组
[root@b4_sw_3552p test]# usermod -a -G root admin
[admin@b4_sw_3552p test]$ groups admin
admin : admin root
使用 mount 挂载 windows 目录
普通用户没有写的权限的解决办法(可以通过 file_mode 和 dir_mode 来设置权限,覆盖默认的 755 权限。)
[root@localhost ~]# mount -t cifs -o username=beijing,password=123456linux //192.168.1.101/linux /mnt
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 43G 3.9G 39G 9% /
devtmpfs 1.1G 0 1.1G 0% /dev
tmpfs 1.1G 518M 568M 48% /dev/shm
tmpfs 1.1G 8.4M 1.1G 1% /run
tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup
/dev/sda1 497M 129M 369M 26% /boot
tmpfs 218M 0 218M 0% /run/user/1001
tmpfs 218M 0 218M 0% /run/user/0
//192.168.1.101/linux 301G 296G 5.2G 99% /mnt
[root@localhost ~]# su - beijing
Last login: Mon May 23 22:04:37 CST 2016 on pts/0
[beijing@localhost mnt]$ touch temp.txt
touch: cannot touch ‘temp.txt’: Permission denied
[root@localhost /]# mount -t cifs -o username=beijing,password=123456cjl,rw,dir_mode=0777,file_mode=0777 //192.168.1.101/linux /mnt
[root@localhost /]# su - beijing
Last login: Mon May 23 22:20:07 CST 2016 on pts/0
[beijing@localhost ~]$ cd /mnt
[beijing@localhost mnt]$ ls
desktop.ini oracle temp.txt
[beijing@localhost mnt]$ touch txt.txt
[beijing@localhost mnt]$ ls
desktop.ini oracle temp.txt txt.txt
根据程序名称,查询端口使用情况(查询 nginx 占用的端口)
-bash-4.1$ ps -ef | grep nginx
root 23701 1 0 Mar09 ? 00:00:00 nginx: master process ./nginx
fourjoy 34887 34858 0 16:13 pts/8 00:00:00 grep nginx
nobody 45647 23701 0 May05 ? 00:02:53 nginx: worker process
nobody 45648 23701 0 May05 ? 00:03:05 nginx: worker process
查看变量的值
[root@localhost beijing]# echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/xe
查看文件结尾几行(动态显示文件最新内容)
[root@localhost beijing]# tail -f -n 100 log2014.log
[root@localhost beijing]# tail -fn 100 log2014.log
卸载挂载文件
卸载挂载文件时,如果当前位置在挂载的目录,会提示 target is busy,退出当前目录,就可以正常卸载。
[root@localhost mnt]# umount -t cifs /mnt
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@localhost mnt]# cd /
[root@localhost mnt]# umount -t cifs /mnt
setup 修改系统服务
[root@localhost /]# setup