harddisk容量少了很多 [論壇 - 新手村]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊

(1) 2 »


harddisk容量少了很多
會員三級
註冊日期:
2009/3/12 22:37
所屬群組:
已註冊使用者
等級: 13
HP : 0 / 323
MP : 74 / 13268
EXP: 94
離線
有什麼方法清除沒有用的檔案

2017/11/24 7:31
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2008/11/21 9:18
所屬群組:
已註冊使用者
等級: 23
HP : 0 / 571
MP : 229 / 23933
EXP: 86
離線
試試 BleachBit
類似 CCleaner 清掉不少東西

2017/11/27 20:41
應用擴展 工具箱
回覆: harddisk容量少了很多
會員二級
註冊日期:
2016/2/24 19:05
所屬群組:
已註冊使用者
等級: 5
HP : 0 / 114
MP : 15 / 2374
EXP: 59
離線
可以用 Baobab 軟體查看哪些檔案佔用磁碟空間
可以用 Deborphan 軟體查看有哪些不再用到的軟體包
可以查看所有標示為手動安裝的軟體包看看是不是有自己不再用到的軟體(雖然我不知道怎麼看就是了)

2017/11/27 23:05
應用擴展 工具箱
回覆: harddisk容量少了很多
會員三級
註冊日期:
2016/4/18 12:29
所屬群組:
已註冊使用者
等級: 9
HP : 0 / 221
MP : 39 / 4474
EXP: 84
離線
ubuntu有內建Disk Analyzer可以查看
xubuntu似乎沒有?(gnome only?)

指令部分可以使用
df -h
du -h -d1

如果是套件查詢可用
dpkg -l


另借串問一下
1.我使用了 du -h -d1後,顯示我的 /var、/usr很大,/var (812M )、 /usr (4.2G),一直往下看之後發現
/var裡面的lib很大,/usr裡面有kernel source code(還有兩個Orz),想請問怎麼判斷那些檔案可以用rm -rf 刪除,而不會影響系統?

2.dpkg -l 查看,最大宗為 linux-image、libXXX開頭(有一些Lib我沒有印像有裝過? libsqlite3-0、libqt5dbus5...???)
問題也是同上,我要如何確定移除哪些lib而不會影響系統

3.以libroffice、vim為例,使用apt-get autoremove + tab會看到
vim vim-common vim-runtime vim-tiny

....libreoffice-core libreoffice-gtk libreoffice-help-en-us libreoffice-math libreoffice-style-elementary libreoffice-style-galaxy libreoffice-writer libreoffice-base-core libreoffice-calc libreoffice-common...


以vim來說,我平常都是用vim這個指令,那是不是代表vim-common 、vim-runtime、vim-tiny都可以刪除? (vim-runtime?,那平常打的vim不是runtim嗎?)

我平常不使用libroffice,我要如何一次移除這整個套件?

謝謝各位的撥冗觀看

2017/12/14 11:32
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
ubuntu_net2016 寫到:
ubuntu有內建Disk Analyzer可以查看
xubuntu似乎沒有?(gnome only?)

指令部分可以使用
df -h
du -h -d1

如果是套件查詢可用
dpkg -l


另借串問一下
1.我使用了 du -h -d1後,顯示我的 /var、/usr很大,/var (812M )、 /usr (4.2G),一直往下看之後發現
/var裡面的lib很大,/usr裡面有kernel source code(還有兩個Orz),想請問怎麼判斷那些檔案可以用rm -rf 刪除,而不會影響系統?

2.dpkg -l 查看,最大宗為 linux-image、libXXX開頭(有一些Lib我沒有印像有裝過? libsqlite3-0、libqt5dbus5...???)
問題也是同上,我要如何確定移除哪些lib而不會影響系統

3.以libroffice、vim為例,使用apt-get autoremove + tab會看到
vim vim-common vim-runtime vim-tiny

....libreoffice-core libreoffice-gtk libreoffice-help-en-us libreoffice-math libreoffice-style-elementary libreoffice-style-galaxy libreoffice-writer libreoffice-base-core libreoffice-calc libreoffice-common...


以vim來說,我平常都是用vim這個指令,那是不是代表vim-common 、vim-runtime、vim-tiny都可以刪除? (vim-runtime?,那平常打的vim不是runtim嗎?)

我平常不使用libroffice,我要如何一次移除這整個套件?

謝謝各位的撥冗觀看


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

針對您問的問題,
下面的講解,我可能沒有講的很完整,有些我也沒研究透徹,
所以您可以再自行去探索,
請聚焦於理解關於「套件的操作和概念」,
先建立一些基礎的概念,就可以進一步去探索相關的議題。

一些「討論案例」和「參考連結」,以前紀錄在「[索引] 套件操作實務」。

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

關於

ubuntu_net2016 寫到:
ubuntu有內建Disk Analyzer可以查看
xubuntu似乎沒有?(gnome only?)



執行


$ apt-cache search 'Disk Analyzer'



沒有顯示任何結果,直接跳到另一個提示字元。

執行


$ apt-cache search 'Disk' | grep 'Analyzer' -i



顯示


