內容選單標籤

2025年8月17日 星期日

指令介紹

 ---------------------------------------------------------------------------
線上說明

 ~$ man ls

clear(1)                                          User commands                                         clear(1)
NAME
 ...
SYNOPSIS
...    
DESCRIPTION
...
OPTIONS
...

PORTABILITY
...

HISTORY
...

SEE ALSO
 

~$ info ls
~$ ls --help
 

 

 ---------------------------------------------------------------------------
檔案與磁碟管理

 ~$ ls
 下載
...

~$ cd 下載
~/下載$ 

~/下載$ pwd
/home/kk/下載

~/下載$ cd ~                #回使用者家目錄,或cd 不加參數
kk@ubun:~$ 

 

 ---------------------------------------------------------------------------

 ---------------------------------------------------------------------------

 ---------------------------------------------------------------------------

 ---------------------------------------------------------------------------

 --------------------------------------------------------------------------- 

2025年8月4日 星期一

安裝QEMU/KVM 套件、新Ubuntu

 

------------------------------------------------------
硬體規格:4核 CPU、7.5GB RAM、219GB 硬碟

~$ lscpu
架構:                    x86_64
  CPU 作業模式:          32-bit, 64-bit
  Address sizes:          36 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   4
  On-line CPU(s) list:    0-3
 

~$ free -h
                       total        used        free      shared  buff/cache   available
Mem:           7.5Gi       2.3Gi       3.3Gi       474Mi       2.5Gi       5.2Gi
置換:         2.0Gi          0B       2.0Gi
 

~$ df -h
檔案系統        容量  已用  可用 已用% 掛載點
tmpfs           765M  1.9M  764M    1% /run
/dev/sda3       219G   46G  163G   22% /
tmpfs           3.8G   19M  3.8G    1% /dev/shm
tmpfs           5.0M  8.0K  5.0M    1% /run/lock
tmpfs           3.8G     0  3.8G    0% /run/qemu
/dev/sda2       512M  6.2M  506M    2% /boot/efi
tmpfs           765M  136K  765M    1% /run/user/1000
 

------------------------------------------------------
確認系統支援虛擬化

#輸出 >0 表示支援
~$ egrep -c '(vmx|svm)' /proc/cpuinfo
8
 

~$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
 

------------------------------------------------------ 
安裝EMU/KVM套件、當前用戶加入權限群組

~$ sudo apt update

~$ sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

~$ sudo usermod -aG libvirt,kvm $(whoami) 

# 立即生效(或重新登入)
~$ newgrp libvirt 

 

 

 

------------------------------------------------------
 使用USB安裝Ubuntu

 ~$ lsblk -l
...
sdc      8:32   1  57.7G  0 disk 
sdc1     8:33   1   5.9G  0 part /media/kk/Ubuntu 24.04.2 LTS amd64
sdc2     8:34   1     5M  0 part 
sdc3     8:35   1   300K  0 part 
sdc4     8:36   1  51.8G  0 part /media/kk/writable


 ------------------------------------------------------
月曆

~$ sudo apt update

~$ sudo apt install ncal

~$ cal
      八月 2025         
日 一 二 三 四 五 六  
                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                    

~$ date
西元2025年08月15日 (週五) 10時08分41秒 CST 

~$ cal 03 1969
      三月 1969         
日 一 二 三 四 五 六  
                   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          

 

 ------------------------------------------------------
youtube轉MP3

~$ sudo apt install yt-dlp ffmpeg -y 

~$ sudo apt update

~$ sudo apt upgrade yt-dlp 

~$ yt-dlp -x --audio-format mp3 --audio-quality 0 https://www.youtube.com/watch?v=By_Fd8IyzGg
 

 

 ------------------------------------------------------

 

 ------------------------------------------------------

 

 

 ------------------------------------------------------

 

 ------------------------------------------------------

 

 ------------------------------------------------------ 

2025年3月27日 星期四

Ubuntu24.04.2

系統時間呈現秒數 
設定-->系統-->日期與時間-->秒數

安裝chrome
下載/google-chrome-stable_current_amd64.deb
~$ ls 下載/google-chrome-stable_current_amd64.deb 
~$ ls ./下載/google-chrome-stable_current_amd64.deb
~$ sudo apt install ./下載/google-chrome-stable_current_amd64.deb 

 

 下載/google-chrome-stable_current_amd64.deb
-->右鍵-->使用AppCenter開啟-->安裝

 

更新
顯示程式-->軟體更新

 $ sudo apt update

$ sudo apt upgrade

 

APT、 dpkg、snap

apt 是 Ubuntu 中常用的套件管理指令    //Advanced Package Tool

dpkg 是直接管理 Debian 套件的低階指令

snap 是 Ubuntu 引入的新一代套件管理系統 

-----------------------------------------------------------------------

# sudo apt update    //更新軟體庫清單

$ apt list --upgradable        

# sudo apt upgrade     //升級系統或軟體

 # sudo apt search vlc    //搜尋特定應用程式

$ sudo apt install vlc    //安裝應用程式

$ apt list    //列出系統中的套件資訊
$ apt list --installed    //只顯示已安裝的套件

 $ sudo apt show vlc   //列出應用程式的詳細資訊
[sudo] kk 的密碼:
Package: vlc
Version: 3.0.20-3build6
Priority: optional
...

 $ sudo apt remove vlc    //移除應用程式

 $ sudo apt purge vlc    //移除應用程式及所有設定檔


                                                                                                                            

For Python IDLE

~$ python3 --version
Python 3.12.3

~$ python3
Python 3.12.3 (main, Feb  4 2025, 14:48:35) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print(3+6)
9

CTRL+D    or  CTRL+Z   //離開
 
 
$ sudo apt install idle3
 

 $ apt list -a idle
正在列出... 完成
idle/noble-updates,now 3.12.3-0ubuntu2 all [已安裝,自動]
idle/noble 3.12.3-0ubuntu1 all

$ apt list --installed | grep idle


~$ apt show -a idle
Package: idle
Version: 3.12.3-0ubuntu2
Priority: optional
Section: universe/python
Source: python3-defaults
...
 
顯示程式-->IDLE


切換admin

$ sudo su
[sudo] kk 的密碼:

root@kk-VMware-Virtual-Platform:/home/kk# exit 或 CTRL+D
exit


查看cpu、ram、process
$ top

CTRL+Z    //離開

 

查看記憶體
~$ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.7Gi       3.4Gi       1.8Gi       176Mi       2.9Gi       4.3Gi
置換:            0B          0B          0B


查看硬碟
~$ df -h
檔案系統        容量  已用  可用 已用% 掛載點
tmpfs           790M  2.1M  788M    1% /run
/dev/sda2        20G  8.9G  9.7G   48% /
tmpfs           3.9G   92M  3.8G    3% /dev/shm
tmpfs           5.0M  8.0K  5.0M    1% /run/lock
tmpfs           790M  148K  790M    1% /run/user/1000
/dev/sr0        5.8G  5.8G     0  100% /media/kk/Ubuntu 24.04.1 LTS amd64


打包 tar
 //c:create建立壓縮檔案 v:verbose輸出處理的檔案列表 f:archive file指定壓縮檔案
$ tar -cvf aa.tar a1.txt a2.txt   
a1.txt
a2.txt

//列出 .tar 壓縮檔案的內容
$ tar -tf aa.tar
a1.txt
a2.txt

//解壓縮 .tar 壓縮檔案
$ cp aa.tar 文件

$ cd 文件

$ ls
aa.tar
 

//x:extract
$ tar -xvf aa.tar
a1.txt
a2.txt
$ ls
a1.txt  a2.txt  aa.tar


 
----------------------------------------------------------------------------
Disk Mount

 ~$ sudo fdisk -l                # manipulate disk partition table
...
Disk /dev/sdb: 149.05 GiB, 160041885696 bytes, 312581808 sectors
Disk model: WDC WD1600JS-22M
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F40B36E3-5EC5-8642-B955-AEC41EB0B612

所用裝置   Start      結束      磁區  Size 類型
/dev/sdb1   2048 312581774 312579727  149G Linux filesystem
...


$ sudo blkid /dev/sdb1                # locate/print block device attributes
/dev/sdb1: UUID="f4f0b2ec-3e02-408d-bc5f-62b8a2612403" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="05c312c1-a6d8-634b-a30e-02c147ae7890"

~$ sudo mkdir /mnt/wdc01
~$ ls -l /mnt/wdc01
總用量 0

~$ sudo mount /dev/sdb1 /mnt/wdc01
~$ ls -l /mnt/wdc01
總用量 892600

 ~$ sudo umount /mnt/wdc01
~$ ls -l /mnt/wdc01
總用量 0
 

 

 列出掛載

~$ mount
...
/dev/sdb1 on /mnt/wdc01 type ext4 (rw,relatime)

 

~$ lsblk
...
sdb      8:16   0 149.1G  0 disk 
└─sdb1   8:17   0   149G  0 part /mnt/wdc01

 

~$ df -h
檔案系統        容量  已用  可用 已用% 掛載點
tmpfs           765M  1.9M  764M    1% /run
/dev/sda3       219G   43G  166G   21% /
tmpfs           3.8G     0  3.8G    0% /dev/shm
tmpfs           5.0M  8.0K  5.0M    1% /run/lock
/dev/sda2       512M  6.2M  506M    2% /boot/efi
tmpfs           765M  128K  765M    1% /run/user/1000
/dev/sdb1       146G  872M  138G    1% /mnt/wdc01

 

~$ cat /etc/mtab
...
/dev/sdb1 /mnt/wdc01 ext4 rw,relatime 0 0 

 


----------------------------------------------------------------------------
永久掛載磁碟(開機自動掛載)

$ sudo blkid
... 
/dev/sdb1: UUID="f4f0b2ec-3e02-408d-bc5f-62b8a2612403" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="05c312c1-a6d8-634b-a30e-02c147ae7890"

~$ lsblk -f
...
sdb                                                                             
└─sdb1 ext4     1.0         f4f0b2ec-3e02-408d-bc5f-62b8a2612403  137.3G     1% /mnt/wdc01

 

~$ ls -l /etc/fstab
-rw-rw-r-- 1 root root 665 12月 18  2022 /etc/fstab
~$ sudo cp /etc/fstab /etc/fstab.bk
~$ ls -l /etc/fstab*
-rw-rw-r-- 1 root root 665 12月 18  2022 /etc/fstab
-rw-r--r-- 1 root root 665  7月 11 11:11 /etc/fstab.bk

~$ sudo nano /etc/fstab
...
UUID=f4f0b2ec-3e02-408d-bc5f-62b8a2612403  /mnt/wdc01  ext4  defaults  0  0

 #最底下加入

 

UUID=<磁碟UUID>  <掛載點>  <文件系統類型>  <選項>  <備份>  <檢查>
 UUID:    磁碟的唯一識別碼    用 blkid 查詢
掛載點:    磁碟要掛載到的目錄    如 /mnt/data
文件系統類型:    磁碟的格式    ext4, ntfs, xfs, fat32
選項:    掛載參數    defaults(包含 rw,suid,dev,exec,auto,nouser,async)
備份:    是否用 dump 備份    0(不備份)
檢查:    開機時是否用 fsck 檢查    0(不檢查)、1(根目錄)、2(其他分區)

# 測試 fstab 是否正確,如果沒有錯誤訊息,表示 fstab 配置正確。
~$ sudo mount -a

 

重啟驗證
sudo reboot

開機後檢查是否自動掛載:
~$ df -h  # 查看掛載狀態
~$ lsblk -f  # 確認分區掛載情況 

 

卸載磁碟
~$ sudo umount /mnt/wdc01
並刪除 /etc/fstab 中的對應行。 

 

 
----------------------------------------------------------------------------
How to Delete All Partitions and Create a New Single Partition in Ubuntu

 ~$ lsblk
...
sdb      8:16   0 465.8G  0 disk 
├─sdb1   8:17   0   563M  0 part 
└─sdb2   8:18   0    59G  0 part 

~$ sudo gdisk /dev/sdb
[sudo] kk 的密碼: 
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: present

