Useful Commands: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
https://www.diskpart.com/articles/delete-hidden-partition-on-usb-drive-7201.html
= File System =
= File System =
{| class="wikitable"
{| class="wikitable"
Line 4: Line 6:
|-
|-
| (查) 變彩色,加上後綴,目錄以 / 結尾,連結以 @ 結尾
| (查) 變彩色,加上後綴,目錄以 / 結尾,連結以 @ 結尾
| <source lang="bash">ls -FG</source>
| <syntaxhighlight lang="bash">ls -FG</syntaxhighlight>
|-
|-
| (查) 在目前的目錄下搜尋所有隱藏檔,'''注意要有單引號'''
| (查) 在目前的目錄下搜尋所有隱藏檔,'''注意要有單引號'''
| <source lang="bash">find . -name '.*'</source>
| <syntaxhighlight lang="bash">find . -name '.*'</syntaxhighlight>
|-
|-
| delete dist directory recursively except README.md and itself.
| delete dist directory recursively except README.md and itself.
| <source lang="bash">find dist -not -path dist -not -path dist/README.md -delete</source>
| <syntaxhighlight lang="bash">find dist -not -path dist -not -path dist/README.md -delete</syntaxhighlight>
|-
|-
| 刪除檔名 - 或是 -- 開頭的檔案 |
| 刪除檔名 - 或是 -- 開頭的檔案
| <source lang="bash">rm -- -X --exclude-from</source>
| <syntaxhighlight lang="bash">rm -- -X --exclude-from</syntaxhighlight>
|-
|-
| 變更檔案時間為<br/>2013 年 9 月 1 號 00:00:00
| 變更檔案時間為<br/>2013 年 9 月 1 號 00:00:00
| <source lang="bash">touch -t 201309010000 檔案名稱</source>
| <syntaxhighlight lang="bash">touch -t 201309010000 檔案名稱</syntaxhighlight>
|-
|-
| Linux 環境產生 Ramdisk (無法指定大小)
| Linux 環境產生 Ramdisk (無法指定大小)
| <source lang="bash">mount -t ramfs ramfs /usr/local/ramdisk</source>
| <syntaxhighlight lang="bash">mount -t ramfs ramfs /usr/local/ramdisk</syntaxhighlight>
|-
|-
| Linux/BSD 環境產生 Ramdisk (配置 128M)
| Linux/BSD 環境產生 Ramdisk (配置 128M)
| <source lang="bash">mount -t tmpfs -o size=128m tmpfs /usr/local/ramdisk</source>
| <syntaxhighlight lang="bash">mount -t tmpfs -o size=128m tmpfs /usr/local/ramdisk</syntaxhighlight>
|-
| Test I/O performance of 1G write with 4K block
| <syntaxhighlight lang="bash">dd if=/dev/zero of=100k.bin bs=4k count=262144</syntaxhighlight>
|-
|-
| 產生 100K 的檔案
| 產生 100K 的檔案
| <source lang="bash">dd if=/dev/zero of=100k.bin bs=1k count=100</source>
| <syntaxhighlight lang="bash">dd if=/dev/zero of=100k.bin bs=1k count=100</syntaxhighlight>
|-
|-
| 產生 10M 的檔案<br/>空間將會塞爆時,不會有警告訊息
| 產生 10M 的檔案<br/>空間將會塞爆時,不會有警告訊息
| <source lang="bash">dd if=/dev/zero of=10m.bin bs=1m count=10</source>
| <syntaxhighlight lang="bash">dd if=/dev/zero of=10m.bin bs=1m count=10</syntaxhighlight>
|-
|-
| 故意消耗系統記憶體 (RAM+SWAP)
| 故意消耗系統記憶體 (RAM+SWAP)
| <source lang="bash">
| <syntaxhighlight lang="bash">
mkdir /usr/local/ramdisk
mkdir /usr/local/ramdisk
mount -t tmpfs -o size=2G tmpfs /usr/local/ramdisk
mount -t tmpfs -o size=2G tmpfs /usr/local/ramdisk
dd if=/dev/zero of=/usr/local/ramdisk/fill.bin bs=1m count=2048
dd if=/dev/zero of=/usr/local/ramdisk/fill.bin bs=1m count=2048
</source>
</syntaxhighlight>
|}
|}