baobab - GNOME disk usage analyzer
duc - high-performance disk usage analyzer
duc-nox - high-performance disk usage analyzer (without X support)



執行


$ apt-cache search 'Analyzer' | grep 'Disk' -i



顯示


baobab - GNOME disk usage analyzer
duc - high-performance disk usage analyzer
duc-nox - high-performance disk usage analyzer (without X support)



關於「baobab」,在「#3」有提到。

林博仁 寫到:
可以用 Baobab 軟體查看哪些檔案佔用磁碟空間


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

執行


$ apt-cache show baobab



顯示


Package: baobab
Architecture: amd64
Version: 3.26.1-0ubuntu1
Priority: optional
Section: gnome
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian GNOME Maintainers <pkg-gnome-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 820
Depends: libc6 (>= 2.4), libcairo2 (>= 1.2.4), libglib2.0-0 (>= 2.40), libgtk-3-0 (>= 3.19.12), libpango-1.0-0 (>= 1.14.0), dconf-gsettings-backend | gsettings-backend
Recommends: yelp
Filename: pool/main/b/baobab/baobab_3.26.1-0ubuntu1_amd64.deb
Size: 150286
MD5sum: 7f21a722fea6127ac072f3e569a798f6
SHA1: 2656745f742d2b08b81df129efd67613d1de542a
SHA256: 338f4ed35fffdbdaa8700b9be429765b36e7ef32efba5dcf0164b8f78fc413ba
Homepage: https://wiki.gnome.org/Apps/Baobab
Description-en: GNOME disk usage analyzer
Disk Usage Analyzer is a graphical, menu-driven application to analyse
disk usage in a GNOME environment. It can easily scan either the whole
filesystem tree, or a specific user-requested directory branch (local or
remote).
.
It also auto-detects in real-time any changes made to your home
directory as far as any mounted/unmounted device. Disk Usage Analyzer
also provides a full graphical treemap window for each selected folder.
Description-md5: 5f6072b89ebb1dc83433fa7658814dc6
Task: ubuntu-desktop, ubuntu-usb, edubuntu-desktop, edubuntu-usb, ubuntu-gnome-desktop, ubuntukylin-desktop, ubuntu-budgie-desktop
Supported: 9m



可以看到「baobab」這個套件的相關資訊。

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

執行下面指令,過濾某個欄位,舉例如下:


$ apt-cache show baobab | grep '^Homepage:'



顯示


Homepage: https://wiki.gnome.org/Apps/Baobab



就可以看到上面的「Homepage:」那個欄位「https://wiki.gnome.org/Apps/Baobab」。

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

我在「Ubuntu 17.10」 測試

執行


$ dpkg -l baobab



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-========================================-=========================-=========================-=======
ii baobab 3.26.1-0ubuntu1 amd64 GNOME disk usage analyzer



表示我的系統「Ubuntu 17.10」,有安裝「baobab」這個套件。


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

我在「Xubuntu 17.10」 測試

執行


$ dpkg -l baobab



顯示


$ dpkg-query: no packages found matching baobab



表示我的系統「Xubuntu 17.10」,沒有安裝「baobab」這個套件。

所以執行下面指令,安裝「baobab」這個套件。


$ sudo apt-get install baobab



就會有「Disk Usage Analyzer」可以使用。

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

當安裝了「baobab」這個套件。


$ dpkg -L baobab | grep bin



顯示


/usr/bin
/usr/bin/baobab



可以找到「/usr/bin/baobab」這個檔案。

或是也可以執行


$ whereis baobab



顯示


baobab: /usr/bin/baobab /usr/share/man/man1/baobab.1.gz



一樣可以找到「/usr/bin/baobab」這個檔案。


執行


$ which baobab



顯示


/usr/bin/baobab



一樣可以找到「/usr/bin/baobab」這個檔案。

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

當安裝了「baobab」這個套件。

執行


$ dpkg -L baobab | grep man



顯示


/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/baobab.1.gz



就可以了解到,可以執行下面指令,閱讀「baobab」這個指令相關的說明


$ man baobab



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

當安裝了「baobab」這個套件。

執行


$ dpkg -L baobab | grep applications



顯示


/usr/share/applications
/usr/share/applications/org.gnome.baobab.desktop



就可以找到「/usr/share/applications/org.gnome.baobab.desktop」這個檔案。

可以執行指令,觀看「/usr/share/applications/org.gnome.baobab.desktop」這個檔案


$ cat /usr/share/applications/org.gnome.baobab.desktop



內容有點多,就不貼出來了,請自行測試,

也可以透過「grep」過濾出關注的內容

例如執行


$ cat /usr/share/applications/org.gnome.baobab.desktop | grep 'exec' -i



或是執行


$ grep -i 'exec' /usr/share/applications/org.gnome.baobab.desktop



顯示


TryExec=baobab
Exec=baobab



一些關於「Desktop Entry」的討論案例,紀錄在「[索引] 泛Ubuntu 安裝調校


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

待續...

2017/12/17 16:45
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
ubuntu_net2016 寫到:
我平常不使用libroffice,我要如何一次移除這整個套件?



最近有類似的一個討論案例「#4 回覆: 部份應用軟體無法輸入中文」。