Found valid MBR and GPT. Which do you want to use?
 1 - MBR
 2 - GPT
 3 - Create blank GPT


Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Command (? for help): p
Disk /dev/sdb: 976773168 sectors, 465.8 GiB
Model: ST500DM002-1BD14
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 4B1314EA-9E88-4AF9-8462-947882E67B13
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 976773101 sectors (465.8 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): x

Expert command (? for help): z
About to wipe out GPT on /dev/sdb. Proceed? (Y/N): y
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y

~$ lsblk
...
sdb      8:16   0 465.8G  0 disk

~$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries in memory.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-976773134, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-976773134, default = 976773119) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): p
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdb: 976773168 sectors, 465.8 GiB
Model: ST500DM002-1BD14
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 6A4DEE9A-E958-4951-B9A9-9D733941AD14
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2029 sectors (1014.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       976773119   465.8 GiB   8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

~$ lsblk
...
sdb      8:16   0 465.8G  0 disk 
└─sdb1   8:17   0 465.8G  0 part 

~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 122096384 4k blocks and 30531584 inodes
Filesystem UUID: 694e2a5e-c728-4b41-8913-6b032e7bd22d
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

~$ lsblk -f
...
sdb                                                                         
└─sdb1
     ext4   1.0         694e2a5e-c728-4b41-8913-6b032e7bd22d  

~$ blkid
/dev/sda3: UUID="93c62a33-7ed4-4360-8b04-039d04dd41cb" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4efee950-a548-4e1d-ae82-f113bc1f310f"


----------------------------------------------------------------------------
Gdisk create partition and formmat filesystem ext4 and delete

 ~$ sudo gdisk /dev/sdb
[sudo] kk 的密碼: 
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-976773134, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-976773134, default = 976773119) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdb: 976773168 sectors, 465.8 GiB
Model: ST500DM002-1BD14
Sector size (logical/physical): 512/4096 bytes
Disk identifier (GUID): 6A4DEE9A-E958-4951-B9A9-9D733941AD14
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2029 sectors (1014.5 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048       976773119   465.8 GiB   8300  Linux filesystem

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.

~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.47.0 (5-Feb-2023)
/dev/sdb1 contains a ext4 file system
    last mounted on Tue Jul 15 11:42:07 2025
Proceed anyway? (y,N) y
Creating filesystem with 122096384 4k blocks and 30531584 inodes
Filesystem UUID: a760efbc-223b-4654-bc51-a7024b6d9c1b
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done  

~$ lsblk -f
...
sdb                                                                             
└─sdb1 ext4     1.0         a760efbc-223b-4654-bc51-a7024b6d9c1b 

               
~$ blkid
/dev/sda3: UUID="93c62a33-7ed4-4360-8b04-039d04dd41cb" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4efee950-a548-4e1d-ae82-f113bc1f310f"

/dev/sdb1: UUID="694e2a5e-c728-4b41-8913-6b032e7bd22d" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="36b27912-d9bd-4b70-8f22-1c5deab4e49f"
 

~$ sudo gdisk /dev/sdb
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): d
Using 1

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.


~$ lsblk -f
...
sdb                                                                         
 

~$ blkid
/dev/sda3: UUID="93c62a33-7ed4-4360-8b04-039d04dd41cb" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="4efee950-a548-4e1d-ae82-f113bc1f310f"
 

 

----------------------------------------------------------------------------
檢查USB隨身碟是GPT還是MBR及轉換為MBR並格式化為FAT且複製大量資料

~$ lsblk -l
...
sdd      8:48   1   3.8G  0 disk 
sdd1     8:49   1   3.8G  0 part /media/kk/CarMusic
 

~$ sudo parted -l
...
型號:USB 2.0 USB Flash Drive (scsi)
磁碟 /dev/sdd:4043MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  4042MB  4041MB  fat32     Linux filesystem
 

~$ sudo gdisk /dev/sdd
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu
 

Command (? for help): r

Recovery/transformation command (? for help): ?
b    use backup GPT header (rebuilding main)
c    load backup partition table from disk (rebuilding main)
d    use main GPT header (rebuilding backup)
e    load main partition table from disk (rebuilding backup)
f    load MBR and build fresh GPT from it
g    convert GPT into MBR and exit
h    make hybrid MBR
i    show detailed information on a partition
l    load partition data from a backup file
m    return to main menu
o    print protective MBR data
p    print the partition table
q    quit without saving changes
t    transform BSD disklabel partition
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu

Recovery/transformation command (? for help): g

MBR command (? for help): ?
a    toggle the active/boot flag
c    recompute all CHS values
l    set partition as logical
o    omit partition
p    print the MBR partition table
q    quit without saving changes
r    set partition as primary
s    sort MBR partitions
t    change partition type code
w    write the MBR partition table to disk and exit

MBR command (? for help): w

Converted 1 partitions. Finalize and exit? (Y/N): y
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.

 

~$ sudo parted -l
...
型號:USB 2.0 USB Flash Drive (scsi)
磁碟 /dev/sdd:4043MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  4042MB  4041MB  primary  fat32
 

~$ lsblk -l
...
sdd      8:48   1   3.8G  0 disk 
sdd1     8:49   1   3.8G  0 part /media/kk/CarMusic
 

~$ sudo mkfs.fat /dev/sdd1
mkfs.fat 4.2 (2021-01-31)
mkfs.fat: /dev/sdd1 contains a mounted filesystem.


~$ lsblk -l
...
sdd      8:48   1   3.8G  0 disk 
sdd1     8:49   1   3.8G  0 part /media/kk/CarMusic


~$ sudo mount /dev/sdd1 /mnt/disk01

~$ df -Th /mnt/disk01
檔案系統       類型  容量  已用  可用 已用% 掛載點
/dev/sdd1      vfat  3.8G   12M  3.8G    1% /mnt/disk01
 

 

~$ rsync -avh --progress /mnt/disk02/New/kkMusic_202507/2025/ /mnt/disk01/2025/
sending incremental file list
created directory /mnt/disk01/2025
./
 

 

----------------------------------------------------------------------------
複製大量資料資料夾
$ rsync -avh --progress kkMusic_202008/ new02/kkMusic-02
$ cd new02/
$ ls -al
總用量 148
drwxrwxr-x 4 kk   kk    4096  7月 22 15:14 .
drwxrwxrwx 8 root root  4096  7月 22 15:04 ..
drwxr-xr-x 3 kk   kk   73728  7月 17 15:34 kkMusic-02