Line 43: Line 48:
|-
|-
| Samba (Linux) ||
| Samba (Linux) ||
<source lang="bash">
<syntaxhighlight lang="bash">
sudo mount -t smbfs {remote} {local} -o \
sudo mount -t smbfs {remote} {local} -o \
   iocharset=utf8, \
   iocharset=utf8, \
Line 49: Line 54:
   uid=`id -u {local user}`, \
   uid=`id -u {local user}`, \
   gid=`id -u {local group}`
   gid=`id -u {local group}`
</source>
</syntaxhighlight>
|-
|-
| Samba (MacOS) ||
| Samba (MacOS) ||
<source lang="bash">
<syntaxhighlight lang="bash">
mount_smbfs //'{group};{user}':{password}@{remote}/{shared dir} {local dir}
mount_smbfs //'{group};{user}':{password}@{remote}/{shared dir} {local dir}
smbutil view //Guest@192.168.91.65
smbutil view //Guest@192.168.91.65
smbutil view //'WORKGROUP;Administrator':12345@192.168.1.2 # for Windows 2K3
smbutil view //'WORKGROUP;Administrator':12345@192.168.1.2 # for Windows 2K3
</source>
</syntaxhighlight>
|-
|-
| Samba (FreeBSD) ||
| Samba (FreeBSD) ||
<source lang="bash">
<syntaxhighlight lang="bash">
mount -t smbfs -o '-N' //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples # Using ~/.nsmbrc
mount -t smbfs -o '-N' //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples # Using ~/.nsmbrc
mount_smbfs -I 192.168.91.65 //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples
mount_smbfs -I 192.168.91.65 //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples
smbutil view -I 192.168.91.65 //raymondwu@RaymondWu-PC
smbutil view -I 192.168.91.65 //raymondwu@RaymondWu-PC
</source>
</syntaxhighlight>
|}
|}


Line 71: Line 76:
|-
|-
| zip ||
| zip ||
<source lang="bash">
<syntaxhighlight lang="bash">
zip -r front-end.zip index.html static/
zip -r front-end.zip index.html static/
unzip -l front-end.zip
unzip -l front-end.zip
unzip -p front-end.zip index.html
unzip -p front-end.zip index.html
</source>
</syntaxhighlight>
|-
|-
| tar ||
| tar ||
<source lang="bash">
<syntaxhighlight lang="bash">
tar --exclude=".*" -zcvf ~/solr-4.3.0.tgz solr-4.3.0
tar --exclude=".*" -zcvf ~/solr-4.3.0.tgz solr-4.3.0
tar -C /usr/local --exclude '.*' -zcvf tika-1.4-pxx.tgz tika
tar -C /usr/local --exclude '.*' -zcvf tika-1.4-pxx.tgz tika
</source>
</syntaxhighlight>
|-
|-
| gzip ||
| gzip ||
<source lang="bash">
<syntaxhighlight lang="bash">
gzip -k taiwan-taco.map
gzip -k taiwan-taco.map
gzip -l taiwan-taco.map.gz  
gzip -l taiwan-taco.map.gz  
   compressed uncompressed  ratio uncompressed_name
   compressed uncompressed  ratio uncompressed_name
     25400590    38204880  33.5% taiwan-taco.map
     25400590    38204880  33.5% taiwan-taco.map
</source>
</syntaxhighlight>
|-
|-
| xz ||
| xz ||
<source lang="bash">
<syntaxhighlight lang="bash">
xz -zk hd-20190227.csv
xz -zk hd-20190227.csv
xz -vt hd-20190227.csv.xz  
xz -vt hd-20190227.csv.xz  
hd-20190227.csv.xz (1/1)
hd-20190227.csv.xz (1/1)
   100 %    344.1 KiB / 1,458.1 KiB = 0.236
   100 %    344.1 KiB / 1,458.1 KiB = 0.236
