2013年3月13日 星期三 晴shell
1. 爲全部用戶添加別名命令 la=’ls -a’,要求重啓後有效。vim
[root@desktop107 ~]# aliascentos
alias cp='cp -i'bash
alias l.='ls -d .* --color=tty'ssh
alias ll='ls -l --color=tty'ide
alias ls='ls --color=tty'oop
alias mv='mv -i'this
alias rm='rm -i'url
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'firefox
[root@desktop107 ~]# alias la='ls -a'
驗證
[root@desktop107 ~]# alias
alias cp='cp -i'
alias l.='ls -d .* --color=tty'
alias la='ls -a'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
重啓後生效
[root@desktop107 ~]# vim /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
alias la='ls -a' (原爲空白行,在此添加命令,保存退出,重啓後生效)
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
fi
空白處添加alias la='ls -a'
注意,不可在~/.bashrc目錄下操做,不然只對root用戶有效
二、使 用 ls 命令列出 /etc 和 /ttmp 目錄下的全部文件 , 將 找到的結果追加輸出到文件/tmp/stdout.txt 中, 將報錯信息輸出到/tmp/stderr.txt 中。
[root@desktop107 ~]# ls /ttmp /etc >/tmp/stdout.txt 2>/tmp/stderr.txt
驗證:
[root@desktop107 ~]# cat /tmp/stderr.txt
ls: /ttmp: No such file or directory
[root@desktop107 ~]#
注意:
原文件/tmp/stdout.txt和/tmp/stderr.txt都不存在,當將結果輸出時,自動建立該文件。
3. 統計/etc/passwd 文件中共有多少個用戶, 其 shell 是/sbin/nologin。
方法一:
[root@desktop107 ~]# grep --color /sbin/nologin /etc/passwd|wc -l
32
方法二:
[root@desktop107 ~]# grep --color /sbin/nologin /etc/passwd|awk -F: '{x+=1} END{print x}'
32
方法三:
[root@desktop107 ~]# awk -F: '$7=="/sbin/nologin"{x+=1} END{print x}' /etc/passwd
32
方法四:
[root@desktop107 ~]# grep -c /sbin/nologin /etc/passwd
32
4. 將文件/root/install.log 中的第 7 至 28 行的 rpm 字符替換成 RPM。
[root@desktop107 ~]# sed -n '7,28s/rpm/RPM/p' /root/install.log
無rpm,無顯示
5. Create a new user named eric, his primary group is named eric, and additional groups
include mail, adm and sys.
有錯誤操做時刪除用戶信息,注意-r,刪除與該用戶相關的信息
[root@desktop107 ~]# userdel -r eric
建立用戶及其附加組
[root@desktop107 ~]# useradd -G mail,adm,sys eric
修改賬戶附加組
[root@desktop107 ~]# usermod -G adm eric
附加組必須提早都存在
6. Set user eric will be disable at 15 Mar 2013.
[root@desktop107 ~]# usermod -e 2013-03-15 eric
驗證:
[root@desktop107 ~]# cat /etc/shadow
eric:!!:15776:0:99999:7::15779:
15776建立日期,15779失效日期
7.使用命令找到屬於 rpcbind 的進程號, 並 pkill 掉該進程。
查找進程
方法一:
[root@desktop107 ~]# ps aux |grep rpcbind
root 7664 0.0 0.0 61188 748 pts/3 S+ 05:26 0:00 grep rpcbind
[root@desktop107 ~]#
無該進程
方法二:
[root@desktop107 ~]# pgrep rpcbind
[root@desktop107 ~]#
殺死進程
kill 進程號
pkill+進程號
進程名
killall+進程名
8.使用 root 登陸系統,使用命令殺死 root 用戶的全部進程。
[root@desktop107 ~]# kill -9 -U root
9.使用pgrep查看bash的進程號。
[root@desktop107 ~]# pgrep bash
4331
[root@desktop107 ~]#
10.使用top命令每隔0.5秒查看一次進程號爲1和2的進程信息。
[root@desktop107 ~]# top -d 0.5 -p 1,2
Tasks: 2 total, 0 running, 2 sleeping, 0 stopped, 0 zombie
Cpu(s): 1.5%us, 0.5%sy, 0.0%ni, 98.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 7849056k total, 3949196k used, 3899860k free, 64148k buffers
Swap: 0k total, 0k used, 0k free, 1332244k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 15 0 10368 676 564 S 0.0 0.0 0:02.29 init
2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0
11.開啓firefox程序,調整該進程的nice優先級爲-5。
練習
[root@desktop107 ~]# nice -5 firefox
正常運行
[root@desktop107 ~]# nice 3 firefox
nice: 3: No such file or directory
[root@desktop107 ~]# nice -6 firefox
正常運行
[root@desktop107 ~]# renice -6 firefox
0: old priority 0, new priority -6
[root@desktop107 ~]# renice 3 firefox
0: old priority 0, new priority 3
[root@desktop107 ~]# nice 3 firefox
nice: 3: No such file or directory
[root@desktop107 ~]# nice 2 firefox
nice: 2: No such file or directory
[root@desktop107 ~]# renice 2 firefox
0: old priority 0, new priority 2
[root@desktop107 ~]# renice -1 firefox
0: old priority 0, new priority -1
[root@desktop107 ~]# renice --7 firefox
0: old priority 0, new priority 0
[root@desktop107 ~]# renice -7 firefox
0: old priority 0, new priority -7
[root@desktop107 ~]# renice 5 firefox
0: old priority 0, new priority 5
[root@desktop107 ~]# nice 4 firefox
nice: 4: No such file or directory
[root@desktop107 ~]# nice -2 firefox
[root@desktop107 ~]#
正常運行
[root@desktop107 ~]# renice 3 firefox
0: old priority 0, new priority 3
[root@desktop107 ~]# renice 4 firefox
0: old priority 0, new priority 4
nice所設級別高於以前的級別,可打開程序;
renice所設級別如何設都沒法打開程序
nice所設級別不能低於以前的級別
renice設級別可任意
[root@desktop107 ~]# firefox &
程序放於後臺運行
Ctrl+Z組合鍵暫停程序並放於後臺,
查看後臺進程jobs -l
再運行則fg+進程號
12.刪除/etc/yum.repo.d/目錄下的yum源,手動建立新的yum源:ftp://192.168.0.25/pub/centos5.8
[root@desktop107 ~]# cat /etc/yum.repos.d/dvd.repo
[dvd]
name=centos
baseurl=ftp://192.168.0.254/pub/centos5.8
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-beta
[root@desktop107 ~]#
[root@desktop107 ~]# rm /etc/yum.repos.d/dvd.repo
rm: remove regular file `/etc/yum.repos.d/dvd.repo'? y
[root@desktop107 ~]# cat /etc/yum.repos.d/dvd.repo
cat: /etc/yum.repos.d/dvd.repo: No such file or directory
[root@desktop107 ~]#
建立新的yum源
[root@desktop107 ~]# vim /etc/yum.repos.d/evd.repo
[evd]
name=centos
baseurl=ftp://192.168.0.25/pub/centos5.8
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-beta
1三、使用 yum 命令列出全部以 vim 開頭的 rpm 軟件,安裝vim-X11軟件。
列出rpm軟件
[root@desktop107 ~]# yum list |grep '^vim'
vim-X11.x86_64 2:7.0.109-7.el5 installed
vim-common.x86_64 2:7.0.109-7.el5 installed
vim-enhanced.x86_64 2:7.0.109-7.el5 installed
vim-minimal.x86_64 2:7.0.109-7.el5 installed
[root@desktop107 ~]#
安裝vim-X11軟件
[root@desktop7 ~]# yum install vim-X11.x86_64
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vim-X11.x86_64 2:7.0.109-7.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Installing:
vim-X11 x86_64 2:7.0.109-7.el5 dvd 1.0 M
Transaction Summary
===============================================================================================
Install 1 Package(s)
Upgrade 0 Package(s)
Total download size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
vim-X11-7.0.109-7.el5.x86_64.rpm | 1.0 MB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : vim-X11 1/1
Installed:
vim-X11.x86_64 2:7.0.109-7.el5
Complete!
[root@desktop7 ~]#
1四、修改虛擬機啓動級別爲 3,要求重啓後生效。
SSH虛擬機
[root@localhost ~]# vi /etc/inittab
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
"/etc/inittab" 53L, 1666C
將默認值5改成3(id:5:initdefault:-->id:3:initdefault:)
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
-- INSERT --
及時更改回來
1五、設置SSH,要求真機遠程虛擬機時不須要密碼便可登陸。
(1)刪除無關信息
[root@desktop107 ~]# cd /root/.ssh
[root@desktop107 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@desktop107 .ssh]#
刪除本機鏈接其餘機器原信息
[root@desktop7 ~]# vim ~/.ssh/known_hosts
刪除原公鑰
[root@desktop7 ~]# cd /root/.ssh/
[root@desktop7 .ssh]# ls
authorized_keys id_rsa id_rsa.pub known_hosts
[root@desktop7 .ssh]# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmZen4F46bQlnOkb2UgTf9cjpC9ZnD8tX2+s4C/EBiHo+HQA5oWxTJr1ku3NN2Z3Ht5WR0vQQi0+4BO0FSqcchBqp8mZr4t8kUOVdseVl7D1vDqc/5H30GXfVbzJ3X6Ihhq5ToIcEBq64UegkzbYlTV61IfnrN5wmdJMVdZ7YqmJXcW6BfQJg4bgE+gPq04L2uKMAugPq/413l6lqb4Pw/Ek/yYbLfvXIScJwY67XeOJyXnvAwKB4XTHZyQe+U1GteW/7gKke0DbfuO5hg3casU05uF16d8aQCReMcTLbJCVVIjn6y8flcr/9M7Z5EKcNLXmO5S1AU0gxLT01lE3l2w== root@instructor.example.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmZen4F46bQlnOkb2UgTf9cjpC9ZnD8tX2+s4C/EBiHo+HQA5oWxTJr1ku3NN2Z3Ht5WR0vQQi0+4BO0FSqcchBqp8mZr4t8kUOVdseVl7D1vDqc/5H30GXfVbzJ3X6Ihhq5ToIcEBq64UegkzbYlTV61IfnrN5wmdJMVdZ7YqmJXcW6BfQJg4bgE+gPq04L2uKMAugPq/413l6lqb4Pw/Ek/yYbLfvXIScJwY67XeOJyXnvAwKB4XTHZyQe+U1GteW/7gKke0DbfuO5hg3casU05uF16d8aQCReMcTLbJCVVIjn6y8flcr/9M7Z5EKcNLXmO5S1AU0gxLT01lE3l2w== root@instructor.example.com
[root@desktop7 .ssh]# rm authorized_keys
rm: remove regular file `authorized_keys'? y
[root@desktop7 .ssh]# rm authorized_keys
rm: cannot lstat `authorized_keys': No such file or directory
[root@desktop7 .ssh]#
刪除其餘無關信息
[root@desktop7 .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@desktop7 .ssh]# cd
[root@desktop7 ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAqHSoXXlrZP5dlCi4TDMIqd0N5G9iXy/T7wBmJ3q0IuLKZSnOs5xBSAm8NR0Cjg70X/ZuCWmwg4IPLrHlb/zqPlb7cQDYdVBR3NA6znpCJZW8viUDrag1IvMWg8WBvE1W7f9KDYA5FXBn7/P5SX57Vr+7L8HwwFbAKQWP5GKz7KVPQMmwO+wyIN9aeveqHQfEjex8OG/JCIJX9kmz2NqWQ5Fdor1qoqh0fgKmB1jnJr6jMbJmKBWWGHaHYCJgOpOF/4mLtYkU+kRitemWQ88lIjENCSFoqIiCEJ8d2+VqQjj+6BSIWKQGDimHqo/MYjsSNvXP7hJ4IqIBaD7LMn3MAQ== root@desktop107.example.com
[root@desktop7 ~]# rm /root/.ssh/id_rsa.pub
rm: remove regular file `/root/.ssh/id_rsa.pub'? y
[root@desktop7 ~]#
本機私鑰(保留)
[root@desktop7 ~]# cat /root/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEoQIBAAKCAQEAqHSoXXlrZP5dlCi4TDMIqd0N5G9iXy/T7wBmJ3q0IuLKZSnO
s5xBSAm8NR0Cjg70X/ZuCWmwg4IPLrHlb/zqPlb7cQDYdVBR3NA6znpCJZW8viUD
rag1IvMWg8WBvE1W7f9KDYA5FXBn7/P5SX57Vr+7L8HwwFbAKQWP5GKz7KVPQMmw
O+wyIN9aeveqHQfEjex8OG/JCIJX9kmz2NqWQ5Fdor1qoqh0fgKmB1jnJr6jMbJm
KBWWGHaHYCJgOpOF/4mLtYkU+kRitemWQ88lIjENCSFoqIiCEJ8d2+VqQjj+6BSI
WKQGDimHqo/MYjsSNvXP7hJ4IqIBaD7LMn3MAQIBIwKCAQBzgzGfLrAKvQz34Whu
w+iu/frlyLh7yQZavnHvL5F3Aene+Bi1rPmQe7RBrX4YRMTUFrHakZ2cAWl/GuZ4
rW1sk2qWoX58VFVkNwPAyNzmkpANWzW46F7zZNw9GbgMF8aUkcxhB3eZrCoDn/tl
mI8W6d9xNIfUWL5IA9BiF8vVd4465HyY+78AQSev2/LI5S04uSB5Wld8pCVFetxs
JL28WR4oLC1pws8lEqN9ck3G6HqE9Cj9or0M5W8vgTPo52dlklwq5rxO887x7z36
F+GsEIQs8YjtR8tNKCm+hFJD5Yv+umrFgC3MOe2VgH7t/QC/RmMM8D11Da+6LSrX
UKELAoGBANoob4oJId3hAYIjUy1PLCWaxaeBawLwVH/POsYqINaTXa8Bx8b0+SKX
l/xWO6sEcTaEOE1Cwrrxv040qnTi0zoJlO3gl3ZqGze2dHQCSItxRnHdZ+H3NQvn
0Ob4kbIPe1RgUfGPNp3ds3a1c3MlB27KxA5qTB05XNzRC/5nbvgtAoGBAMWtIkXT
sIhfftPMg7q+OBJVw4VbYQaCaSHMZmw7rtWoMbf7tTbIyI57BNCaK+AK5Q9WQLJz
cDIek0xbhipOxCqB1IIWYSFHsEfeouffeRtAp9pqLp8B9W2tnk9YKBWPuZO0SBBp
Z9ARTEElwPV3eAJVQHEQ6AFJO9mnsO5RDpOlAoGAErMCPwgY2IEAIRj4gDn8eEB3
V4AfHYJQYrn9uTbPnV0WqJnAqqdIje+8kfjDSSxEN99yikeNCLWiru6SRIh4gVFH
R5boaTxLec3Pd6hsnjzox+5n/Wz16xPetLY4X7gvJH1I2jDYy7Pqz6knJyBuWfQf
bvMrGHKhj0UeSQGNKzcCgYEAmH4/AqqeIA8nUu45u/HTe9vCt1Ue9mSaPqT+jgIn
yWR+IDc0BbDVOrar8WD9Rm7N9eNzvNy1owGk1IEeWybR16X7tM9vgBK7MCDG0CFs
DbWIzRAVVhd0MAmXYcep5L9UpSSsnvI6JCqZ6R0f002IdtQNJAW6SiKNQYFcmpZN
Es8CgYAWSzCdtWXADbnIbNaTh00fP3ffXZ632h0muVXiQtExHspkBszWVu0SIN3E
LovsfxrswRfW3XFOgCNOFdjOAjSHxRqjWSVMmYGVQzr+cjQA1E5YtQ1VhFtA/EM2
OL/O6gtUyObrOVI8FWyxA+QWfD//GCGbvAgP/NR89mU2lqYX3w==
-----END RSA PRIVATE KEY-----
[root@desktop7 ~]#
(2)生成公鑰
[root@desktop7 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
06:4f:65:a6:39:fb:3c:f9:e3:80:c8:44:63:02:e6:ab root@desktop7.example.com
[root@desktop7 ~]#
傳送公鑰
[root@desktop7 ~]# scp /root/.ssh/id_rsa.pub 192.168.0.211:/root/.ssh/authorized_keys
The authenticity of host '192.168.0.211 (192.168.0.211)' can't be established.
RSA key fingerprint is 9b:17:46:38:b6:7a:6b:07:57:9e:fb:11:a0:ab:37:5f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.211' (RSA) to the list of known hosts.
root@192.168.0.211's password:
id_rsa.pub 100% 407 0.4KB/s 00:00
[root@desktop7 ~]#
驗證
[root@desktop7 ~]# ssh 192.168.0.211
Last login: Wed Mar 13 07:19:05 2013
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 52:54:00:00:00:6B
inet addr:192.168.0.211 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::5054:ff:fe00:6b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:297 errors:0 dropped:0 overruns:0 frame:0
TX packets:293 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:42077 (41.0 KiB) TX bytes:28480 (27.8 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:1779 errors:0 dropped:0 overruns:0 frame:0
TX packets:1779 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5727966 (5.4 MiB) TX bytes:5727966 (5.4 MiB)
[root@localhost ~]#
方法二:
[root@desktop7 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.0.211
#本機所生成的公鑰要用絕對路徑
1六、將/var/log/messages 文件中全部 3 月 11 號的日誌過濾出來。
[root@desktop7 ~]# grep "Mar 11" /var/log/messages
Mar 11 20:29:02 desktop7 kernel: ide-floppy driver 0.99.newide
Mar 11 20:29:02 desktop7 kernel: usbcore: registered new driver hiddev
Mar 11 20:29:02 desktop7 kernel: usbcore: registered new driver usbhid
Mar 11 20:29:02 desktop7 kernel: drivers/usb/input/hid-core.c: v2.6:USB HID core driver
Mar 11 20:29:02 desktop7 kernel: PNP: PS/2 Controller [PNP0303:PS2K,PNP0f03:PS2M] at 0x60,0x64 irq 1,12
Mar 11 20:29:02 desktop7 kernel: serio: i8042 KBD port at 0x60,0x64 irq 1
Mar 11 20:29:02 desktop7 kernel: serio: i8042 AUX port at 0x60,0x64 irq 12
Mar 11 20:29:02 desktop7 kernel: mice: PS/2 mouse device common for all mice
Mar 11 20:29:02 desktop7 kernel: md: md driver 0.90.3 MAX_MD_DEVS=256, MD_SB_DISKS=27
1七、經過 Sed 修改計算機主機名爲 desktop10X.example.com,X 爲本身的座位號。
[root@desktop7 ~]# sed '/HOSTNAME/c
HOSTNAME=desktop107.example.com' /etc/sysconfig/network
還原原主機名
[root@desktop7 ~]# sed '/HOSTNAME/c HOSTNAME=desktop7.example.com' /etc/sysconfig/network
1八、經過 ifconfig,grep,awk 過濾出本機 IP 地址。
方法一:
[root@desktop7 ~]# ifconfig br0 |grep "inet addr"
inet addr:192.168.0.7 Bcast:192.168.0.255 Mask:255.255.255.0
[root@desktop7 ~]# ifconfig br0 |grep "inet addr"|awk '{print $2}'
addr:192.168.0.7
[root@desktop7 ~]# ifconfig br0 |grep "inet addr"|awk '{print $2}'|cut -d: -f2
192.168.0.7
-d:取值 -f2:第二列
方法二:
[root@desktop7 ~]# ifconfig br0 |grep "inet addr"|awk '{print $2}'|awk -F: '{print $2}'
192.168.0.7
1九、修改虛擬機網卡配置文件,將開機啓動網卡修改成開機禁用該網卡。
方法一:
[root@desktop7 ~]# sed '4s/yes/no/' /etc/sysconfig/network-scripts/ifcfg-eth0
驗證:
[root@desktop7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
BRIDGE=br0
ONBOOT=no
IPADDR=192.168.0.7
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
ROUTE=192.168.0.254
DNS1=192.168.0.254
[root@desktop7 ~]#
方法二:
[root@desktop7 ~]# sed '/ONBOOT=yes/c ONBOOT=no' /etc/sysconfig/network-scripts/ifcfg-eth0
驗證:
[root@desktop8 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
BRIDGE=br0
ONBOOT=no
IPADDR=192.168.0.7
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
ROUTE=192.168.0.254
DNS1=192.168.0.254
20、將全部UID號大於500的帳戶顯示出來(僅顯示帳戶名稱)
[root@desktop7 ~]# awk -F: '$3>500 {print $1}' /etc/passwd
nfsnobody
eric
驗證
[root@desktop7 ~]# awk -F: '$3>500 {print $1,$3}' /etc/passwd
nfsnobody 65534
eric 501
2一、配置網卡虛擬接口爲固定 IP,IP 地址爲 192.168.0.100+X,X 爲本身的座位號。
方法一:
[root@desktop7 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.0.107
NETMASK=255.255.255.0
GATEWAY=192.168.0.254
ROUTE=192.168.0.254
DNS1=192.168.0.254
方法二:
[root@desktop7 ~]# cat >>/etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
ROOTPROTO=static
IPADDR=192.168.0.107
GATEWAY=192.168.0.254
DNS1=192.168.0.254
NETMASK=255.255.255.0
Ctrl+d組合鍵保存退出
驗證:
[root@desktop7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
ROOTPROTO=static
IPADDR=192.168.0.107
GATEWAY=192.168.0.254
DNS1=192.168.0.254
NETMASK=255.255.255.0
22. 以root身份,創建cron任務以下:
每2個月的每週1和4的22點46分,將文件/etc/passwd 拷貝到/tmp/目錄下,命名爲passwd_年月日(年月日爲當時時間)
通常配置方式
[root@desktop7 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
文件內容
46 22 * */2 1,4 cp /etc/passwd /tmp/passwd_`date +%Y-%m-%d`
當時驗證
* * * * * cp /etc/passwd /tmp/passwd_`date +%Y-%m-%d`
用腳本驗證
一、配置計劃任務
[root@desktop7 ~]# crontab -e
* * * * * /root/001.sh
二、編輯腳本001.sh
#!/bin/bash
cp /etc/passwd /tmp/passwd_`date +%Y-%m-%d`
賦予權限
[root@desktop7 ~]# chmod a+x 001.sh
三、驗證
[root@desktop7 ~]# cd /tmp
[root@desktop7 tmp]# ls
orbit-root
passwd_2013-03-14
[root@desktop7 tmp]# ll passwd_2013-03-14
-rw-r--r-- 1 root root 1681 Mar 14 05:34 passwd_2013-03-14
[root@desktop7 tmp]# ll passwd_2013-03-14
-rw-r--r-- 1 root root 1681 Mar 14 05:35 passwd_2013-03-14