----------------------------------------------------------------------------
刪除大量資料資料夾
$ ls -al kkMusic-02/
總用量 3855908
drwxr-xr-x 3 kk kk    73728  7月 17 15:34  .
drwxrwxr-x 4 kk kk     4096  7月 22 15:14  ..
drwxr-xr-x 2 kk kk    36864  7月 17 15:35  0919
$ rm -r kkMusic-02/0919/


----------------------------------------------------------------------------
刪除大量資料中*.jpg
$ rm *.jpg
 

----------------------------------------------------------------------------
大量資料中檔名含有空白的部份刪除
$ ls
'0_Piano Relajante Music.mp3'
...

 $ for f in *; do mv "$f" $(echo "$f" | tr -d ' '); done
$ ls
 0_PianoRelajanteMusic.mp3
...


----------------------------------------------------------------------------
ubuntu刪除大量檔案的檔案名稱中的"("和")"
$ ls
...
'LETITBE-(BEATLES).MP3'
... 

$ find . -name '*[()]*' -exec bash -c 'mv "$0" "${0//[()]/}"' {} \;
$ ls
...
LETITBE-BEATLES.MP3
...

 

----------------------------------------------------------------------------
ubuntu刪除大量檔案的檔案名稱中的"'"
$ ls
...
"月光女神-HEDOESN'TSEEME.MP3"

$ for f in *"'"*; do mv -- "$f" "${f//\'/}"; done
$ ls
...
月光女神-HEDOESNTSEEME.MP3


----------------------------------------------------------------------------
先備份

$ mkdir -p kkMusic-bk

 $ ls -l
總用量 72
drwxrwxr-x 2 kk kk  4096  7月 23 11:52 kkMusic-bk
drwxr-xr-x 2 kk kk 69632  7月 22 17:13 kkMusic-02

$ rsync -avh --progress kkMusic-02/ kkMusic-bk/

 

----------------------------------------------------------------------------
ubuntu 大量檔案,檔名中有"&"更改為"+"

$ cd kkMusic-02
$ ls
...

'李宗盛&林憶蓮_當愛已成往事.mp3'

$ find . -type f -name "*&*" | while read -r file; do
  newname=$(echo "$file" | sed 's/&/+/g')
  mv "$file" "$newname"

$ ls
李宗盛+林憶蓮_當愛已成往事.mp3
 

 

----------------------------------------------------------------------------
ubuntu大量檔案,檔案名稱副檔名"*.MP3"或"*.Mp3"或"*.mP3"都改成"*.mp3" 

$ ls
...
月光女神-AWHITERSHADEOFPALE.MP3 

 $ for file in *.[mM][pP]3; do     mv "$file" "${file%.*}.mp3"; done

$ ls
...
月光女神-AWHITERSHADEOFPALE.mp3
 

 

 ----------------------------------------------------------------------------
在 Ubuntu 中批量將檔案名稱中第一個出現的 "_" 改為 "-"

$ for file in *; do
  newname=$(echo "$file" | sed 's/_/-/')
  if [ "$newname" != "$file" ]; then
    mv -- "$file" "$newname"
  fi
done
  

$ ls
...
張信哲-弦歌有你_1_01愛如潮水.mp3


 ----------------------------------------------------------------------------
ubuntu 檔案名稱中前2個是英文字母,在原檔名前加上 "Eng-"

 $ ls
...
Adele-Hello.mp3

$ for file in [a-zA-Z][a-zA-Z]*; do
    if [[ -f "$file" ]]; then
        mv "$file" "Eng-$file"
    fi
done


$ ls
Eng-Adele-Hello.mp3
 

 

  ----------------------------------------------------------------------------
ubuntu系統如何將大量mp3檔中,權限設置不是"-rw-rw-r--"改成"-rw-rw-r--"

 

$ find -type f -name "*.mp3" ! -perm 664 -exec chmod 664 {} \;


$ ls -al
總用量 4488232
...
-rw-rw-r-- 1 kk kk   9663264  7月 17 12:29 Eng-Adele-Hello.mp3
 

 

 

 

  ----------------------------------------------------------------------------
ubntu 大量MP3檔案中,以檔名前2個字為篩選條件,相同者是同一個群集,如何在相同群集前加上3碼的編號。譬如:001_伍佰-你是我的花朵.mp3,001_伍佰-夢醒時分.mp3.......002_信樂團-OneNightIn北京.mp3.....003_光頭華夏-无期.mp3...。也就是不同群集有不同編號。

$ vi rename_clusters.sh
 #!/bin/bash

declare -A cluster_numbers
counter=1

# 處理所有大小寫變化的MP3文件
for file in *.[mM][pP]3; do
    # 統一轉換為小寫比較,並取前2個字元
    lower_file=$(echo "$file" | tr '[:upper:]' '[:lower:]')
    cluster_key=${lower_file:0:2}
    
    if [[ -z "${cluster_numbers[$cluster_key]}" ]]; then
        cluster_numbers[$cluster_key]=$(printf "%03d" $counter)
        ((counter++))
    fi
    
    cluster_number=${cluster_numbers[$cluster_key]}
    
    # 檢查是否已經有編號前綴
    if [[ "$file" != "${cluster_number}_"* ]]; then
        echo "重命名: $file → ${cluster_number}_$file"
        mv -- "$file" "${cluster_number}_$file"
    fi
done

echo "處理完成。"

 

 $ ls -l rename_clusters.sh 
-rw-rw-r-- 1 kk kk 894  7月 23 15:19 rename_clusters.sh


$ chmod +x rename_clusters.sh
$ ls -l rename_clusters.sh 
-rwxrwxr-x 1 kk kk 894  7月 23 15:19 rename_clusters.sh

 $ ls
Eng-Adele-Hello.mp3
...

$ ./rename_clusters.sh

$ ls
001_Eng-Adele-Hello.mp3
...



----------------------------------------------------------------------------
大量更改MP3檔的屬性的Title跟檔名一樣

$ for file in *.mp3; do
  title="${file%.mp3}"  # 移除.mp3扩展名
  id3v2 -t "$title" "$file"
