linux redhat 虛擬機

df ###查看已經使用了的空間

blkid ###顯示所有可用設備的id信息

du -sh /mnt/  ###查看設備的使用情況

fuser -vm /dev/sdb1  ###

[kiosk@foundation59 Desktop]$ fuser -vm /dev/sdb1

[kiosk@foundation59 Desktop]$ 


[root@foundation14 ~]# updatedb    ###更新數據庫

[root@foundation14 ~]# locate westos   ###查找westos文件,locate查找不準確,locate只在數據庫裏面查找,所以要更新數據路庫

[root@foundation14 ~]# touch /boot/westos

[root@foundation14 ~]# locate westos

[root@foundation14 ~]# updatedb

[root@foundation14 ~]# locate westos

/boot/westos

[root@foundation14 ~]# rm -fr /boot/westos

[root@foundation14 ~]# locate westos

/boot/westos

[root@foundation14 ~]# ll /boot/westos

ls: cannot access /boot/westos: No such file or directory

[root@foundation14 ~]# cat /boot/westos

cat: /boot/westos: No such file or directory

[root@foundation14 ~]# updatedb

[root@foundation14 ~]# cat /boot/westos

cat: /boot/westos: No such file or directory

[root@foundation14 ~]# locate westos

[root@foundation14 ~]# 


[root@desktop14 Desktop]# cd /mnt

[root@desktop14 mnt]# ls

[root@desktop14 mnt]# touch file{1..5}

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 1 root root 0 Oct 12 21:53 file1

-rw-r--r--. 1 root root 0 Oct 12 21:53 file2

-rw-r--r--. 1 root root 0 Oct 12 21:53 file3

-rw-r--r--. 1 root root 0 Oct 12 21:53 file4

-rw-r--r--. 1 root root 0 Oct 12 21:53 file5

[root@desktop14 mnt]# grep bash /etc/passwd    ###查看用戶本機所有用戶信息

root:x:0:0:root:/root:/bin/bash

student:x:1000:1000:Student User:/home/student:/bin/bash

[root@desktop14 mnt]# useradd westos

[root@desktop14 mnt]# useradd lee

[root@desktop14 mnt]# chown westos file1   ###更改文件file1所屬用戶爲westsos 

[root@desktop14 mnt]# chown lee file2

[root@desktop14 mnt]# chown westos.lee file3   ##3更改文件file3所屬用戶爲westos所屬組爲lee 

[root@desktop14 mnt]# chown lee.lee file4

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 1 westos root 0 Oct 12 21:53 file1

-rw-r--r--. 1 lee    root 0 Oct 12 21:53 file2

-rw-r--r--. 1 westos lee  0 Oct 12 21:53 file3

-rw-r--r--. 1 lee    lee  0 Oct 12 21:53 file4

-rw-r--r--. 1 root   root 0 Oct 12 21:53 file5

[root@desktop14 mnt]# find /mnt/ -user westos    ###查找屬於用戶westos的文件

/mnt/file1

/mnt/file3

[root@desktop14 mnt]# find /mnt/ -group root   ###查找屬於組root的文件

/mnt/

/mnt/file1

/mnt/file2

/mnt/file5

[root@desktop14 mnt]# ll -d /mnt/   ###查看目錄信息

drwxr-xr-x. 2 root root 66 Oct 12 21:53 /mnt/

[root@desktop14 mnt]# find /mnt/ -group lee -a -user westos    ###查找屬於組lee並且屬於用戶westos的

/mnt/file3

[root@desktop14 mnt]# find /mnt/ -not -group lee -a -not -user westos   ###查找不再組lee並且不屬於用古westos的

/mnt/

/mnt/file2

/mnt/file5


###############################