以下是參考步驟

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

執行


$ dpkg -l '*libreoffice*'



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-========================================-=========================-=========================-======
un browser-plugin-libreoffice <none> <none> (no description available)
un libreoffice <none> <none> (no description available)
un libreoffice-avmedia-backend <none> <none> (no description available)
ii libreoffice-avmedia-backend-gstreamer 1:5.4.2-0ubuntu0.17.10.1 amd64 GStreamer backend for LibreOffice
un libreoffice-base <none> <none> (no description available)
ii libreoffice-base-core 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- shared library
un libreoffice-bundled <none> <none> (no description available)
ii libreoffice-calc 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- spreadsheet
ii libreoffice-common 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- arch-independent files
ii libreoffice-core 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- arch-dependent files
un libreoffice-dev <none> <none> (no description available)
ii libreoffice-draw 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- drawing
un libreoffice-evolution <none> <none> (no description available)
...略...


顯示結果我沒有全貼出來,所以「...略...」表示被我省略的部份。

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

執行下面指令,過濾出開頭是「ii」的那幾筆。


$ dpkg -l '*libreoffice*' | grep '^ii'



顯示


ii libreoffice-avmedia-backend-gstreamer 1:5.4.2-0ubuntu0.17.10.1 amd64 GStreamer backend for LibreOffice
ii libreoffice-base-core 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- shared library
ii libreoffice-calc 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- spreadsheet
ii libreoffice-common 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- arch-independent files
ii libreoffice-core 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- arch-dependent files
ii libreoffice-draw 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- drawing
ii libreoffice-gnome 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- GNOME integration
ii libreoffice-gtk3 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- GTK+ 3 integration
ii libreoffice-help-en-us 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- English_american help
ii libreoffice-impress 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- presentation
ii libreoffice-math 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- equation editor
ii libreoffice-ogltrans 1:5.4.2-0ubuntu0.17.10.1 amd64 LibreOffice Impress extension for slide transitions using OpenGL
ii libreoffice-pdfimport 1:5.4.2-0ubuntu0.17.10.1 all transitional package for PDF Import component for LibreOffice
ii libreoffice-style-breeze 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- Breeze symbol style
ii libreoffice-style-elementary 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- Elementary symbol style
ii libreoffice-style-galaxy 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- Galaxy (Default) symbol style
ii libreoffice-style-tango 1:5.4.2-0ubuntu0.17.10.1 all office productivity suite -- Tango symbol style
ii libreoffice-writer 1:5.4.2-0ubuntu0.17.10.1 amd64 office productivity suite -- word processor



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

執行下面指令,過濾出開頭是「ii」的那幾筆,並且只有顯示套件名稱


$ dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3



顯示


libreoffice-avmedia-backend-gstreamer
libreoffice-base-core
libreoffice-calc
libreoffice-common
libreoffice-core
libreoffice-draw
libreoffice-gnome
libreoffice-gtk3
libreoffice-help-en-us
libreoffice-impress
libreoffice-math
libreoffice-ogltrans
libreoffice-pdfimport
libreoffice-style-breeze
libreoffice-style-elementary
libreoffice-style-galaxy
libreoffice-style-tango
libreoffice-writer



這樣就可以獲得套件清單。

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

要同時移除多個套件,
指令的形式「sudo apt-get remove package-1 package-2 package-3」,
套用上面的例子就是「sudo apt-get remove libreoffice-avmedia-backend-gstreamer libreoffice-base-core libreoffice-calc」,

所以可以結合剛剛的指令


$ sudo apt-get remove $(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)



就會先出現「確認訊息」,確認您是否要繼續執行


Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libreoffice-avmedia-backend-gstreamer libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome
libreoffice-gtk3 libreoffice-help-en-us libreoffice-impress libreoffice-math libreoffice-ogltrans libreoffice-pdfimport libreoffice-style-breeze
libreoffice-style-elementary libreoffice-style-galaxy libreoffice-style-tango libreoffice-writer python3-uno
0 upgraded, 0 newly installed, 19 to remove and 0 not upgraded.
After this operation, 329 MB disk space will be freed.
Do you want to continue? [Y/n]



按下「Enter」後,就會繼續執行移除的動作。

關於「$(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)」這個用法,

您可以執行「$ man bash」,然後使用「Command Substitution」當關鍵字找尋,
應該可以找到類似如下的說明


Command Substitution
	Command substitution allows the output of  a  command  to  replace  the
	command name.  There are two forms:

		   $(command)
	or
		   `command`



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

您也可執行下面指令,先把套件清單,存到一個檔案「pkg.list」。


$ dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3 > pkg.list



您可以先編輯「pkg.list」把不要刪除的套件,刪除該行。

然後再執行下面指令,根據「pkg.list」列的套件清單,來刪除套件


$ sudo apt-get remove $(cat pkg.list)