done
 



 

----------------------------------------------------------------------------
 如何將磁碟內所有目錄及檔案複製到另一磁碟內的資料夾bk內?

~$ mkdir -p /mnt/disk01/spusb

~$ rsync -avh --progress /mnt/disk02/ /mnt/disk01/spusb/

~$ find /mnt/disk02 | wc -l
476

~$ find /mnt/disk01/spusb | wc -l
476


----------------------------------------------------------------------------
解壓縮到另一資料夾

$ unzip ./LocalKingMap_20250720_3D.zip -d kkLocal

 

 

----------------------------------------------------------------------------
USB 隨身碟分割區改成GPT

 ~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdd:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:loop
磁碟旗標:

編號  起點   終點    大小    檔案系統  旗標
 1    0.00B  2022MB  2022MB  fat16


~$ sudo blkid /dev/sdd
/dev/sdd: SEC_TYPE="msdos" UUID="D6E0-DACF" BLOCK_SIZE="512" TYPE="vfat"

 ~$ sudo gdisk /dev/sdd
[sudo] kk 的密碼: 
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: MBR only
  BSD: not present
  APM: not present
  GPT: not present
....

Command (? for help): ?
b    back up GPT data to a file
c    change a partition's name
d    delete a partition
i    show detailed information on a partition
l    list known partition types
n    add a new partition
o    create a new empty GUID partition table (GPT)
p    print the partition table
q    quit without saving changes
r    recovery and transformation options (experts only)
s    sort partitions
t    change a partition's type code
v    verify disk
w    write table to disk and exit
x    extra functionality (experts only)
?    print this menu


Command (? for help): o
This option deletes all partitions and creates a new protective MBR.
Proceed? (Y/N): y

