1. 程式人生 > >Linux 常用命令和使用者管理

Linux 常用命令和使用者管理

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+=

常用命令

絕對路徑/相對路徑

recursive 

directory 

使用者管理命令

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.