一樣會先出現「確認訊息」,確認您是否要繼續執行


Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libreoffice-avmedia-backend-gstreamer libreoffice-base-core libreoffice-calc libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome
libreoffice-gtk3 libreoffice-help-en-us libreoffice-impress libreoffice-math libreoffice-ogltrans libreoffice-pdfimport libreoffice-style-breeze
libreoffice-style-elementary libreoffice-style-galaxy libreoffice-style-tango libreoffice-writer python3-uno
0 upgraded, 0 newly installed, 19 to remove and 0 not upgraded.
After this operation, 329 MB disk space will be freed.
Do you want to continue? [Y/n]



按下「Enter」後,就會繼續執行移除的動作。

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

另外「apt-get remove」可以加入「--purge」這個參數。


$ sudo apt-get remove --purge $(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)



或是也可以直接執行「apt-get purge」


$ sudo apt-get purge $(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)



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

也可以加入「-s」或是「--simulate」這個參數

執行


$ sudo apt-get remove --purge -s $(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)



或是執行


$ sudo apt-get purge -s $(dpkg -l '*libreoffice*' | grep '^ii' | cut -d ' ' -f 3)



顯示


Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
libreoffice-avmedia-backend-gstreamer* libreoffice-base-core* libreoffice-calc* libreoffice-common* libreoffice-core* libreoffice-draw* libreoffice-gnome*
libreoffice-gtk3* libreoffice-help-en-us* libreoffice-impress* libreoffice-math* libreoffice-ogltrans* libreoffice-pdfimport* libreoffice-style-breeze*
libreoffice-style-elementary* libreoffice-style-galaxy* libreoffice-style-tango* libreoffice-writer* python3-uno*
0 upgraded, 0 newly installed, 19 to remove and 0 not upgraded.
Purg libreoffice-avmedia-backend-gstreamer [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-help-en-us [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-writer [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-calc [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-base-core [1:5.4.2-0ubuntu0.17.10.1]
Purg python3-uno [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-pdfimport [1:5.4.2-0ubuntu0.17.10.1]
Purg libreoffice-core [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-ogltrans:amd64 libreoffice-impress:amd64 libreoffice-gnome:amd64 libreoffice-draw:amd64 ]
Purg libreoffice-style-tango [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-ogltrans:amd64 libreoffice-impress:amd64 libreoffice-gnome:amd64 libreoffice-draw:amd64 ]
Purg libreoffice-common [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-style-galaxy:amd64 libreoffice-ogltrans:amd64 libreoffice-impress:amd64 libreoffice-style-elementary:amd64 libreoffice-gnome:amd64 libreoffice-draw:amd64 ]
Purg libreoffice-ogltrans [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-style-galaxy:amd64 libreoffice-impress:amd64 libreoffice-style-elementary:amd64 libreoffice-gnome:amd64 libreoffice-draw:amd64 ]
Purg libreoffice-impress [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 libreoffice-gnome:amd64 libreoffice-draw:amd64 ]
Purg libreoffice-draw [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 libreoffice-gnome:amd64 ]
Purg libreoffice-gnome [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-gtk3:amd64 libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 ]
Purg libreoffice-gtk3 [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-math:amd64 libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 ]
Purg libreoffice-math [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-breeze:amd64 libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 ]
Purg libreoffice-style-breeze [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-galaxy:amd64 libreoffice-style-elementary:amd64 ]
Purg libreoffice-style-elementary [1:5.4.2-0ubuntu0.17.10.1] [libreoffice-style-galaxy:amd64 ]
Purg libreoffice-style-galaxy [1:5.4.2-0ubuntu0.17.10.1]



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

請參考

$ man apt-get

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

待續...

2017/12/17 16:51
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
ubuntu_net2016 寫到:
以vim來說,我平常都是用vim這個指令,那是不是代表vim-common 、vim-runtime、vim-tiny都可以刪除? (vim-runtime?,那平常打的vim不是runtim嗎?)



在討論上面您提的這個疑問前,

先釐清一下,

當執行「$ sudo apt-get install vim」時,這裡的「vim」指的是「Package (套件)」。

而執行「$ vim」時,這裡的「vim」,指的則是「Command (指令)」。

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

先跳過「vim」,先舉另外的例子。

執行下面指令,安裝「hello」這個「Package (套件)」。


$ sudo apt-get install hello



安裝「hello」這個「Package (套件)」後。

可以執行下面指令,了解「hello」這個「Package (套件)」,安裝哪些檔案在系統上。


$ dpkg -L hello



顯示


/.
/usr
/usr/bin
/usr/bin/hello
/usr/share
/usr/share/doc
/usr/share/doc/hello
/usr/share/doc/hello/NEWS.gz
/usr/share/doc/hello/changelog.Debian.gz
/usr/share/doc/hello/copyright
/usr/share/info
/usr/share/info/hello.info.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/hello.1.gz



上面的檔案清單,也可以從「/var/lib/dpkg/info/hello.list」這個檔案找到。

執行下面指令,觀看「/var/lib/dpkg/info/hello.list」的內容。


$ cat /var/lib/dpkg/info/hello.list



顯示


/.
/usr
/usr/bin
/usr/bin/hello
/usr/share
/usr/share/doc
/usr/share/doc/hello
/usr/share/doc/hello/NEWS.gz
/usr/share/doc/hello/changelog.Debian.gz
/usr/share/doc/hello/copyright
/usr/share/info
/usr/share/info/hello.info.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/hello.1.gz


或是也可以從網頁上「https://packages.ubuntu.com/artful/hello」。

下面有「[list of files]」,點選下去,就會連到「https://packages.ubuntu.com/artful/amd64/hello/filelist」。

就可以看到類似的檔案清單。

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

從上面的檔案清單,可以看到其中有一個檔案「/usr/bin/hello」,這個就是「Command (指令)」。

可以執行


$ hello



顯示


Hello, world!



這裡的「hello」指的是「Command (指令)」。

上面的其實也可以執行如下,只是通常比較少這樣下指令就是了。


$ /usr/bin/hello



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

從上面的檔案清單,可以看到其中有一個檔案「/usr/share/man/man1/hello.1.gz」,

所以就可以聯想到,可以執行


$ man hello



就可以看到相關的「說明」。

更進一步可以從下面這個連結,建立一些概念。

* 鳥哥的 Linux 私房菜 / 鳥哥的 Linux 私房菜 / 4.3 Linux系統的線上求助man page與info page

上面的其實也可以執行如下,只是通常比較少這樣下指令就是了。


$ man /usr/share/man/man1/hello.1.gz



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

從上面的檔案清單,可以看到其中有一個檔案「/usr/share/info/hello.info.gz」,

所以就可以聯想到,可以執行


$ info hello



上面的其實也可以執行如下,只是通常比較少這樣下指令就是了。


$ info /usr/share/info/hello.info.gz



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

再回到「hello」這個指令來回推。

執行


$ whereis hello



顯示


hello: /usr/bin/hello /usr/share/man/man1/hello.1.gz /usr/share/info/hello.info.gz



一樣可以找到「/usr/bin/hello」這個檔案路徑。

接著執行


$ dpkg -S /usr/bin/hello



顯示


hello: /usr/bin/hello



表示「/usr/bin/hello」這個檔案,是來自於「hello」這個套件。

除了使用「whereis」,也可以善用另一個指令「which」。

執行


$ which hello



顯示


/usr/bin/hello



所以可以結合成一行指令

執行


$ dpkg -S $(which hello)



顯示


hello: /usr/bin/hello



一樣可以了解到「/usr/bin/hello」這個檔案,是來自於「hello」這個套件。

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

上面的模式,一樣可以套用另外一個例子,我們來看最常用的「ls」這個指令。

執行


$ whereis ls



顯示


ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1/ls.1posix.gz



執行


$ which ls



顯示


/bin/ls



執行


$ dpkg -S /bin/ls



或是執行


$ dpkg -S $(which ls)



顯示


coreutils: /bin/ls



就可以了解到「/bin/ls」來自於「coreutils」這個套件。


接著就可以執行「$ dpkg -L coreutils」找到其他更多的指令。


/.
/bin
/bin/cat
/bin/chgrp
/bin/chmod
/bin/chown
/bin/cp
/bin/date
/bin/dd
/bin/df
/bin/dir
/bin/echo
/bin/false
/bin/ln
/bin/ls
/bin/mkdir
/bin/mknod
/bin/mktemp
/bin/mv
/bin/pwd
/bin/readlink
/bin/rm
/bin/rmdir
/bin/sleep
/bin/stty
/bin/sync
/bin/touch
/bin/true
/bin/uname
/bin/vdir
...略...



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

待續...

2017/12/17 17:12
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
回來討論「vim」

執行


$ whereis vim



顯示


vim: /usr/bin/vim.gtk3 /usr/bin/vim.tiny /usr/bin/vim /usr/bin/vim.basic /etc/vim /usr/share/vim /usr/share/man/man1/vim.1.gz



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

執行


$ dpkg -S /usr/bin/vim.tiny



顯示


vim-tiny: /usr/bin/vim.tiny



表示「/usr/bin/vim.tiny」是來自於「vim-tiny」這個套件。

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

執行


$ dpkg -S /usr/bin/vim.basic



顯示


vim: /usr/bin/vim.basic



表示「/usr/bin/vim.basic」是來自於「vim」這個套件。

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

執行


$ dpkg -S /usr/bin/vim.gtk3



顯示


vim-gtk3: /usr/bin/vim.gtk3



表示「/usr/bin/vim.gtk3」是來自於「vim-gtk3」這個套件。

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

待續...

2017/12/17 17:17
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
接續上面

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

執行下面指令,了解「vim-tiny」這個套件,安裝那些檔案在系統上。


$ dpkg -L vim-tiny



顯示


/.
/etc
/etc/vim
/etc/vim/vimrc.tiny
/usr
/usr/bin
/usr/bin/vim.tiny
/usr/share
/usr/share/bug
/usr/share/bug/vim-tiny
/usr/share/bug/vim-tiny/presubj
/usr/share/bug/vim-tiny/script
/usr/share/doc
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/vim-tiny
/usr/share/vim
/usr/share/vim/vim80
/usr/share/vim/vim80/doc
/usr/share/vim/vim80/doc/README.Debian
/usr/share/vim/vim80/doc/help.txt
diverted by vim-runtime to: /usr/share/vim/vim80/doc/help.txt.vim-tiny
/usr/share/vim/vim80/doc/tags
diverted by vim-runtime to: /usr/share/vim/vim80/doc/tags.vim-tiny
/usr/share/doc/vim-tiny
/usr/share/vim/vimrc.tiny



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

執行下面指令,了解「vim」這個套件,安裝那些檔案在系統上。


$ dpkg -L vim



顯示


/.
/usr
/usr/bin
/usr/bin/vim.basic
/usr/share
/usr/share/bug
/usr/share/bug/vim
/usr/share/bug/vim/presubj
/usr/share/bug/vim/script
/usr/share/doc
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/vim
/usr/share/doc/vim



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

執行下面指令,了解「vim-gtk3」這個套件,安裝那些檔案在系統上。


$ dpkg -L vim-gtk3



顯示


/.
/usr
/usr/bin
/usr/bin/vim.gtk3
/usr/share
/usr/share/bug
/usr/share/bug/vim-gtk3
/usr/share/bug/vim-gtk3/presubj
/usr/share/bug/vim-gtk3/script
/usr/share/doc
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/vim-gtk3
/usr/share/doc/vim-gtk3



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

待續...

2017/12/17 17:22
應用擴展 工具箱
回覆: harddisk容量少了很多
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 36
HP : 179 / 898
MP : 664 / 28641
EXP: 92
離線
延續上面,接著開始來探索「/usr/bin/vim」這個檔案。

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

執行


$ dpkg -S /usr/bin/vim



顯示


dpkg-query: no path found matching pattern /usr/bin/vim



關於「/usr/bin/vim」這個檔案,無法找到是來自於哪個套件。

因為這裡使用了「Debian Alternatives System」這個機制,
所以推論「/usr/bin/vim」這個檔案會是由「MaintainerScripts」產生。

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

執行


$ file /usr/bin/vim



顯示


/usr/bin/vim: symbolic link to /etc/alternatives/vim



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

執行


$ file /etc/alternatives/vim



顯示


/etc/alternatives/vim: symbolic link to /usr/bin/vim.gtk3



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

執行下面指令,觀看「/var/lib/dpkg/info/vim-tiny.postinst」這個檔案的內容


$ cat /var/lib/dpkg/info/vim-tiny.postinst



顯示


#!/bin/sh
set -e

pkg=vim-tiny
variant=tiny
mandir=/usr/share/man

# add /usr/bin/vim.variant as alternative for /usr/bin/vim. Priority are
# chosen accordingly to the principle: ``more features, higher priority''

add_variant_alternative () {
  if [ "$variant" != "tiny" ]; then
    update-alternatives --install /usr/bin/vim vim /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/vimdiff vimdiff /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/rvim rvim /usr/bin/vim.$variant $1
  fi
  update-alternatives --install /usr/bin/rview rview /usr/bin/vim.$variant $1
  # Since other packages provide these commands, we'll setup alternatives for
  # their manpages, too.
  for i in vi view ex editor ; do
    update-alternatives \
      --install /usr/bin/$i $i /usr/bin/vim.$variant $1 \
      --slave $mandir/fr/man1/$i.1.gz $i.fr.1.gz $mandir/fr/man1/vim.1.gz \
      --slave $mandir/it/man1/$i.1.gz $i.it.1.gz $mandir/it/man1/vim.1.gz \
      --slave $mandir/pl/man1/$i.1.gz $i.pl.1.gz $mandir/pl/man1/vim.1.gz \
      --slave $mandir/ru/man1/$i.1.gz $i.ru.1.gz $mandir/ru/man1/vim.1.gz \
      --slave $mandir/ja/man1/$i.1.gz $i.ja.1.gz $mandir/ja/man1/vim.1.gz \
      --slave $mandir/man1/$i.1.gz $i.1.gz \
              $mandir/man1/vim.1.gz
  done
  case "$variant" in
    gtk|gtk3|athena) # gui enabled variants
      add_gui_variant_alternative $1
      ;;
  esac
}

add_gui_variant_alternative () {
  for i in gvim gview rgview rgvim evim eview gvimdiff ; do
    update-alternatives --install /usr/bin/$i $i /usr/bin/vim.$variant $1
  done
}

case "$pkg" in
  vim-tiny)
    add_variant_alternative 15
    ;;
  vim)
    add_variant_alternative 30
    ;;
  vim-nox)
    add_variant_alternative 40
    ;;
  vim-gtk|vim-gtk3|vim-athena)
    add_variant_alternative 50
    ;;
