คำสั่ง Linux ที่ฉันโปรดปราน - รายการคำสั่ง Linux พื้นฐาน 25+ อันดับแรกและ Cheat Sheet
เผยแพร่แล้ว: 2017-10-07ฉันทำงานบนสภาพแวดล้อม Linux มาเป็นเวลานาน และเพิ่งได้สำรวจคำสั่งอื่นๆ อีกมากมายเมื่อเร็วๆ นี้ ในบทช่วยสอนนี้ เราจะพูดถึงคำสั่ง Linux ที่ใช้บ่อยที่สุดเพื่อการอ้างอิงที่สะดวกของคุณ
มาเริ่มกันเลย.
1. จะรับเวอร์ชัน Linux OS และข้อมูลระบบได้อย่างไร
1 2 3 4 5 6 7 8 9 10 |
root @ crunchify : ~ # lsb_release -a No LSB modules are available . Distributor ID : Ubuntu Description : Ubuntu 17.04 Release : 17.04 Codename : zesty root @ crunchify : / opt # uname -a Linux crunchify 4.9.36 - x86_64 - linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux |
2. จะอัพเดท OS เป็นเวอร์ชั่นล่าสุดได้อย่างไร?
apt – รับ การอัปเดต && apt – รับการ อัปเกรด
3. จะสร้างและแยก tar.gz ได้อย่างไร?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
root @ crunchify : / tmp / crunchify # ls -ltra total 12 drwxrwxrwt 10 root root 4096 Oct 6 17 : 51 . . - rw - r -- r -- 1 root root 6 Oct 6 17 : 51 one . txt drwxr - xr - x 2 root root 4096 Oct 6 17 : 51 . < ! -- Create tar . gz file -- > root @ crunchify : / tmp / crunchify # tar -cvf - one.txt | gzip > crunchify.tar.gz one . txt root @ crunchify : / tmp / crunchify # ls -ltr total 16 - rw - r -- r -- 1 root root 6 Oct 6 17 : 51 one . txt - rw - r -- r -- 1 root root 10240 Oct 6 17 : 52 crunchify . tar . gz < ! -- Extract tar . gz file -- > root @ crunchify : / tmp / crunchify # tar -zxvf crunchify.tar.gz one . txt |
4. จะดูไฟล์ Linux ที่ซ่อนอยู่ได้อย่างไร?
root@crunchify:/tmp/crunchify# ls -ltra
5. จะเชื่อมโยงไฟล์ใน Linux ได้อย่างไร?
ln -s /path/to/file /symlink
ในคำสั่งด้านล่าง .. เมื่อคุณพิมพ์ /tmp/java มันจะถูกเปลี่ยนเส้นทางไปที่ /opt/java
1 2 3 4 5 6 7 8 |
root @ crunchify : / tmp / crunchify # ln -s /opt/java/ /tmp/java root @ crunchify : / tmp # pwd / tmp root @ crunchify : / tmp # ls -ltr total 4 drwxr - xr - x 4 root root 4096 Oct 6 18 : 01 crunchify lrwxrwxrwx 1 root root 10 Oct 6 18 : 03 java - > / opt / java / |
จะอัปเดต Symlink อย่างแรงได้อย่างไร เพียงใช้พารามิเตอร์ -fs
6. จะเปลี่ยนสิทธิ์และเจ้าของไฟล์ได้อย่างไร?
-
chmod
777 <ชื่อไฟล์> -
chown
root:root <ชื่อไฟล์>
ต้องการใช้ chmod และ chown บนไดเร็กทอรีหรือไม่? เพียงใช้พารามิเตอร์ -R ตัวอย่าง: chmod -R 777 /folder/
.
7. วิธีการคัดลอกไฟล์จากระยะไกล?
scp [email protected]:/tmp/crunchify/one.txt /opt/
ใช้พารามิเตอร์ -r
เพื่อคัดลอกโฟลเดอร์
8. จะตรวจสอบได้อย่างไรว่า Java Process ทำงานอยู่?
ps -ไม่กี่ | grep java
9.ตรวจสอบว่า VM ของฉันทำงานนานแค่ไหน?
1 2 |
root @ crunchify : / tmp / java # uptime 18 : 12 : 24 up 34 min , 2 users , load average : 0.08 , 0.02 , 0.01 |
10 . จะสร้าง HeapDump ของกระบวนการ Java ได้อย่างไร?
$/opt/java/bin> ./jmap -dump:format=b,file=/tmp/heapdump.dmp 33333 (ID กระบวนการ)
11. จะตรวจสอบจำนวนการเชื่อมต่อที่ใช้งานบนพอร์ต 8080 ทุก ๆ 5 วินาทีได้อย่างไร?
ในขณะที่จริง; ทำ netstat -an | grep -c $(ชื่อโฮสต์ -i):8080; นอน 5; เสร็จแล้ว;
12. จะเข้าสู่ระบบในฐานะผู้ใช้รายอื่นได้อย่างไร?
sudo su – กระทืบ
13. จะดาวน์โหลด JDK 9 จากอินเทอร์เน็ตได้อย่างไร?
สั่งการ:
1 |
root @ crunchify : / tmp / java # curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/9+181/jdk-9_linux-x64_bin.tar.gz |
ต้องการติดตั้ง Java โดยใช้ system command
?
1 2 3 4 5 6 7 8 9 10 11 12 |
root @ crunchify : / tmp / java # java -version The program 'java' can be found in the following packages : * default - jre * openjdk - 8 - jre - headless * gcj - 4.8 - jre - headless * gcj - 4.9 - jre - headless * gcj - 5 - jre - headless * gcj - 6 - jre - headless * openjdk - 9 - jre - headless Try : apt install < selected package > root @ crunchify : / tmp / java # apt install openjdk-9-jre-headless |
14. จะล้างไฟล์ขนาดใหญ่ได้อย่างไร?
ใช้คำสั่ง cat /dev/null > file-name
1 2 3 4 5 6 7 8 9 10 |
root @ crunchify : / opt # ls -ltr total 16 drwxr - xr - x 3 root root 4096 Oct 6 18 : 23 java - rw - r -- r -- 1 root root 11729 Oct 6 18 : 32 one . txt root @ crunchify : / opt # cat /dev/null > one.txt root @ crunchify : / opt # ls -ltr total 4 drwxr - xr - x 3 root root 4096 Oct 6 18 : 23 java - rw - r -- r -- 1 root root 0 Oct 6 18 : 33 one . txt |
15. จะสร้างไฟล์โดยไม่มี VI หรือ VIM ได้อย่างไร?
ใช้คำสั่ง touch
1 2 3 4 5 6 7 8 9 10 11 12 |
root @ crunchify : / opt # ls -ltr total 4 drwxr - xr - x 3 root root 4096 Oct 6 18 : 23 java - rw - r -- r -- 1 root root 0 Oct 6 18 : 33 one . txt root @ crunchify : / opt # touch two.txt root @ crunchify : / opt # ls -ltr total 4 drwxr - xr - x 3 root root 4096 Oct 6 18 : 23 java - rw - r -- r -- 1 root root 0 Oct 6 18 : 33 one . txt - rw - r -- r -- 1 root root 0 Oct 6 18 : 36 two . txt |
16. จะดูและล้างประวัติคำสั่งได้อย่างไร?
- root@crunchify:/opt# history (เพื่อดูประวัติ)
- root@crunchify:/opt# history -c (เพื่อล้างประวัติ)
17. ข้อมูลระบบทั่วไป
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
--------- Free and use memory ----------- root @ crunchify : / opt # free -h total used free shared buff / cache available Mem : 989M 93M 241M 7.7M 654M 868M Swap : 511M 0B 511M --------- system info ----------- root @ crunchify : / opt # uname -a Linux crunchify 4.9.36 - x86_64 - linode85 #1 SMP Thu Jul 6 15:31:23 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux --------- release info ----------- root @ crunchify : / opt # uname -r 4.9.36 - x86_64 - linode85 --------- find hostname ----------- root @ crunchify : / opt # hostname -f crunchify --------- Uptime Status ----------- root @ crunchify : / opt # uptime 18 : 41 : 51 up 1 : 04 , 2 users , load average : 0.00 , 0.00 , 0.00 --------- find IP ----------- root @ crunchify : / opt # hostname -I 74.207.254.177 2600 : 3c01 : : f03c : 91ff : febd : f028 --------- Check Last Reboot time ----------- root @ crunchify : / opt # last reboot reboot system boot 4.9.36 - x86_64 - li Fri Oct 6 17 : 37 still running wtmp begins Fri Oct 6 17 : 37 : 40 2017 --------- find Date ----------- root @ crunchify : / opt # date Fri Oct 6 18 : 42 : 09 UTC 2017 --------- Check Calendar ----------- root @ crunchify : / opt # cal October 2017 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 --------- check who all are online ----------- root @ crunchify : / opt # w 18 : 42 : 15 up 1 : 04 , 2 users , load average : 0.00 , 0.00 , 0.00 USER TTY FROM LOGIN @ IDLE JCPU PCPU WHAT root ttyS0 - 17 : 45 55 : 23 0.03s 0.02s - bash root pts / 0 216.113.160.67 17 : 47 7.00s 0.39s 0.00s w --------- check who you are ----------- root @ crunchify : / opt # whoami root |

