---
# System prepended metadata

title: Linux Commands
tags: [Linux Essentials]

---

---
title: Linux Commands
tags: "Linux Essentials"
image: 
---
<!-- title naming rule:  https://phoenixnap.com/kb/linux-commands-cheat-sheet -->

# Linux Commands Cheat Sheet

:::info
熟悉 Linux 常用指令，方能事半功倍!
:::

## Hardware Info

* dmesg
* ==cat== /proc/cpuinfo
* free -h
* lshw
* lsblk
* lspci -tv
* lsusb -tv
* dmidecode
* hdparm -i /dev/[disk]
* hdparm -tT /dev/[disk]
* badblocks -s /dev/[disk]


## File Compression

* tar cvf  [compressed_file.tar] [file_name]
* tar xvf  [compressed_file.tar]
* ==tar== zcvf [compressed_file.tar.gz]
* gzip [file_name]


## Package Installation

* Install from source:
```
./configure
make
make install
```
* ``dpkg -i pkg.deb`` – install a package (Debian)`
* ``rpm -Uvh pkg.rpm`` – install a package (RPM)
* apt-get
  * ``sudo apt-get update``
  * ``sudo apt-get upgrade``
  * ``apt-cache search --names-only vim``
  * ``sudo apt-get install vim``
  * ``sudo apt-get remove vim``


## SSH Login

* ssh user@host
* ssh host
* ssh -p [port] user@host
* telnet host


## Searching

* grep [pattern] [file_name]
* ==grep== -r [pattern] [directory_name]
* egrep
* locate [name]
* ==find== [/folder/location] -name [a]
* find [/folder/location] -size [+100M]


## File Transfer

* scp [file_name.txt] [server/tmp]
* rsync -a [/your/directory] [/backup/] 


## Process Related

* ==ps==
* pstree
* pmap
* top
* ==kill== [process_id]
* pkill [proc_name]
* ==killall== [proc_name]
* bg
* fg
* fg [job]
* lsof


## File Permission

* chmod 777 [file_name]
* chmod 755 [file_name]
* chmod 766 [file_name]
* chown [user] [file_name]
* chown [user]:[group] [file_name]
* chgrp


## File Commands

* ==ls==
* ls -a
* pwd
* mkdir [directory]
* rm [file_name]
* ==rm== -r [directory_name]
* rm -rf [directory_name]
* ==cp== [file_name1] [file_name2]
* cp -r [directory_name1] [directory_name2]
* ==mv== [file_name1] [file_name2]
* ln -s /path/to/[file_name] [link_name]
* touch [file_name]
* more [file_name]
* head [file_name]
* tail [file_name]
* gpg -c [file_name]
* gpg [file_name.gpg]
* wc
* ==file== [file_name]
* du -hs [directory_name]


## System Info

* uname -r
* uname -a
* uptime
* hostname
* hostname -i
* last reboot
* date
* timedatectl
* cal
* w
* whoami
* finger [username]


## Network

* ip addr show
* ip address add [IP_address]
* ifconfig
* netstat -pnltu
* netstat -nutlp
* whois [domain]
* dig [domain]
* dig -x host
* dig -x [ip_address]
* host [domain]
* hostname -I
* wget [file_name]


## Directory Navigation

cd ..
==cd==
cd /chosen/directory

## Users

* id
* last
* who
* w
* groupadd
* [group_name]
* adduser [user_name]
* usermod -aG [group_name] [user_name]
* userdel [user_name]
* usermod


## Disk Usage

* df -h
* df -i
* fdisk -l
* du -ah
* du -sh
* findmnt
* mount [device_path] [mount_point]


## References

* [Linux Commands Cheat Sheet: With Examples](https://phoenixnap.com/kb/linux-commands-cheat-sheet)
* [...](https://...)