esac



exit 0




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

執行下面指令,觀看「/var/lib/dpkg/info/vim.postinst」這個檔案的內容


$ cat /var/lib/dpkg/info/vim.postinst



顯示


#!/bin/sh
set -e

pkg=vim
variant=basic
mandir=/usr/share/man

# add /usr/bin/vim.variant as alternative for /usr/bin/vim. Priority are
# chosen accordingly to the principle: ``more features, higher priority''

add_variant_alternative () {
  if [ "$variant" != "tiny" ]; then
    update-alternatives --install /usr/bin/vim vim /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/vimdiff vimdiff /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/rvim rvim /usr/bin/vim.$variant $1
  fi
  update-alternatives --install /usr/bin/rview rview /usr/bin/vim.$variant $1
  # Since other packages provide these commands, we'll setup alternatives for
  # their manpages, too.
  for i in vi view ex editor ; do
    update-alternatives \
      --install /usr/bin/$i $i /usr/bin/vim.$variant $1 \
      --slave $mandir/fr/man1/$i.1.gz $i.fr.1.gz $mandir/fr/man1/vim.1.gz \
      --slave $mandir/it/man1/$i.1.gz $i.it.1.gz $mandir/it/man1/vim.1.gz \
      --slave $mandir/pl/man1/$i.1.gz $i.pl.1.gz $mandir/pl/man1/vim.1.gz \
      --slave $mandir/ru/man1/$i.1.gz $i.ru.1.gz $mandir/ru/man1/vim.1.gz \
      --slave $mandir/ja/man1/$i.1.gz $i.ja.1.gz $mandir/ja/man1/vim.1.gz \
      --slave $mandir/man1/$i.1.gz $i.1.gz \
              $mandir/man1/vim.1.gz
  done
  case "$variant" in
    gtk|gtk3|athena) # gui enabled variants
      add_gui_variant_alternative $1
      ;;
  esac
}

