linux系統命令基礎知識

來源:互聯網
上載者:User

標籤:應用程式   設定檔   常用   引導程式   撤銷   開始   ctr   通過   是否一致   

安裝好Linux系統之後查看/目錄,/下目錄的作用如下:

/下目錄作用
/bin /usr/bin /usr/local/bin 普通使用者可執行目錄
/sbin /usr/sbin /usr/local/sbin 系統可執行目錄
/etc/設定檔目錄
/usr/應用程式目錄
/var/伺服器資料目錄
/lib /usr/lib /usr/local/lib 庫檔案目錄(系統模組)
/dev/塊裝置目錄和字元裝置
/boot引導程式目錄(核心,開機檔案,引導程式)
/root管理員家目錄
/home普通使用者家目錄
/proc記憶體資訊目錄(記憶體資訊和進程資訊) 偽檔案系統
/sys記憶體資訊目錄(記憶體資訊和進程資訊) 偽檔案系統
/tmp臨時檔案目錄
/opt第三方軟體目錄
/mnt臨時掛在點
/srv伺服器資料目錄
/media媒體目錄
/miscautofs
/netautofs
/tftpboottftp服務使用
/selinux selinux使用
/lost+found 用於檔案系統恢複

 

linux常用命令

ctrl+l 清屏
ctrl+c 中斷

[基本命令]

ls -l install.log
-:rw-r--r-- :1 :root :root :39410 : 2013-05-21: install.log
檔案類型:許可權:永久連結數:擁有者:所屬組:檔案大小:最後一次修改時間:檔案名稱
- 普通檔案
d 目錄檔案
c 字元檔案
b 塊裝置檔案
l 軟連結檔案(符號)
p 管道檔案
s 通訊端檔案

ls -l 長格式 -a 所有檔案 -A 所有檔案除了.和..
. 目前的目錄
.. 上層目錄
-d 顯示目錄資訊 -h 最大單位顯示 -t 安時間排序
-r 反向 -R 遞迴

1.ls --help
2.info ls
3.type ls
alias la=‘ls -la‘
unalias la
4.man ls
一 使用者命令
二 系統調用
三 庫調用
四 特殊檔案
五 設定檔
六 遊戲
七 雜項(man)
八 系統命令
九 核心參考

makewhatis 維護man後台
man -f passwd 查詢命令在那些章節有相應說明
man -k passwd 模糊查詢

cd cd / .. ../.. . ~ -返回上次工作目錄
pwd 查詢位置

查看檔案內容

1.head

head -n 30 install.log

2.tail

tail -n 20 install.log

tail -f /var/log/messages

3.more

more install.log

4.less

less install.log

5.cat

cat -n install.log

cat -b install.log

 

cat -n install.log | less

| 管道符號

前一個命令輸出作為後一個命令輸入

 

建立檔案

touch

touch aa.txt

touch cc.txt tt.txt

touch abc{1..10}.txt

touch {a,b,c}{1..3}.txt

 

建立目錄

mkdir

mkdir tt

mkdir test1 test2

mkdir abc{1..10}

mkdir -p dir/aa

mkdir -pv dir/aa

 

拷貝copy 剪下move

cp /root/install.log /tmp/

cp /root/install.log /tmp/install 拷貝的同時重新命名

cp -r /tmp/dir/ /

mv /root/xx.txt /tmp/

mv /root/xx.txt /tmp/haha.txt

mv xx.txt xx.txt.bak

mv /tmp/tt /

 

刪除

rmdir 只能刪除空目錄

rm

rm tt.txt

rm -f install.log

rm -rf abc9

rm -rf *.txt

rm -rf abc*

rm -rf /dir/

vim 文字編輯器 vi
命令模式進入輸入模式
a 當前字元後輸入
A 當前行行尾輸入
i 當前字元前輸入
I 當前行行首輸入
o 當前行下一行輸入
O 當前行上一行輸入
s 刪除當前字元後輸入
S 刪除當前行後輸入

home鍵位行首 end行尾

命令模式
u 撤銷一步操作
ctrl + r 重做

yy 複製一行
50yy 複製50行
dd 剪下一行 dd刪除
50dd 剪下50行

p 粘貼

w 下一個單詞的首字元
dw 刪除/剪下一個單詞 yw

^ 行首 d^ y^
$ 行尾 d$ y$

G 尾行
gg 首行
750G 定位到750
dgg 刪除當前行到首行
dG 刪除當前行到尾行

末行模式
:w :q :wq
:w! :q! :wq!
:e /root/aa.txt 開啟/讀入
:2,3w /root/newfile.txt 另存
:r /root/file.txt 追加讀入
:e! 重新讀入當前檔案

:set nu 顯示行號
:set nonu 去掉行號
:set autoindent 自動縮近
:set noautoindent 去掉自動縮近

尋找
/ 從上往下
? 從下往上
N n

替換
:%s/ab/OO/gc %所有行 g全域 s替換 c互動式替換
2,5s/ab/OO/gc

