Linux的基本概念
在用命令行的時候,一定要知道自己當前的目錄。
命令 | 說明 | example | |
路徑 |
. .. / ~ 相對路徑 絕對路徑 |
當前路徑 上一路徑 根目錄 家目錄 從當前位置開始算起 從根/家開始算起 |
. ../ cd / cd ~ Desktop ~/Desktop |
幫助 |
man --help |
幫助,信息多,可以看參數 幫助,簡單 |
man ls ls --help |
參數 |
-d -i -r -a -p |
direction 文件 interactive 交互 recrusive 迭代 all 全部 prot 端口 |
ls -d cp -i Desktop/1.txt Desktop rm -r Desktop ls -a ssh -p 22 [email protected] |
顯示文件結構 |
ls tree |
list 顯示文件的列表 樹 樹狀顯示 |
ls -lha tree -d Desktop |
查看/修改文件內容 |
cat more grep |
顯示文本 分屏顯示文本 搜索文本 |
cat -n Desktop/1.txt more Desktop/1.txt grep -n character file |
文件相關 |
pwd cd touch mkdir rm clear mv cp echo > >> | |
print work directory change directory create txt create directory remove clear shell move cope print to screen 輸出到文件 pip, 輸出做輸入 |
pwd cd Desktop touch Desktop/1.txt mkdir Desktop/1 rm -r Desktop/1 clear mv Desktop/1 Document cp -r Desktop/1 Document echo print >>Desktop/1/1.txt
cat 1.txt | grep 1 |
ssh |
shutdown ping ifconfig ssh scp
|
關機。重啓 測試連接 查看IP 遠程登錄 遠程傳文件 |
shutdown -r now ping 127.0.0.1 ifconfig | grep -n inet ssh -p 22 [email protected] scp -P 22 -r Desktop/1 [email protected]:Desktop |
權限相關 |
sudo groupadd useradd passwd groupdel /etc/group /etc/passwd usermod id who whoami which su
|
substitute user, 預設爲root 加組 加用戶 改密碼 刪組 組信息 用戶信息 修改用戶的組和附加組 查看用戶的組和附加組 查看所有登錄的賬戶 查看你登錄的賬戶 查看信息 開啓root
|
sudo groupadd dev sudo groupadd dev useradd -m -g dev usr1 passwd usr1 groupdel -r dev cat /etc/group | grep -n dev cat /etc/passwd | grep -n usr1 usermod -G dev2 id usr1 who whoami which python3 su
|
修改文件的權限 |
chown chgrp chmod |
修改所有者 修改歸屬組 修改權限信息 |
chown -R usr1 Desktop/1 chgrp -R usr1 Desktop/1 chmod -R 777 Desktop/1 |
技巧:
1. tab 補齊
2.在shell裏用arrow可以重複上一條指令
3.調節shell的字體大小 ctrl+shift+=
用戶管理命令
1.su: 切換當前的用戶。
su user2 #切換用戶
su -user2 #切換用戶,並且到新用戶的home下
exit #退出當前用戶
su #進入root賬號
2.我們先解釋一下在ls -lh下顯示的文件權限信息,然後再解釋改變文件權限信息的方式
drwxr-xr-x 2 usr2 pi 4096 11月 9 21:42 1
# explain for each character
d: directory
rwx: read write execute, the first one is for the creator of this file
r-x: three authorizations for the group members
r-x: three authorization for the rest members
2: the the way to access this file.
usr2: the owner of this file
pi: the group
4096: the size of this file
11.9: the creation date
21:42: the last modification date
1: the file name
and the shell will tell the doc and directory use diff color
#
chown -R user dir #modify the owner of this file
chgrp -R user dir #modify the group of this file
chmod -R 755 dir # change the file authorization
chmod -R +/-rwx #the same command, but the function is limited, only for owner.