add_gui_variant_alternative () {
  for i in gvim gview rgview rgvim evim eview gvimdiff ; do
    update-alternatives --install /usr/bin/$i $i /usr/bin/vim.$variant $1
  done
}

case "$pkg" in
  vim-tiny)
    add_variant_alternative 15
    ;;
  vim)
    add_variant_alternative 30
    ;;
  vim-nox)
    add_variant_alternative 40
    ;;
  vim-gtk|vim-gtk3|vim-athena)
    add_variant_alternative 50
    ;;
esac



exit 0




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

執行下面指令,觀看「/var/lib/dpkg/info/vim-gtk3.postinst」這個檔案的內容


$ cat /var/lib/dpkg/info/vim-gtk3.postinst



顯示


#!/bin/sh
set -e

pkg=vim-gtk3
variant=gtk3
mandir=/usr/share/man

# add /usr/bin/vim.variant as alternative for /usr/bin/vim. Priority are
# chosen accordingly to the principle: ``more features, higher priority''

add_variant_alternative () {
  if [ "$variant" != "tiny" ]; then
    update-alternatives --install /usr/bin/vim vim /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/vimdiff vimdiff /usr/bin/vim.$variant $1
    update-alternatives --install /usr/bin/rvim rvim /usr/bin/vim.$variant $1
  fi
  update-alternatives --install /usr/bin/rview rview /usr/bin/vim.$variant $1
  # Since other packages provide these commands, we'll setup alternatives for
  # their manpages, too.
  for i in vi view ex editor ; do
    update-alternatives \
      --install /usr/bin/$i $i /usr/bin/vim.$variant $1 \
      --slave $mandir/fr/man1/$i.1.gz $i.fr.1.gz $mandir/fr/man1/vim.1.gz \
      --slave $mandir/it/man1/$i.1.gz $i.it.1.gz $mandir/it/man1/vim.1.gz \
      --slave $mandir/pl/man1/$i.1.gz $i.pl.1.gz $mandir/pl/man1/vim.1.gz \
      --slave $mandir/ru/man1/$i.1.gz $i.ru.1.gz $mandir/ru/man1/vim.1.gz \
      --slave $mandir/ja/man1/$i.1.gz $i.ja.1.gz $mandir/ja/man1/vim.1.gz \
      --slave $mandir/man1/$i.1.gz $i.1.gz \
              $mandir/man1/vim.1.gz
  done
  case "$variant" in
    gtk|gtk3|athena) # gui enabled variants
      add_gui_variant_alternative $1
      ;;
  esac
}

