Linux

[Linux] User Operations

  • 查看線上使用者
who
  • 查看自身
whoami
  • 登出其他使用者
sudo pkill -u username

[Linux] gcc指令

  • 編譯+執行
gcc -o targetname sourcename.c ; ./targetname

[Linux] File Operations

  • 顯示檔案,依照時間排序
ll -t
  • 查詢檔案
find targetdir targetfile
find targetdir -type mytype -name targetfile
  • 刪除檔案
rm -rf targetfile
-r:遞迴刪除資料夾內所有內容
-f:強制刪除
  • 壓縮/解壓縮/檢視
#壓縮
tar -zcvf out.tar.gz sourcedir
#解壓縮
tar -zxvf in.tar.gz -C targetdir
#檢視
tar -ztvf in.tar.gz
  • 複製檔案
#複製單一檔案並改名為targetfile
cp sourcefile targetfile
#複製單一檔案至某目錄下
cp sourcefile targetdir
#複製資料夾
cp -r sourcedir targetdir
  • 移動(更名)檔案
mv sourcefile targetfile
#一次移動多個檔案
mv -t targetdir file1 file2 ...
#格式化更名檔案,將matchfile符合exp1的字替換成exp2
rename 's/exp1/exp2/g' matchfile

[Linux] Disk Operations

  • 觀察磁碟分割狀態
lsblk
freeBSD:
camcontrol devlist

example:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1.5G 0 rom /media/hubert/Ubuntu 16.04.3 LTS amd64
sda 8:0 0 40G 0 disk 
├─sda2 8:2 0 1K 0 part 
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda1 8:1 0 38G 0 part /
  • 磁碟分割與掛載
df mydir #查看zfs分割掛載
gpart show mydisk #查看gpt分割
  • 分辨磁碟分割是GPT還是MBR
fdisk -l /dev/sda

example:

若出現:WARNING: GPT (GUID Partition Table) detected,則是GPT
若正常顯示磁碟分割,則是MBR
  • 退出CD
eject

[Linux] Kernel Version

cat   /proc/version

uname   -a
#lsb_release -a

LSB Version: 1.3

Distributor ID: RedHatEnterpriseAS

Descrīption: Red Hat Enterprise Linux AS release 4 (Nahant Update 1)

Release: 4

Codename: NahantUpdate1

[Linux] Get My Public IP

If You are not Behind a Router

  • You can find it out using ifconfig.

If You are Behind a Router

  • Your computer will not know about the public IP address as the router does a network address translation.
curl icanhazip.com

[Linux] Centos7 remove the old kernels

Why removing the old kernels?

  • Even though the old kernels are not harmful to your system, they still take up some space in your disk.
  • The menu of grub2 will become more complex and unuseful, squeezing your custom list to the bottom.

 1.Check Installed Kernels

rpm-qa kernel

 2.Remove Kernels

–count=n, n is the number of kernels YOU WANT TO LEFT.

yum install yum-utils
package-cleanup --oldkernels --count=1

 3.Set Number of Old Kernels Saved

edit /etc/yum.conf

installonly_limit=1