:%s/^\t// 替換所有開始指標符
:%s/\t// 替換每行第一個指標符
:%s/ //g 去掉所有空格
:%s/^#//g 刪掉行首#

:g/^$/d 刪除空行
:g/^\s*$/d 刪除所有類型空行

:X 加密 解密

vim設定檔 /etc/vimrc

多檔案操作
vim aa.txt cc.txt tt.txt
:args next prev first last ctrl+6

vimdiff aa.txt cc.txt tt.txt
ctrl+w+w

vim -O aa.txt tt.txt cc.txt
vim -o aa.txt tt.txt cc.txt

vim教程
/usr/share/vim/vim70/tutor/tutor.zh.euc

gedit /usr/share/vim/vim70/tutor/tutor.zh.euc
檔案--->另存---->字元集----->儲存----->替換
vimtutor

iconv -f gb18030 -t utf-8 tutor.zh.euc -o test.txt
字元編碼轉換

shift+k

可視化模式v
y 複製 d 刪除 p 粘貼
可視化塊模式 ctrl+v
shift+i----->輸入字元-->ESC(兩次)

使用者管理
uid 0 rootgid 0 root
uid 1-499 system gid 1-499 system group
uid 500-60000 user gid 500-60000 group

添加使用者useradd
useradd abc1

儲存使用者資訊的檔案:/etc/passwd
robin:x:500:500:ptuser:/home/robin:/bin/bash
使用者名稱:密碼預留位置號:uid:gid:描述:家目錄:shell

useradd -u 1000 -g 500 -c hello -d /mnt/abc2 -s /bin/bash abc2

添加組groupadd
groupadd uplooking

儲存組資訊的檔案 /etc/group
uplooking:x:502:
組名:組密碼預留位置號:gid:使用者名稱
groupadd -g 2000 upup

設定密碼
1.root通過passwd robin
2.robin執行passwd修改自己密碼

密碼儲存檔案:/etc/shadow
robin:$1$Bj0Exbfx$e24mczi0jmsiDR:15847:2:10:3:2::

第一列:使用者名稱
第二列:密碼(md5)
第三列:密碼最後一次修改時間(天)
第四列:密碼最小時間
第五列:密碼最大時間(密碼有效期間)(天)
第六列:密碼到期前警告時間
第七列:密碼到期後帳號到期時間
第八列:帳號有效期間
第九列:保留列

練習:
1.添加組kkk gid為1500
groupadd -g 1500 kkk
2.添加使用者 zorro uid 1500 屬於kkk組 描述:hello 家目錄/mnt shell:bash

useradd -u 1500 -g kkk -c hello -d /mnt/zorro -s /bin/bash zorro

3.通過管理員設定該使用者密碼為123
終端登入zorro 設定自己密碼為123.com


修改使用者資訊
usermod
usermod -u -g -c -d -s robin

usermod -l abc2abc abc2
usermod -L robin
usermod -U robin
usermod -f 密碼到期後帳號到期時間
usermod -e 帳號有效期間

修改組資訊
groupmod -g 2500 uplooking
groupmod -n upup uplooking

修改密碼及資訊
passwd -n(最小時間) -x 最大時間 -w 警告時間 -i 密碼到期後帳號到期時間

passwd -l robin 鎖定密碼
passwd -u robin 解鎖密碼
passwd -S robin  查看密碼狀態

添加使用者tom和jerry 分別設定兩個使用者密碼為123
鎖定tom帳號 鎖定jerry密碼
終端登入測試 傳回值是否一致?
查看shedow檔案 兩個使用者有什麼區別?
!鎖定帳號
!! 鎖定密碼

刪除使用者:
userdel -r abc2
刪除群組
groupdel upup


附加組
groupadd yw
groupadd kf
useradd -G kf,yw wg 覆蓋附加組資訊
useradd -a -G kf,yw wg 追加附加組資訊

groupadd boss
gpasswd boss

手動添加帳號
#####1.groupadd zu
1).vim /etc/group
zu:x:2000:

######2.useradd -g zu zhb
1).vim /etc/passwd
zhb:x:2000:2000::/home/zhb:/bin/bash
2).mkdir /home/zhb
3).cp /etc/skel/.bash* /home/zhb/

#####3.passwd zhb
1).vim /etc/shadow
zhb::15848:0:99999:7:::
2).grub-md5-crypt產生密碼 將密碼複製到第二列

終端登入測試 建立檔案?


多使用者匯入
1.匯入檔案(user.txt)內的使用者和系統的passwd檔案使用者資訊不能衝突
2.匯入檔案(user.txt)內使用者不能衝突

[[email protected] ~]# cat user.txt
user1:x:3000:3000:ptuser:/home/user1:/bin/bash
user2:x:3001:3001:ptuser:/home/user2:/bin/bash

newusers < user.txt

[[email protected] ~]# cat passwd.txt
user1:123
user2:123

chpasswd < passwd.txt

使用者設定檔
/etc/default/useradd
HOME=/home
SHELL=/bin/bash
SKEL=/etc/skel

/etc/login.defs(限制uid數量 密碼限制)

 

linux系統命令基礎知識

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.