Command (? for help): p
Disk /dev/sdd: 3948544 sectors, 1.9 GiB
Model:                 
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): D87E3941-C7FB-40DC-987F-379373674D17
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 3948510
Partitions will be aligned on 2048-sector boundaries
Total free space is 3948477 sectors (1.9 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdd.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.


~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdd:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點  終點  大小  檔案系統  名稱  旗標

~$ sudo blkid /dev/sdd
/dev/sdd: SEC_TYPE="msdos" UUID="D6E0-DACF" BLOCK_SIZE="512" TYPE="vfat" PTUUID="d87e3941-c7fb-40dc-987f-379373674d17" PTTYPE="gpt"


----------------------------------------------------------------------------
建立分割區大小

~$ sudo gdisk /dev/sdd
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-3948510, default = 2048) or {+-}size{KMGTP}: 
Last sector (2048-3948510, default = 3946495) or {+-}size{KMGTP}: 
Current type is 8300 (Linux filesystem)
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): p
Disk /dev/sdd: 3948544 sectors, 1.9 GiB
Model:                 
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): D87E3941-C7FB-40DC-987F-379373674D17
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 3948510
Partitions will be aligned on 2048-sector boundaries
Total free space is 4029 sectors (2.0 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         3946495   1.9 GiB     8300  Linux filesystem

 

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdd.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.


~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdd:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  2021MB  2020MB            Linux filesystem

 ~$ sudo blkid /dev/sdd
/dev/sdd: SEC_TYPE="msdos" UUID="D6E0-DACF" BLOCK_SIZE="512" TYPE="vfat" PTUUID="d87e3941-c7fb-40dc-987f-379373674d17" PTTYPE="gpt"

 

 

 

----------------------------------------------------------------------------
格式化分割區

~$ lsblk -l
...
sdd      8:48   1   1.9G  0 disk 
sdd1     8:49   1   1.9G  0 part 

 

~$ sudo mkfs.vfat -F 32 -n "USB_DATA" /dev/sdd1
mkfs.fat 4.2 (2021-01-31)

 

~$ lsblk -l
...
sdd      8:48   1   1.9G  0 disk 
sdd1     8:49   1   1.9G  0 part /media/kk/USB_DATA

~$ sudo parted  -l 
型號:Ut165  (scsi)
磁碟 /dev/sdd:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  2021MB  2020MB  fat32     Linux filesystem

~$ sudo blkid /dev/sdd1
/dev/sdd1: LABEL_FATBOOT="USB_DATA" LABEL="USB_DATA" UUID="2532-F879" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="Linux filesystem" PARTUUID="5558af6f-be5f-4f58-baa0-a2fd6005a686" 

 

 

 

 

 

 




----------------------------------------------------------------------------
製作出linux與windows都能讀取資料的USB隨身碟

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdd:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  4009MB  4008MB            Linux filesystem

 

~$ lsblk -l
...
sdd      8:48   1   3.7G  0 disk 
sdd1     8:49   1   3.7G  0 part /media/kk/C852-54B5

 

~$ sudo umount /dev/sdd1
 

~$ sudo mkfs.vfat -F 32 -n "USB_DATA" /dev/sdd1
mkfs.fat 4.2 (2021-01-31)

 

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdd:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  4009MB  4008MB  fat32     Linux filesystem


~$ lsblk -l
...
sdd      8:48   1   3.7G  0 disk 
sdd1     8:49   1   3.7G  0 part 


~$ sudo blkid /dev/sdd1
/dev/sdd1: LABEL_FATBOOT="USB_DATA" LABEL="USB_DATA" UUID="DC64-50B6" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="Linux filesystem" PARTUUID="82ae7ab9-c4ca-4d2b-997d-ce7cca2e27d7"


 


----------------------------------------------------------------------------
USB隨身碟,GPD轉MBR

 ~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdc:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點  終點  大小  檔案系統  名稱  旗標


#完全清除磁碟的分區表
~$ sudo sgdisk -Z /dev/sdc

~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdc:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:unknown
磁碟旗標:
 

 

~$ sudo fdisk /dev/sdc

Welcome to fdisk (util-linux 2.39.3).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.


Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0xfc3f7af9.

命令 (m 以獲得說明): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty MBR (DOS) partition table
   s   create a new empty Sun partition table

命令 (m 以獲得說明): o
Created a new DOS (MBR) disklabel with disk identifier 0xba64ff3e.

命令 (m 以獲得說明): w
The partition table has been altered.
Syncing disks.

~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdc:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點  終點  大小  類型  檔案系統  旗標
 

 

----------------------------------------------------------------------------
建立新分割區

 ~$ sudo fdisk /dev/sdc
...
命令 (m 以獲得說明): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
分割區編號 (1-4, default 1): 
First sector (2048-3948543, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3948543, default 3948543): 

Created a new partition 1 of type 'Linux' and of size 1.9 GiB.

 命令 (m 以獲得說明): t
Selected partition 1
Hex code or alias (type L to list all): L

00 空               27 Hidden NTFS Win  82 Linux 交換區/ S  c1 DRDOS/sec (FAT-
01 FAT12            39 Plan 9           83 Linux            c4 DRDOS/sec (FAT-
02 XENIX root       3c PartitionMagic   84 OS/2 hidden or   c6 DRDOS/sec (FAT-
03 XENIX usr        40 Venix 80286      85 Linux 擴展       c7 Syrinx         
04 FAT16 <32M       41 PPC PReP 開機    86 NTFS 卷冊集      da Non-FS 資料    
05 延伸             42 SFS              87 NTFS 卷冊集      db CP/M / CTOS /… 
06 FAT16            4d QNX4.x           88 Linux 純文字     de Dell 公用程式  
07 HPFS/NTFS/exFAT  4e QNX4.x 第二部分  8e Linux LVM        df BootIt         
08 AIX              4f QNX4.x 第三部分  93 Amoeba           e1 DOS 存取       
09 AIX 可開機       50 OnTrack DM       94 Amoeba BBT       e3 DOS R/O        
0a OS/2 開機管理員  51 OnTrack DM6 Aux  9f BSD/OS           e4 SpeedStor      
0b W95 FAT32        52 CP/M             a0 IBM Thinkpad hi  ea Linux extended 
0c W95 FAT32 (LBA)  53 OnTrack DM6 Aux  a5 FreeBSD          eb BeOS fs        
0e W95 FAT16 (LBA)  54 OnTrackDM6       a6 OpenBSD          ee GPT            
0f W95 Ext'd (LBA)  55 EZ-Drive         a7 NeXTSTEP         ef EFI (FAT-12/16/
10 OPUS             56 Golden Bow       a8 Darwin UFS       f0 Linux/PA-RISC  
11 隱藏 FAT12       5c Priam Edisk      a9 NetBSD           f1 SpeedStor      
12 Compaq 診斷      61 SpeedStor        ab Darwin 開機      f4 SpeedStor      
14 隱藏 FAT16 <32M  63 GNU HURD 或 Sys  af HFS / HFS+       f2 DOS 次級       
16 隱藏 FAT16       64 Novell Netware   b7 BSDI fs          f8 EBBR protective
17 隱藏 HPFS/NTFS   65 Novell Netware   b8 BSDI 交換區      fb VMware VMFS    
18 AST 智慧休眠     70 DiskSecure 多種  bb 開機精靈隱藏     fc VMware VMKCORE 
1b 隱藏 W95 FAT32   75 PC/IX            bc Acronis FAT32 L  fd Linux raid 自動
1c 隱藏 W95 FAT32   80 舊版 Minix       be Solaris 開機     fe LANstep        
1e 隱藏 W95 FAT16   81 Minix / 舊版 Li  bf Solaris          ff BBT            
24 NEC DOS        

Aliases:
   linux          - 83
   swap           - 82
   extended       - 05
   uefi           - EF
   raid           - FD
   lvm            - 8E
   linuxex        - 85


Hex code or alias (type L to list all): 0c
Changed type of partition 'Empty' to 'W95 FAT32 (LBA)'.

命令 (m 以獲得說明): w
The partition table has been altered.
Syncing disks.


~$ sudo parted -l
...
 型號:Ut165  (scsi)
磁碟 /dev/sdc:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  2022MB  2021MB  primary            lba


~$ lsblk -l
...
sdc      8:32   1   1.9G  0 disk /media/kk/D6E0-DACF
sdc1     8:33   1   1.9G  0 part 

 

----------------------------------------------------------------------------
格式化成FAT32

 ~$ lsblk -l
...
 sdc      8:32   1   1.9G  0 disk /media/kk/D6E0-DACF
sdc1     8:33   1   1.9G  0 part 


~$ sudo umount /dev/sdc
~$ lsblk -l
...
sdc      8:32   1   1.9G  0 disk 
sdc1     8:33   1   1.9G  0 part 
 

~$ sudo mkfs.vfat -F 32 -n "USB_DATA" /dev/sdc1
mkfs.fat 4.2 (2021-01-31)

 

~$ sudo parted -l
...
型號:Ut165  (scsi)
磁碟 /dev/sdc:2022MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  2022MB  2021MB  primary  fat32     lba


~$ sudo blkid /dev/sdc1
/dev/sdc1: LABEL_FATBOOT="USB_DATA" LABEL="USB_DATA" UUID="112B-813A" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="ba64ff3e-01"
 

 

----------------------------------------------------------------------------
使用者家目錄以英文顯示

 ~$ LC_ALL=C xdg-user-dirs-gtk-update
Moving DESKTOP directory from 桌面 to Desktop
Moving DOWNLOAD directory from 下載 to Downloads
Moving TEMPLATES directory from 模本 to Templates
Moving PUBLICSHARE directory from 公共 to Public
Moving DOCUMENTS directory from 文件 to Documents
Moving MUSIC directory from 音樂 to Music
Moving PICTURES directory from 圖片 to Pictures
Moving VIDEOS directory from 影片 to Videos

~$ ls
 Desktop     Public      Documents   Templates   Downloads   Videos    Music     Pictures   

 

---------------------------------------------------------------------------- 
將掛載的磁碟內資料夾,再掛載綁定到使用者家目錄

~$ sudo mount /dev/sdb1 /mnt/disk01

~$ sudo mount --bind /mnt/disk01/MyDownLoad/ ./下載 

~$ ls 下載
張宇-走樣.mp4

~$ ls /mnt/disk01/MyDownLoad/
張宇-走樣.mp4
 

 

---------------------------------------------------------------------------- 
永久掛載

 ~$ sudo cp  /etc/fstab /etc/fstab.bk
~$ ls -l /etc/fstab*
-rw-r--r-- 1 root root 585  7月 23 10:53 /etc/fstab
-rw-r--r-- 1 root root 585  8月  4 09:40 /etc/fstab.bk
 

~$ sudo blkid
...
/dev/sdb1: UUID="9e7b9707-1373-4e9f-947e-b45fe49fdfa0" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="434d78b1-d584-43fc-be07-07ea365e8a87"


~$ sudo nano /etc/fstab
...

UUID=9e7b9707-1373-4e9f-947e-b45fe49fdfa0  /mnt/disk01  ext4  defaults  0  0

/mnt/disk01/MyDownLoad/ /home/kk/下載 none bind 0 0

#最底下加上這2行

 

 

 

 

 


 

 

 

---------------------------------------------------------------------------- 
USB隨身碟GPD轉MBR ,使用gdisk 

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdc:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:gpt
磁碟旗標:

編號  起點    終點    大小    檔案系統  名稱              旗標
 1    1049kB  4009MB  4008MB  fat32     Linux filesystem
 

$ sudo gdisk /dev/sdc
GPT fdisk (gdisk) version 1.0.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): r
 

Recovery/transformation command (? for help): g

MBR command (? for help): w

Converted 1 partitions. Finalize and exit? (Y/N): y
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.


~$ sudo parted -l 
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdc:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  4009MB  4008MB  primary  fat32

 

---------------------------------------------------------------------------- 
USB隨身碟GPD轉MBR ,使用fdisk

~$ sudo fdisk /dev/sdc
...
命令 (m 以獲得說明): o
...
命令 (m 以獲得說明): w
...

 

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdc:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點  終點  大小  類型  檔案系統  旗標

 

 

----------------------------------------------------------------------------  
USB隨身碟GPD轉MBR後,重新建立分割區

~$ sudo fdisk /dev/sdc
...
命令 (m 以獲得說明): n
...
Created a new partition 1 of type 'Linux' and of size 3.7 GiB.
Partition #1 contains a vfat signature.

Do you want to remove the signature? [Y]es/[N]o: y
...

 
命令 (m 以獲得說明): t
Selected partition 1
Hex code or alias (type L to list all): 0c
...
命令 (m 以獲得說明): w
...

 

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdc:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  4010MB  4009MB  primary            lba
 

 

 

 

----------------------------------------------------------------------------  
USB隨身碟轉MBR、建立分割區後,進行格式化

~$ lsblk -l
...
sdc      8:32   1   3.7G  0 disk 
sdc1     8:33   1   3.7G  0 part /media/kk/USB_DATA

 ~$ sudo umount /dev/sdc1
~$ lsblk -l
...
sdc      8:32   1   3.7G  0 disk 
sdc1     8:33   1   3.7G  0 part 


~$ sudo mkfs.vfat -F 32 -n "USB_DATA" /dev/sdc1

~$ sudo parted -l
...
型號: USB FLASH DRIVE (scsi)
磁碟 /dev/sdc:4010MB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:

編號  起點    終點    大小    類型     檔案系統  旗標
 1    1049kB  4010MB  4009MB  primary  fat32     lba


 

 

---------------------------------------------------------------------------- 
查看CPU與記憶體

~$ lscpu
架構:                    x86_64
  CPU 作業模式:          32-bit, 64-bit
  Address sizes:          36 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   4
  On-line CPU(s) list:    0-3
...

 

#核心數
~$ nproc
4
 

#記憶體
~$ free -h
               total        used        free      shared  buff/cache   available
Mem:           7.5Gi       2.8Gi       2.2Gi       456Mi       3.0Gi       4.7Gi
置換:         2.0Gi          0B       2.0Gi
  

 

---------------------------------------------------------------------------- 


 

檔案與資料夾操作

 Summary Table
----------------------------------------------------------------
Delete a file: rm file                # remove files or directories
Delete an empty directory: rmdir dir            #remove empty directories
Delete a directory & contents: rm -r dir
Force delete (no prompt): rm -rf dir
Rename/move file/dir: mv old new





 

 

2024年12月27日 星期五

Python

---------------------------------dir() 

 dir()

dir(__builtins__)

dir(list)
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] 

 

---------------------------------文字轉Lst

Lst=list("ABCDEF")
Lst
['A', 'B', 'C', 'D', 'E', 'F'] 

Lst=list(dir(list))
Lst
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

Lst.index("append")
37
Lst[37:]
['append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] 

 

---------------------------------help() 

help(list.append)
Help on method_descriptor:

append(self, object, /)
    Append object to the end of the list.

Lst=[i for i in "ABCD"]
Lst
['A', 'B', 'C', 'D']

Lst.append("K")
Lst
['A', 'B', 'C', 'D', 'K']

 help(list.pop)
Help on method_descriptor:

pop(self, index=-1, /)
    Remove and return item at index (default last).

    Raises IndexError if list is empty or index is out of range.

Lst.pop()
'K'
Lst
['A', 'B', 'C', 'D']
Lst.pop(3)
'D'
Lst
['A', 'B', 'C']

 

 ---------------------------------print()format   

for i in range(1,9+1):
    for j in range(1,9+1):
        print("{0}*{1}={2:2d}".format(i,j,i*j),end=" ")
    print()

 
1*1= 1 1*2= 2 1*3= 3 1*4= 4 1*5= 5 1*6= 6 1*7= 7 1*8= 8 1*9= 9 
2*1= 2 2*2= 4 2*3= 6 2*4= 8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 
3*1= 3 3*2= 6 3*3= 9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27 
4*1= 4 4*2= 8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36 
5*1= 5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45 
6*1= 6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54 
7*1= 7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63 
8*1= 8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72 
9*1= 9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81  

2024年12月25日 星期三

Ubuntu24.04.1

  Debian packages  and dependencies

 APT (Advanced Packaging Tool)


~$ dpkg -l | grep apt

~$ sudo apt update    #更新套件資料庫內,軟體版本資訊

~$ sudo apt upgrade    #更新系統上所有已經安裝套件



終端機

ctrl+alt+T 叫出終端機
ctrl+shift+Q    關閉終端機
F11    終端機全螢幕 / 恢復
 
ctrl+shift+C   複製
ctrl+shift+V    貼上
 

$ clear    清除終端機畫面

 

 

 系統時間呈現秒數

~$ gsettings set org.gnome.desktop.interface clock-show-seconds true

 設定-->系統-->日期與時間-->秒數



安裝chrome

下載    google-chrome-stable_current_amd64.deb

~$ ls ./下載/google-chrome-stable_current_amd64.deb
./下載/google-chrome-stable_current_amd64.deb

 ~$ sudo apt install ./下載/google-chrome-stable_current_amd64.deb



標點符號    全形
 中文(新酷音)

中英文輸入切換:微軟建+空白建


ctrl+1     /    ctrl+0   叫出各種符號選單

shift+,    ,
shift+.    。
shift+?    ?  
shift+!    !
shift+:    :
shift+"    ;

shift+(  (     
shift+)     )
shift+[    『
shift+]    』
shift+z    《
shift+x    》



----------------------------------------------------------------- 開始使用 --------------------------------

查詢 Ubuntu 版本資訊

~$ uname -a
Linux kk-VMware-Virtual-Platform 6.8.0-51-generic #52-Ubuntu SMP PREEMPT_DYNAMIC Thu Dec  5 13:09:44 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux



~$ lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 24.04.1 LTS
Release:    24.04
Codename:    noble


顯示程式-->設定-->系統-->關於



查詢IP

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host noprefixroute
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:d1:a8:ef brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.142.128/24 brd 192.168.142.255 scope global dynamic noprefixroute ens33
       valid_lft 1053sec preferred_lft 1053sec
    inet6 fe80::20c:29ff:fed1:a8ef/64 scope link
       valid_lft forever preferred_lft forever
 


概覽
Windows 鍵


 
在應用程式間切換
Alt + Tab
 

 
最大 / 小 化目前視窗
Windows 鍵 + 方向鍵上 / 下


 
關閉目前視窗
Alt +F4


 
擴展目前視窗到視窗的 左 / 右 半部
Windows 鍵 + 方向鍵左 / 右



切換 工作區(系統桌面的虛擬延伸)
Ctrl + Alt + 方向鍵左 / 右



擷取螢幕畫面

PrintScr


2024年10月3日 星期四

Python 例題

 

def TowerOfHanoi(n,OriginalPillar,DestinationPillar,IntermediaryPillar):
        
    if n==1:
        print("碟 1 從柱",OriginalPillar," 到柱",DestinationPillar)        
        return
    
       
    TowerOfHanoi(n-1,OriginalPillar,IntermediaryPillar,DestinationPillar)
        
    print("碟",n,"從柱",OriginalPillar," 到柱",DestinationPillar)
    
    TowerOfHanoi(n-1,IntermediaryPillar,DestinationPillar,OriginalPillar)

        
#第n個之上(n-1),從A-->B
#第n個        ,從A-->C
#第n個之上(n-1),從B-->C

TowerOfHanoi(3,"A","C","B")
print("完成!")

------------------------------------------

 碟 1 從柱 A  到柱 C
碟 2 從柱 A  到柱 B
碟 1 從柱 C  到柱 B
碟 3 從柱 A  到柱 C
碟 1 從柱 B  到柱 A
碟 2 從柱 B  到柱 C
碟 1 從柱 A  到柱 C
完成!

 ==========================================================

參考解說

https://www.youtube.com/watch?v=oV2C9UINg_U

 

cnt=0
def HanoiTower(n,fro,mid,des):
    global cnt
    if n==1:
        #移動時才累計
        cnt+=1
        #只有一個碟A-->C        
        print("Move",cnt,"disk",n,"from",fro,"to",des)
    else:
        #第n個碟之前(n-1),所有碟A-->B
        HanoiTower(n-1,fro,des,mid)

        #移動時才累計
        cnt+=1
        #第n個碟(n),A-->C
        print("Move",cnt,"disk",n,"from",fro,"to",des)
        
        #第n個碟之前(n-1),所有碟B-->C
        HanoiTower(n-1,mid,fro,des)

HanoiTower(3,"A","B","C")

------------------------------------------

Move 1 disk 1 from A to C
Move 2 disk 2 from A to B
Move 3 disk 1 from C to B
Move 4 disk 3 from A to C
Move 5 disk 1 from B to A
Move 6 disk 2 from B to C
Move 7 disk 1 from A to C
 

========================================================== 

def prime_factorization(n):
    if n==1:
        return[]
    for f in range(2,n+1):
        if n%f==0:
            return [f]+prime_factorization(n//f)

print(prime_factorization(3080))        

------------------------------------------

[2, 2, 2, 5, 7, 11]

 

==========================================================

 

------------------------------------------

==========================================================

 

------------------------------------------

==========================================================

 

------------------------------------------

==========================================================

 

 

 

2024年5月3日 星期五

RockyLinux 9.3 練習(四)

 

檔案系統權限
-----------------------------------------------------------------------------------------

Owner
Group
Other  

r    100    4
w   010    2
x    001    1

每一個檔案均有一個 Owner,僅有 root 與 owner 可以更改檔案存取保護模式 --> chmod
                                                只有 root 可以更改檔案的 Owner 與 Group        -->chown

[kk@Rocky ~]$ ls -l /etc/shadow
----------. 1 root root 730  4月 22 15:44 /etc/shadow

// ---------- 全關,只有 root 可以改

 

[kk@Rocky ~]$ ls -l /usr/bin/passwd
-rwsr-xr-x. 1 root root 32656  5月 15  2022 /usr/bin/passwd

 密碼在系統檔中,本應只有 root 可以改
為了方便使用者可以自行設定密碼,所以改由使用者執行
即暫時將使用者身分提升至 root,完成工作後再自動降回使用者身分
但若故意將密碼設的太長造成溢位,無法完成設定密碼工作,就會一直在 root 身分

 

 

檔案系統權限
-----------------------------------------------------------------------------------------

 

檔案系統權限
-----------------------------------------------------------------------------------------

 

 

檔案系統權限
-----------------------------------------------------------------------------------------

 

 

檔案系統權限
-----------------------------------------------------------------------------------------

 

 

檔案系統權限
-----------------------------------------------------------------------------------------