1.如何關閉linux伺服器?
方法一:halt
方法二:shutdown -h now
2.如何重新開機linux伺服器?
方法一:reboot
方法二:shutdown -r now
3.請檢視目前登入使用者,如果是root使用者,則切換到其他使用者以下所有普通使用者為test.。
檢視目前登入使用者:whoami
切換到test使用者:su test
4.現在root使用者登入,請修改root使用者密碼,并修改某普通使用者的密碼。
passwd [username]
如果不指定使用者名則預設修改root使用者的密碼。注意:普通使用者隻能修改自己的密碼。
5.切換到test使用者的 家目錄下。
切換目錄:cd /home/test
6.在test家目錄中建立一個檔案夾study
建立目錄:mkdir /home/test/study
7.檢視test家目錄下的檔案或子目錄
檢視目錄下的内容:ls /home/test
8.切換到test家目錄的study目錄下,檢視目前路徑
切換目錄:cd /home/test/study
檢視目前路徑:pwd
9.在該路徑下建立一個檔案hello.txt
方法一:touch hello.txt
方法二:vi hello.txt
:wq
10.編輯hello.txt,寫入”hello world”
方法一:vim hello.txt
按(a/i/o)進入編輯模式
寫入” hello world”
方法二:echo ”hello world” >>hello.txt
如果要追加的檔案不存在,會自動建立
11.檢視hello.txt檔案内容
cat hello.txt
12.向hello.txt檔案中追加”yes,we are family! ”
echo ”yes,we are family! ” >> hello.txt
13.拷貝test家目錄的study目錄到root使用者家目錄
cp -r /home/test/study /root/
14.移動絕對路徑下的/root/test/my.txt到test的家目錄中
mv /root/test/my.txt /home/test/
15.删除/root/test/my.txt檔案
rm /root/test/my.txt
16.在/root/test中建立一個檔案you.txt,然後删除/root/test目錄。
touch /root/test/you.txt
rm -r /root/test遞歸删除
rm -rf /root/test遞歸删除 #強制快速删除,不進行對話
17.找一篇文章寫入/root/article.txt中,檢視前10行或後10行。
head -10 /root/article.txt
tail -10 /root/article.txt
18.查找一下my.txt檔案所在的位置
find / -name my.txt
19.過濾出/root/article.txt中帶‘中國’的行。
方法一:grep ‘中國’ /root/article.txt
方法二:sed -n ‘/中國/p’ /root/article.txt
方法三:awk ‘/中國/ {print }’ /root/article.txt
20.檢視article.txt中的内容,使用管道指令過濾出帶‘中國’的行。
方法一: cat /root/article.txt |grep ‘中國’
方法二: cat /root/article.txt |sed -n ‘/中國/p’
方法三: cat /root/article.txt |awk ‘/中國/ {print }’
21.檢視root家目錄下的内容,過濾出my.txt檔案并檢視該檔案中的内容。
錯誤:ls /root|grep my.txt|cat
正确: ls /root|grep my.txt|xargs cat