18. คำสั่งติดตามและสถิติ
1 2 |
------------- Display the last 20 lines of file - and follow it along ------------- root @ crunchify : / opt # tail -f one.txt |
19. Grep Command – ค้นหาไฟล์
1 2 3 4 5 6 7 8 |
----------- Grep text crunchify from file one . txt ----------- root @ crunchify : / opt # grep crunchify one.txt ----------- How to Find files larger than 500MB in / opt --------- find / opt - size + 500M ----------- Find files in / opt / java that start with "java" ----------- find / opt / java - name 'java*' |
20. คำสั่งพื้นที่ดิสก์
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
----------- Current directory Disk usage ----------- root @ crunchify : / opt # du -sh 875M . ----------- Disk usage in mounted file system ----------- root @ crunchify : / opt # df -h Filesystem Size Used Avail Use % Mounted on / dev / root 20G 2.5G 16G 14 % / devtmpfs 493M 0 493M 0 % / dev tmpfs 495M 0 495M 0 % / dev / shm tmpfs 495M 7.7M 487M 2 % / run tmpfs 5.0M 0 5.0M 0 % / run / lock tmpfs 495M 0 495M 0 % / sys / fs / cgroup tmpfs 99M 0 99M 0 % / run / user / 0 ----------- Show inodes stats ----------- root @ crunchify : / opt # df -i Filesystem Inodes IUsed IFree IUse % Mounted on / dev / root 1180608 67446 1113162 6 % / devtmpfs 126148 1375 124773 2 % / dev tmpfs 126633 1 126632 1 % / dev / shm tmpfs 126633 1191 125442 1 % / run tmpfs 126633 2 126631 1 % / run / lock tmpfs 126633 16 126617 1 % / sys / fs / cgroup tmpfs 126633 5 126628 1 % / run / user / 0 |
21. ทำความเข้าใจการอนุญาตไฟล์ลินุกซ์
1 2 3 4 5 6 7 8 |
PERMISSION EXAMPLE U G O rwx rwx rwx chmod 777 filename rwx rwx r - x chmod 775 filename rwx r - x r - x chmod 755 filename rw - rw - r -- chmod 664 filename rw - r -- r -- chmod 644 filename |
22. แผ่นโกงคำสั่ง Handy Linux:
คลิกเพื่อขยาย