add_gui_variant_alternative () {
  for i in gvim gview rgview rgvim evim eview gvimdiff ; do
    update-alternatives --install /usr/bin/$i $i /usr/bin/vim.$variant $1
  done
}

case "$pkg" in
  vim-tiny)
    add_variant_alternative 15
    ;;
  vim)
    add_variant_alternative 30
    ;;
  vim-nox)
    add_variant_alternative 40
    ;;
  vim-gtk|vim-gtk3|vim-athena)
    add_variant_alternative 50
    ;;
esac



exit 0




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

接下來,來作個小實驗。

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

執行下面指令,產生「/usr/local/bin/demo-tiny」,並設為可執行


sudo sh -c 'echo echo tiny > /usr/local/bin/demo-tiny'
sudo chmod +x /usr/local/bin/demo-tiny



執行下面指令,觀看「/usr/local/bin/demo-tiny」


$ cat /usr/local/bin/demo-tiny



顯示


echo tiny



執行下面指令


$ demo-tiny



顯示


tiny



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

執行下面指令,產生「/usr/local/bin/demo-basic」,並設為可執行


sudo sh -c 'echo echo basic > /usr/local/bin/demo-basic'
sudo chmod +x /usr/local/bin/demo-basic



執行下面指令,觀看「/usr/local/bin/demo-basic」


$ cat /usr/local/bin/demo-basic



顯示


echo basic



執行下面指令


$ demo-basic