[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file1 bs=1024 count=10

10+0 records in

10+0 records out

10240 bytes (10 kB) copied, 0.000149041 s, 68.7 MB/s

[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file2 bs=1024 count=20  ###指的是一個空的設備input,output

20+0 records in

20+0 records out

20480 bytes (20 kB) copied, 0.000150441 s, 136 MB/s

[root@desktop14 mnt]# dd if=/dev/zero of=/mnt/file3 bs=1024 count=30

30+0 records in

30+0 records out

30720 bytes (31 kB) copied, 0.000167358 s, 184 MB/s

[root@desktop14 mnt]# ll

total 64

-rw-r--r--. 1 root root 10240 Oct 12 22:08 file1

-rw-r--r--. 1 root root 20480 Oct 12 22:08 file2

-rw-r--r--. 1 root root 30720 Oct 12 22:09 file3

[root@desktop14 mnt]# find /mnt/ -size 20k   ###查找文件大小爲20k的

/mnt/file2

[root@desktop14 mnt]# find /mnt/ -size -20k    ###查找文件小於20k的

/mnt/

/mnt/file1

[root@desktop14 mnt]# find /mnt/ -size +20k    ###查找文件大於20k的

/mnt/file3

[root@desktop14 mnt]# find /mnt/ -size -20k -a -type f   ###查找文件小於20k

/mnt/file1

[root@desktop14 mnt]# find /mnt/ -size -20k -a -type d   ###查找目錄小於20k

/mnt/

[root@desktop14 mnt]# 

##############################

[root@desktop14 mnt]# chmod 000 /mnt/*   ###更改/mnt/下所有文件的權限爲0

[root@desktop14 mnt]# ll

total 64

----------. 1 root root 10240 Oct 12 22:08 file1

----------. 1 root root 20480 Oct 12 22:08 file2

----------. 1 root root 30720 Oct 12 22:09 file3

[root@desktop14 mnt]# chmod 444 file1   ###更改文件file1的權限

[root@desktop14 mnt]# chmod 404 file2

[root@desktop14 mnt]# ll

total 64

-r--r--r--. 1 root root 10240 Oct 12 22:08 file1

-r-----r--. 1 root root 20480 Oct 12 22:08 file2

----------. 1 root root 30720 Oct 12 22:09 file3

[root@desktop14 mnt]# find /mnt -perm 444   ###查找文件權限等於444的文件,permission

/mnt/file1

[root@desktop14 mnt]# find /mnt -perm -444   ###查找權限大於和等於444文件的

/mnt

/mnt/file1

[root@desktop14 mnt]# find /mnt -perm /444

/mnt

/mnt/file1

/mnt/file2

[root@desktop14 mnt]# find /mnt -perm /755   ###斜槓後面跟的數字越大,找到滿足條件的文件會越多,以爲他是或的關係,只要7個條件中有一個滿足就可以

/mnt

/mnt/file1

/mnt/file2

[root@desktop14 mnt]# urwx grx orx^C

####################################################

perm 444  ###文件權限必須是rrr

perm -444   ###文件每一位都要含有r權限

perm /444   ###文件任意一位含有r權限

-maxdepth 數字   ###最深目錄層

-mindepth 數字   ###最淺目錄層

-exec  命令 {} \   ###對查找出的結果做相應的處理

[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name ^C

[root@desktop14 mnt]# find /etc/ -name passwd  ###查找文件名爲passwd的文件

/etc/passwd

/etc/pam.d/passwd

[root@desktop14 mnt]# find /etc/ -maxdepth 1 -name passwd  ###查找目錄深度爲1的文件名爲passwd的文件

/etc/passwd

[root@desktop14 mnt]# find /etc/ -maxdepth 2 -name passwd  ###查找目錄深度爲2以內(包括深度爲1的)的文件名爲passwd的文件

/etc/passwd

/etc/pam.d/passwd

[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name passwd   ###查找最大深度是2最小深度也是2的文件名爲passwd的文件

/etc/pam.d/passwd

[root@desktop14 mnt]# find /etc/ -maxdepth 2 -mindepth 2 -name passwd -exec cp {} /mnt \; ###查找最大深度是2最小深度也是2的文件名是passwd的文件,並且把它複製到/mnt目錄下

[root@desktop14 mnt]# ls  ###查看剛纔複製過來的文件

file1  file2  file3  passwd

[root@desktop14 mnt]# find /mnt/ -perm -444 -exec rm -fr {} \;   ###查找文件權限是444並且刪除所有

find: ‘/mnt/’: No such file or directory

[root@desktop14 mnt]# 

[root@desktop14 mnt]# ls

[root@desktop14 mnt]# 

軟連接就是快捷方式,建立軟鏈接的目的是爲了節省設備存儲

硬鏈接就是把文件重新複製一次,只有文件的內容沒有文件的屬性

[root@desktop14 mnt]# touch file 

[root@desktop14 mnt]# ln -s /mnt/file /mnt/westos  ###soft指的軟鏈接

[root@desktop14 mnt]# ll

total 0

drwxr-xr-x. 2 root root 6 Oct 12 23:06 backup   ###其中的2是文件被記錄的次數

-rw-r--r--. 1 root root 0 Oct 12 23:15 file

lrwxrwxrwx. 1 root root 9 Oct 12 23:15 westos -> /mnt/file

[root@desktop14 mnt]# rm -fr file

[root@desktop14 mnt]# cat /mnt/westos   ###刪掉文件之後,軟鏈接也不可用

cat: /mnt/westos: No such file or directory

[root@desktop14 mnt]# rm -fr *

[root@desktop14 mnt]# touch file

[root@desktop14 mnt]# ln /mnt/file /mnt/westos    ###創建硬鏈接,

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 2 root root 0 Oct 12 23:17 file

-rw-r--r--. 2 root root 0 Oct 12 23:17 westos

[root@desktop14 mnt]# ln /mnt/file /mnt/westos1

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 3 root root 0 Oct 12 23:17 file

-rw-r--r--. 3 root root 0 Oct 12 23:17 westos

-rw-r--r--. 3 root root 0 Oct 12 23:17 westos1

[root@desktop14 mnt]# rm -fr westos1

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 2 root root 0 Oct 12 23:17 file   ###刪除一次,文件的被記錄的次數減少一次

-rw-r--r--. 2 root root 0 Oct 12 23:17 westos

[root@desktop14 mnt]# rm -fr westos

[root@desktop14 mnt]# ll

total 0

-rw-r--r--. 1 root root 0 Oct 12 23:17 file

[root@desktop14 mnt]# rm -fr file

[root@desktop14 mnt]# ll

total 0

[root@desktop14 mnt]# ls -li *  ###查看節點信息

virt-manager ###安裝虛擬機

ls -i ###查看設備的節點號

[root@foundation59 mnt]# virt-manager   ###彈出虛擬機管理界面

[root@foundation59 mnt]# virt-viewer desktop  ###立即彈出desktop虛擬機界面

[root@foundation14 ~]# virt-manager test11

[root@foundation14 ~]# virt-viewer test11   ###查看虛擬機


(virt-viewer:15729): GSpice-WARNING **: PulseAudio context failed Connection refused


(virt-viewer:15729): GSpice-WARNING **: pa_context_connect() failed: Connection refused


(virt-viewer:15729): GSpice-WARNING **: Warning no automount-inhibiting implementation available

^C

[root@foundation14 ~]# 

[root@foundation14 ~]# virsh list   ###列出所有虛擬機信息

 Id    Name                           State

----------------------------------------------------

 2     desktop                        paused

 3     server                         paused

 8     test11                         running

[root@foundation14 ~]# virsh list --all

 Id    Name                           State

----------------------------------------------------

 2     desktop                        paused

 3     server                         paused

 8     test11                         running

[root@foundation14 ~]# virsh destroy test11   ###立即關閉虛擬機

Domain test11 destroyed


[root@foundation14 ~]# virsh start test11   ###開啓虛擬機

[root@foundation14 ~]# virsh shutdown test11   ###關閉虛擬機

Domain test11 started

[root@foundation14 ~]# cd /var/lib/libvirt/images   ###進入虛擬機文件存放目錄

[root@foundation14 images]# ls   ###查看所有可用源鏡像

rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2

rh124-desktop-vda.qcow2  rh124-server-vda.ovl    rh124-server.xml

rh124-desktop-vdb.ovl    rh124-server-vda.qcow2  rhel7.0.qcow2

rh124-desktop-vdb.qcow2  rh124-server-vdb.ovl

[root@foundation14 images]# qemu-img create -f qcow2 -b rhel7.0.qcow2 test1.qcow2  ###快照虛擬機,新快照名爲test1.qcow2

Formatting 'test1.qcow2', fmt=qcow2 size=9663676416 backing_file='rhel7.0.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off 

[root@foundation14 images]# ls   ###查看新建的快照

rh124-desktop-vda.ovl    rh124-desktop.xml       rh124-server-vdb.qcow2

rh124-desktop-vda.qcow2  rh124-server-vda.ovl    rh124-server.xml

rh124-desktop-vdb.ovl    rh124-server-vda.qcow2  rhel7.0.qcow2

rh124-desktop-vdb.qcow2  rh124-server-vdb.ovl    test1.qcow2

[root@foundation14 images]# du -sh test1.qcow2   ###查看快照的大小信息

196Ktest1.qcow2

####################################################################

然後新建虛擬機,選擇已有鏡像



交互式登陸就是你可以和系統進行對話,系統會有反饋

vim /etc/chrony.conf ###設置時間進行同步


[root@foundation59 ~]# find / -group mail   ###

find: ‘/proc/4303/task/4303/fd/6’: No such file or directory

find: ‘/proc/4303/task/4303/fdinfo/6’: No such file or directory

find: ‘/proc/4303/fd/6’: No such file or directory

find: ‘/proc/4303/fdinfo/6’: No such file or directory

find: ‘/run/user/1000/gvfs’: Permission denied

/var/spool/mail

/var/spool/mail/rpc

/var/spool/mail/kiosk

^C

[root@foundation59 ~]# 

[root@foundation59 ~]# find / -group mail -exec cp -rp {} /mnt/backup \;   ###找出用戶組mail 擁有的文件,並且將它們放到/mnt/backup 目錄中

find: ‘/proc/4335/task/4335/fd/6’: No such file or directory

find: ‘/proc/4335/task/4335/fdinfo/6’: No such file or directory

find: ‘/proc/4335/fd/6’: No such file or directory

find: ‘/proc/4335/fdinfo/6’: No such file or directory

find: ‘/run/user/1000/gvfs’: Permission denied

^C


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章