1. 程式人生 > >Linux的基礎命令

Linux的基礎命令

一、Linux基本命令(一)

Linux命令分為內部命令和外部命令,命令字母+選項+引數(再跟目錄/檔案)##可以通過type檢視那個命令是否是內部或者外部命令。 Linux常見的目錄: /root ##root使用者家目錄 /home ##普通使用者家目錄 /bin ##普通使用者使用的命令 /sbin ##管理員使用的命令 /boot ##啟動相關的檔案 /dev ##裝置檔案 /etc ##配置檔案 /usr ##系統檔案 /var ##存放的是一些變化檔案 /tmp ##臨時檔案 /proc ##記憶體虛擬檔案 /media ##移動裝置預設的掛載點 /mnt ##手工掛載裝置的掛載點 /lib ##庫檔案 Linux配置本地倉庫: vi /etc/yum.repo.d/yum.repo [yum] ##倉庫ID,相當於身份證ID name=yum ##倉庫名,相當於我們自己的姓名 baseurl=file:///mnt ##掛載點,掛載光碟(映象)的地方 gpgcheck=0 ##預設是否進行檢測,0為不檢測,1檢測 enabled=1 ##是否開啟倉庫,1開啟,0不開啟 1. cd ##切換 這裡寫圖片描述

2. mkdir ##建立目錄 mkdir -p 消除依賴關係連續建立目錄 這裡寫圖片描述 3. ls ##檢視目錄 [[email protected] ~]# ls anaconda-ks.cfg test test1 4. touch ##建立檔案/文字 [[email protected] ~]# touch files [[email protected] ~]# ls anaconda-ks.cfg files test test1 5. pwd ##檢視當前路徑,相當於定位 [
[email protected]
~]# pwd /root 6. clear ##清屏 7. uname -r ##檢視當前Linux核心版本資訊 [[email protected] ~]# uname -r 3.10.0-862.el7.x86_64 8. uname -a ##詳細檢視當前Linux所有資訊 [[email protected] ~]# uname -a Linux test 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux 9. hostname ##檢視當前主機名稱 [
[email protected]
~]# hostname test #也可以用來臨時改名,例如: [[email protected] ~]# hostname xd [[email protected] ~]# bash [[email protected] ~]# hostname xd 10. cat /proc/meminfo ##檢視記憶體資訊 [[email protected] ~]# cat /proc/meminfo ##在這裡只列舉了前四條 MemTotal: 1865284 kB MemFree: 1521864 kB MemAvailable: 1519724 kB Buffers: 2076 kB 11. du ##統計當前目錄的磁碟空間大小 [[email protected] ~]# du 0 ./test 0 ./test1/test2 0 ./test1 28 . 12. rm ##刪除文字 -r ##刪除目錄 -f ##強制 [[email protected] ~]# touch aa qq [[email protected] ~]# ls aa anaconda-ks.cfg files file.txt qq test test1 [[email protected] ~]# rm aa rm: remove regular empty file ‘aa’? [[email protected] ~]# rm -f qq [[email protected] ~]# rm -rf file 13. which ##檢視命令所在的目錄 [[email protected] ~]# which ls alias ls=’ls –color=auto’ /usr/bin/ls 14. find -name ##根據名稱來查詢檔案 find -size ##根據大小來查詢檔案 find -user ##根據使用者來查詢檔案 find -type ##根據檔案型別查詢檔案 [[email protected] ~]# ls aa anaconda-ks.cfg files file.txt test test1 [[email protected] ~]# find -name files ./files 15. cat ##檢視檔案/文字中的內容 [[email protected] home]# cat /etc/passwd ##只是截取了一部分 root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync 16. more和less ##分頁檢視檔案內容 [[email protected] home]# more /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin [[email protected] home]# less /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin 17. head -5 ##檢視檔案/文字前5行 [[email protected] home]# head -5 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 18. tail -5 ##檢視檔案/文字後5行 [[email protected] home]# tail -5 /etc/passwd systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin polkitd:x:999:998:User for polkitd:/:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin 19. wc -c ##統計檔案內容位元組數 wc -l ##統計檔案內容行數 wc -w ##統計檔案內容單詞數 [[email protected] home]# wc -c /etc/passwd 798 /etc/passwd [[email protected] home]# wc -l /etc/passwd 18 /etc/passwd [[email protected] home]# wc -w /etc/passwd 26 /etc/passwd 20. grep “要查詢的內容” 所在行 ##精確查詢 grep -v“`#” /etc/passwd ##查詢除以#開頭以外的行 [[email protected] home]# grep “root” /etc/passwd root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin 21. ls –help ##檢視ls的幫助資訊 mkdir –help ##檢視mkdir的幫助資訊 [[email protected] home]# ls –help Usage: ls [OPTION]… [FILE]… List information about the FILEs (the current directory by default). Sort entries alphabetically if none of -cftuvSUX nor –sort is specified. 22. man ls | col -b > /a/lshelp.txt ##把ls的幫助資訊儲存成文字 “|” ##重定向輸出 “”“>” ##將掐面命令成功的結果輸出到儲存的檔案中 [[email protected] home]# man ls | col -b > /root/test/ls_help.txt [[email protected] home]# cd /root/test [[email protected] test]# ls ls_help.txt