顯示


basic



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

執行下面指令


$ sudo update-alternatives --install /usr/local/bin/demo demo /usr/local/bin/demo-tiny 15



顯示


update-alternatives: using /usr/local/bin/demo-tiny to provide /usr/local/bin/demo (demo) in auto mode



執行


$ cat /var/lib/dpkg/alternatives/demo



顯示


auto
/usr/local/bin/demo

/usr/local/bin/demo-tiny
15




執行


$ file /usr/local/bin/demo



顯示


$ /usr/local/bin/demo: symbolic link to /etc/alternatives/demo



執行


$ file /etc/alternatives/demo



顯示


$ /etc/alternatives/demo: symbolic link to /usr/local/bin/demo-tiny



也就是「/usr/local/bin/demo」--> 「/etc/alternatives/demo」--> 「/usr/local/bin/demo-tiny」

所以執行


$ demo



顯示


tiny



執行


$ update-alternatives --query demo



顯示


Name: demo
Link: /usr/local/bin/demo
Status: auto
Best: /usr/local/bin/demo-tiny
Value: /usr/local/bin/demo-tiny

Alternative: /usr/local/bin/demo-tiny
Priority: 15



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

執行


$ sudo update-alternatives --install /usr/local/bin/demo demo /usr/local/bin/demo-basic 30



顯示


update-alternatives: using /usr/local/bin/demo-basic to provide /usr/local/bin/demo (demo) in auto mode



執行


$ cat /var/lib/dpkg/alternatives/demo



顯示


auto
/usr/local/bin/demo

/usr/local/bin/demo-basic
30
/usr/local/bin/demo-tiny
15




執行


$ update-alternatives --query demo



顯示


Name: demo
Link: /usr/local/bin/demo
Status: auto
Best: /usr/local/bin/demo-basic
Value: /usr/local/bin/demo-basic

Alternative: /usr/local/bin/demo-basic
Priority: 30

Alternative: /usr/local/bin/demo-tiny
Priority: 15




執行


$ file /usr/local/bin/demo



顯示


$ /usr/local/bin/demo: symbolic link to /etc/alternatives/demo



執行


$ file /etc/alternatives/demo



顯示


$ /etc/alternatives/demo: symbolic link to /usr/local/bin/demo-basic



也就是「/usr/local/bin/demo」--> 「/etc/alternatives/demo」--> 「/usr/local/bin/demo-basic」

所以執行


$ demo



顯示


basic



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

執行


$ sudo update-alternatives --config demo



顯示


There are 2 choices for the alternative demo (providing /usr/local/bin/demo).

  Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/local/bin/demo-basic   30        auto mode
  1            /usr/local/bin/demo-basic   30        manual mode
  2            /usr/local/bin/demo-tiny    15        manual mode

Press <enter> to keep the current choice[ * ], or type selection number:



選擇「2」,按下「Enter」,接著顯示


update-alternatives: using /usr/local/bin/demo-tiny to provide /usr/local/bin/demo (demo) in manual mode



執行


$ file /etc/alternatives/demo



顯示


/etc/alternatives/demo: symbolic link to /usr/local/bin/demo-tiny



執行


$ demo



顯示


tiny



再次執行


$ sudo update-alternatives --config demo



顯示


There are 2 choices for the alternative demo (providing /usr/local/bin/demo).

  Selection    Path                       Priority   Status
------------------------------------------------------------
  0            /usr/local/bin/demo-basic   30        auto mode
  1            /usr/local/bin/demo-basic   30        manual mode
* 2            /usr/local/bin/demo-tiny    15        manual mode

Press <enter> to keep the current choice[ * ], or type selection number:




按下「Ctrl+c」離開,不設定。

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

如何移除

執行


$ sudo update-alternatives --remove-all demo



或是執行


sudo update-alternatives --remove demo /usr/local/bin/demo-tiny
sudo update-alternatives --remove demo /usr/local/bin/demo-basic



如何確認

執行


$ update-alternatives --query demo



顯示


update-alternatives: error: no alternatives for demo



執行


$ ls /etc/alternatives/demo



顯示


ls: cannot access '/etc/alternatives/demo': No such file or directory



執行


$ ls /var/lib/dpkg/alternatives/demo



顯示


$ ls: cannot access '/var/lib/dpkg/alternatives/demo': No such file or directory



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

移除「/usr/local/bin/demo-tiny」和「/usr/local/bin/demo-basic」

執行下面指令


$ sudo rm /usr/local/bin/demo-tiny /usr/local/bin/demo-basic



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

執行


$ whereis update-alternatives



顯示


update-alternatives: /usr/bin/update-alternatives /usr/share/man/man1/update-alternatives.1.gz



執行


$ dpkg -S /usr/bin/update-alternatives



顯示


dpkg: /usr/bin/update-alternatives



表示「/usr/bin/update-alternatives」這個檔案,是來自於「dpkg」這個套件。

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

## log檔路徑

* /var/log/alternatives.log

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

接下來透過「vim」的例子,來對「update-alternatives」做更多的用法說明。

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

待續...

2017/12/17 17:28
應用擴展 工具箱

(1) 2 »

 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.