Sunteți pe pagina 1din 4

Vng Lp For

C php
For x in list
do
lnh
done
V d:
[root@localhost ~]# for i in ktoan kdoanh dtao; do mkdir $i; done
[root@localhost ~]# ll
total 116
-rw-------. 1 root root 1585 Jul 6 2012 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Aug 31 18:29 Desktop
drwxr-xr-x. 2 root root 4096 Jul 6 2012 Documents
drwxr-xr-x. 2 root root 4096 Jul 6 2012 Downloads
drwxr-xr-x 2 root root 4096 Oct 8 17:46 dtao
-rw-r--r--. 1 root root 47875 Jul 6 2012 install.log
-rw-r--r--. 1 root root 10837 Jul 6 2012 install.log.syslog
drwxr-xr-x 2 root root 4096 Oct 8 17:46 kdoanh
drwxr-xr-x 2 root root 4096 Oct 8 17:46 ktoan
drwxr-xr-x. 2 root root 4096 Jul 6 2012 Music
drwxr-xr-x. 2 root root 4096 Jul 6 2012 Pictures

-Add danh sch User t danh sch c sn.


[root@localhost ~]# cd VongLapFor/
[root@localhost VongLapFor]# ll
total 16
-rw-r--r-- 1 root root 230 May 21 2010 backup
-rw-r--r-- 1 root root 1945 Aug 9 2010 danhsach.txt
-rw-r--r-- 1 root root 791 Dec 4 2012 instal.lib.tool.perl.php.mysql
-rw-r--r-- 1 root root 732 May 21 2010 menu
[root@localhost VongLapFor]# cat danhsach.txt
nguyentiendat
lyanhhoang
tranhuuhung
luuhoangkhuong
lenguyennhatanh
tathihoangmai

lyhoanghai
vohoangtam
[root@localhost VongLapFor]# vi taouser
clear
echo " T A O U S E R"
read -p "Nhap file chua user: " file
for i in `cat $file`
do
useradd $i
echo 123 | passwd --stdin $i > /dev/null
echo -n "+ "
done
echo End
[root@localhost VongLapFor]# bash taouser
TAO USER
Nhap file chua user: danhsach.txt
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++
End
[root@localhost VongLapFor]# cat /etc/passwd
lyhoanghai:x:506:506::/home/lyhoanghai:/bin/bash
vohoangtam:x:507:507::/home/vohoangtam:/bin/bash
nguyenducthinh:x:508:508::/home/nguyenducthinh:/bin/bash
phamcaohai:x:509:509::/home/phamcaohai:/bin/bash
maiphuctien:x:510:510::/home/maiphuctien:/bin/bash
nguyenmanhtuan:x:511:511::/home/nguyenmanhtuan:/bin/bash
huynhtanvinh:x:512:512::/home/huynhtanvinh:/bin/bash
hoangthanhtrung:x:513:513::/home/hoangthanhtrung:/bin/bash
phanlongyenanh:x:514:514::/home/phanlongyenanh:/bin/bash
duongthienduc:x:515:515::/home/duongthienduc:/bin/bash
dangquochung:x:516:516::/home/dangquochung:/bin/bash
truongnghiaan:x:517:517::/home/truongnghiaan:/bin/bash
nguyenhoangdam:x:518:518::/home/nguyenhoangdam:/bin/bash

[root@localhost VongLapFor]# cp taouser xoauser


[root@localhost VongLapFor]# vi xoauser
clear
echo " T A O U S E R"
read -p "Nhap file chua user: " file

for i in `cat $file`


do
userdel -r $i
echo -n "+ "
done
echo End
[root@localhost VongLapFor]# bash xoauser
TAO USER
Nhap file chua user: danhsach.txt
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++
End
[root@localhost VongLapFor]# cat /etc/passwd
root:x:0:0:root:/root:/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

m s file , th mc con bn trong mt th mc.

[root@localhost VongLapFor]# vi demfile


clear
read -p "Nhap thu muc can dem: " tmuc
if [ -d $tmuc ]; then
sumfile=0; sumdir=0
for i in $tmuc/*
do
if [ -f $i ]; then
sumfile=$[ $sumfile + 1 ]
else
sumdir=$[ $sumdir + 1 ]
fi
done
echo "Tong So File: $sumfile"
echo "Tong So Thu Muc: $sumdir"
else
echo "Thu Muc Khong Ton Tai"
fi
[root@localhost VongLapFor]# bash demfile

Nhap thu muc can dem: /root


Tong So File: 4
Tong So Thu Muc: 12
[root@localhost VongLapFor]# bash demfile
Nhap thu muc can dem: abc
Thu Muc Khong Ton Tai

S-ar putea să vă placă și