linux学习笔记-常见问题实战(1)
现在我们几个在工作或在面试中可能会遇到的一些linux基础问题
1 定义一个对所有用户都生效的命令别名:
设置别名的命令 alias
[root@localhost ~]# alias cls='clear'
如上设置只是局部有效,当系统重启动或切换用户时及失效。要想对所有用户永久有效需要修改相关配置文件。
/etc/profile 添加 alias cls='clear'
[root@localhost ~]# source /etc/profile
对当前用户永久有效
echo " alias cls='clear'" >> ~/.bashrc
source ~/.bashrc
2 显示/etc/passwd不以/bin/bash结尾的行
[root@localhost ~]# cat /etc/passwd|grep -v "/bin/bash$"
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
3 显示/etc/passwd中包含两位数字或三为数字的行
[root@localhost ~]# cat /etc/passwd|grep -E "[0-9]{2,3}"
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
4 显示/proc/meminfo以大写或小写s开发的行
[root@localhost ~]# cat /proc/meminfo|grep -i "^s"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 6820 kB
Slab: 51728 kB
SReclaimable: 17256 kB
[root@localhost ~]# cat /proc/meminfo|grep "^[Ss]"
SwapCached:
5b4
0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 6820 kB
Slab: 51736 kB
SReclaimable: 17256 kB
SUnreclaim: 34480 kB
SUnreclaim: 34472 kB
[root@localhost ~]# cat /proc/meminfo|grep -v "^[^Ss]"
SwapCached: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Shmem: 6820 kB
Slab: 51780 kB
SReclaimable: 17288 kB
SUnreclaim: 34492 kB
5使用echo输出一个绝对路径 ,使用egrep取其基名
[root@localhost ~]# echo "/etc/passwd"|egrep -o "[^/]+/?$"
passwd
进一步使用egrep取其路径名:
6 找出ip addr中的ip地址 要求结果只显示ip
[root@localhost ~]# ip addr|grep "inet\>" | tr -s " "|cut -d " " -f5
host
192.168.3.255
[root@localhost ~]#
7 vim定制自动缩进4个字符
编辑 .vimrc文件 添加以下内容
set tabstop=4
set softtabstop=4
set shiftwidth=4
8 编写脚步,实现自动添加3个用户,并计算三个用户的uid之和
<待更新>
9 find的常用用法
查收 /usr下 不属于 root bin hadoop 的文件
find /usr -not -user root -a -not -user bin -a -not -user hadoop -ls
215376 0 drwx------ 2 polkitd root 6 6月 10 2014 /usr/share/polkit-1/rules.d
4fc0
查收最近7天修改的文件
find /etc/ -mtime -7
find /etc/ -not -perm +222 -ls
查无宿组或宿主的文件
localhost ~]# find /etc/ ( -nouser -o -nogroup ) -ls
134905616 0 -rw-r--r-- 1 1004 1004
- linux学习笔记--常见问题解决方法
- 【Java学习笔记】61:Linux下集成Eclipse-jee和Tomcat与常见问题
- c++学习笔记三-常见基础问题
- 学习linux中的常见问题
- LifeRay Portal 6学习笔记7:Liferay的一些常见问题
- linux 学习笔记 gdb问题解决
- mybatis学习笔记--常见的问题
- VPS 虚拟主机服务器常见问题与学习笔记
- linux 配置常见问题解决笔记
- linux学习笔记4--线程编程 undefined reference to 'pthread_create'问题
- ExtJs学习笔记(4)常见问题
- [Python]python学习笔记(二)——常见问题
- 学习中LINUX中常见问题(精华)
- Java菜鸟学习笔记(2)--Ubuntu JDK环境变量配置与常见问题
- 【Linux学习笔记⑧】linux基本网络问题
- 自己整理的:学习verilog DHL问题笔记——Quartus常见错误
- 学习中LINUX中常见问题
- c++ 学习笔记(常见问题与困惑)(转载)
- 实战 Linux socket 学习笔记(第三章)
- 【菜鸟C++学习笔记】24. 常见的引用注意问题