</source>
</syntaxhighlight>
|-
|-
| dd ||
| dd ||
<source lang="bash">
<syntaxhighlight lang="bash">
# Make an ISO image.
# Make an ISO image.
df -h
df -h
Line 108: Line 113:
Win7.iso: ISO 9660 CD-ROM filesystem data 'GRMCULFRER_TW_DVD              ' (bootable)
Win7.iso: ISO 9660 CD-ROM filesystem data 'GRMCULFRER_TW_DVD              ' (bootable)
kill -USR1 {pid of dd}
kill -USR1 {pid of dd}
</source>
</syntaxhighlight>
|}
|}


= Other Topics =
= Other Topics =
* [[Useful Commands/Hardware|Hardware]]
* [[Useful Commands/File Processing|File Processing]]
* [[Useful Commands/File Processing|File Processing]]
* [[Useful Commands/Text Processing|Text Processing]]
* [[Useful Commands/Text Processing|Text Processing]]

Latest revision as of 20:13, 3 April 2025

https://www.diskpart.com/articles/delete-hidden-partition-on-usb-drive-7201.html

File System

情境 指令
(查) 變彩色,加上後綴,目錄以 / 結尾,連結以 @ 結尾
ls -FG
(查) 在目前的目錄下搜尋所有隱藏檔,注意要有單引號
find . -name '.*'
delete dist directory recursively except README.md and itself.
find dist -not -path dist -not -path dist/README.md -delete
刪除檔名 - 或是 -- 開頭的檔案
rm -- -X --exclude-from
變更檔案時間為
2013 年 9 月 1 號 00:00:00
touch -t 201309010000 檔案名稱
Linux 環境產生 Ramdisk (無法指定大小)
mount -t ramfs ramfs /usr/local/ramdisk
Linux/BSD 環境產生 Ramdisk (配置 128M)
mount -t tmpfs -o size=128m tmpfs /usr/local/ramdisk
Test I/O performance of 1G write with 4K block
dd if=/dev/zero of=100k.bin bs=4k count=262144
產生 100K 的檔案
dd if=/dev/zero of=100k.bin bs=1k count=100
產生 10M 的檔案
空間將會塞爆時,不會有警告訊息
dd if=/dev/zero of=10m.bin bs=1m count=10
故意消耗系統記憶體 (RAM+SWAP)
mkdir /usr/local/ramdisk
mount -t tmpfs -o size=2G tmpfs /usr/local/ramdisk
dd if=/dev/zero of=/usr/local/ramdisk/fill.bin bs=1m count=2048

Remote File System

Tool Example
Samba (Linux)
sudo mount -t smbfs {remote} {local} -o \
   iocharset=utf8, \
   user={user}%{password}, \
   uid=`id -u {local user}`, \
   gid=`id -u {local group}`
Samba (MacOS)
mount_smbfs //'{group};{user}':{password}@{remote}/{shared dir} {local dir}
smbutil view //Guest@192.168.91.65
smbutil view //'WORKGROUP;Administrator':12345@192.168.1.2 # for Windows 2K3
Samba (FreeBSD)
mount -t smbfs -o '-N' //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples # Using ~/.nsmbrc
mount_smbfs -I 192.168.91.65 //raymondwu@RaymondWu-PC/TikaSamples /var/tika/samples
smbutil view -I 192.168.91.65 //raymondwu@RaymondWu-PC

Compression

Tool Example
zip
zip -r front-end.zip index.html static/
unzip -l front-end.zip
unzip -p front-end.zip index.html
tar
tar --exclude=".*" -zcvf ~/solr-4.3.0.tgz solr-4.3.0
tar -C /usr/local --exclude '.*' -zcvf tika-1.4-pxx.tgz tika
gzip
gzip -k taiwan-taco.map
gzip -l taiwan-taco.map.gz 
  compressed uncompressed  ratio uncompressed_name
    25400590     38204880  33.5% taiwan-taco.map
xz
xz -zk hd-20190227.csv
xz -vt hd-20190227.csv.xz 
hd-20190227.csv.xz (1/1)
  100 %     344.1 KiB / 1,458.1 KiB = 0.236
dd
# Make an ISO image.
df -h
umount /dev/disk2
dd if=/dev/disk2 of=Win7.iso bs=2048 count=1000
file Win7.iso
Win7.iso: ISO 9660 CD-ROM filesystem data 'GRMCULFRER_TW_DVD              ' (bootable)
kill -USR1 {pid of dd}

Other Topics