linux基礎知識(一)

2021-07-13 04:08:39 字數 4004 閱讀 2804

//提示關機資訊

[root@hadoop1 ~]#

broadcast message from root@hadoop1

(/dev/pts/0) at 11:41 ...

the system is going down for maintenancenow!

this computer will reboot

//立即關機

[root@hadoop1 ~]# shutdown -h now

[root@hadoop1~]# ln renfen wangyi  //連線目錄,所以有2 個結點指向這個文件

[root@hadoop1 ~]# ls -l renfen

-rw-r--r--. 2(表示鏈結數) root root 855 mar 25 10:33 renfen

//表示當前目錄和上級目錄

1)chgrp:改變檔案所屬群組

chown:改變檔案所屬人

[root@hadoop1 ~]# chown root:roottestgrp2

[root@hadoop1~]# ls -l testgrp2

-rw-r--r--. 1root root 0 apr  6 09:51 testgrp2

chmod:改變檔案的屬性

-rw-r--r--. 1 root root 0 apr  6 09:51 testgrp2

[root@hadoop1~]# chmod 777 testgrp2

[root@hadoop1 ~]# ls -l testgrp2

-rwxrwxrwx. 1root root 0 apr  6 09:51 testgrp2

-rw-rw-r--. 1root root 0 apr  6 09:51 testgrp2

[root@hadoop1~]# chmod a=rwx,g=rwx,o=rwx testgrp2

[root@hadoop1~]# ls -l testgrp2

-rwxrwxrwx. 1root root 0 apr  6 09:51 testgrp2

2)新增使用者組和使用者 在home下

[root@hadoop1 ~]# groupadd testgrp1

[root@hadoop1 ~]# useradd ren1 -g testgrp1

[root@hadoop1 ~]# useradd ren2 -g testgrp1

a.同一組下的ren2沒有ren1讀的許可權

[root@hadoop1~]# su - ren1  //是的ren1為超級使用者,(su [-] -l或--login 改變身份時,也同時變更工作目錄,也會變更path變數。)

[ren1@hadoop1~]$ cd ..  //用來切換目錄到home下

[ren1@hadoop1home]$ ls -l ren1

total 0

[ren1@hadoop1home]$ ls -l ren2

ls: cannot open directory ren2: permission denied

b. 將ren1改為同組可讀,可用ren2  su進行讀(可用exit來退出使用者的登入回到root下)

[root@hadoop1 ~]# cd /home

[root@hadoop1home]# chmod g+r ren1

[root@hadoop1home]# cd ren1

[root@hadoop1ren1]# touch 11.txt

[root@hadoop1ren1]# su - ren2

[ren2@hadoop1~]$ cd..

-bash:cd..: command not found

[ren2@hadoop1~]$ cd /home

[ren2@hadoop1home]$ ls -l

total 40

drwxr-----.  4ren1  testgrp1 4096 jun  4 12:36 ren1

drwx------.  4 ren2 testgrp1 4096 jun  4 12:14 ren2

[ren2@hadoop1 home]$ ls -l ren1

ls:cannot access ren1/11.txt: permission denied

ls:cannot access ren1/1.txt: permission denied

total 0

-?????????? ? ? ?            ? 11.txt

-????????? ? ?? ?            ? 1.txt

改變[root@hadoop1ren1]# chmod 750 /home/ren1。ren2可以讀取ren1中檔案的具體資訊。

c.ren1中建立資料夾(test2dir),移動檔案到test2dir中

[ren2@hadoop1ren1]$ mkdir test2dir

[ren2@hadoop1ren1]$ ls -l

total 4

-rw-r--r--.1 root root        0 jun  4 12:36 11.txt

-rw-r--r--.1 ren1 testgrp1    0 jun  4 12:25 1.txt

-rw-r--r--.1 ren2 testgrp1    0 jun  4 12:52 2.txt

drwxr-xr-x.2 ren2 testgrp1 4096 jun  4 12:52test2dir

[ren2@hadoop1ren1]$ mv 2.txt 33.txt

[ren2@hadoop1ren1]$ ls -l

total 4

-rw-r--r--.1 root root        0 jun  4 12:36 11.txt

-rw-r--r--.1 ren1 testgrp1    0 jun  4 12:25 1.txt

-rw-r--r--.1 ren2 testgrp1    0 jun  4 12:52 33.txt

drwxr-xr-x.2 ren2 testgrp1 4096 jun  4 12:52test2dir

[ren2@hadoop1ren1]$ ls -l test2.dir

ls:cannot access test2.dir: no such file or directory

[ren2@hadoop1ren1]$ ls -l test2dir

total 0

[ren2@hadoop1ren1]$ ls -l

total 4

-rw-r--r--.1 root root        0 jun  4 12:36 11.txt

-rw-r--r--.1 ren1 testgrp1    0 jun  4 12:25 1.txt

-rw-r--r--.1 ren2 testgrp1    0 jun  4 12:52 33.txt

drwxr-xr-x.2 ren2 testgrp1 4096 jun  4 12:52test2dir

[ren2@hadoop1ren1]$ mv 33.txt test2dir

[ren2@hadoop1ren1]$ mv 11.txt test2dir

[ren2@hadoop1ren1]$ ls -l

total 4

-rw-r--r--.1 ren1 testgrp1    0 jun  4 12:25 1.txt

drwxr-xr-x. 2 ren2 testgrp1 4096 jun  4 12:55 test2dir

Linux基礎知識(一)

一 兩個檔案的交集 並集 前提條件 每個檔案中不得有重複行 1.取出兩個檔案的並集 重複的行只保留乙份 cat file1 file2 sort uniq file3 2.取出兩個檔案的交集 只留下同時存在於兩個檔案中的檔案 cat file1 file2 sort uniq d file3 3.刪...

Linux基礎知識(一)

在linux系統中,檔案許可權的操作是經常使用到的,我們可以通過簡單的命令檢視檔案的基本許可權,修改檔案的內容以及刪除所建立的檔案或者是資料夾。具體內容如下 一 檔案內容檢視 1.touch 檔名稱 在指定的資料夾下面建立新的檔案 2.cat n 檔名稱 檢視檔案的內容,只顯示當地檔案的最後一頁 3...

Linux基礎知識(一)

本篇主要介紹linux作業系統相關知識以及其常用命令等。一般而言,現代計算機計算機系統是乙個複雜的系統,故若程式設計師需要掌握該系統的每乙個細節例如如何通過 去呼叫音響等這些事情,那可能不再編寫 了,這種情況會嚴重影響程式設計師的開發效率。並且管理這些部件並加以優化使用,是一件極富挑戰性的工作,於是...