Ubuntu(Lubuntu) の端末で apt-get install でインストールしたソフトの
一覧を出力するコマンドはなさそうなので、Perl で書いてみた。
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my @history_files = ( "~/.zhistory", "~/.bash_history", ); my %apt_list; my $opt_cmd; GetOptions('command' => \$opt_cmd); for my $history_file (@history_files) { my $cmd = "cat $history_file | grep 'apt-get install'"; my @res = `$cmd`; for my $line (@res) { chomp $line; if ( $line =~ /install (.*)$/ ) { my @apps = split(" ", $1); for my $app (@apps) { $apt_list{$app} = 1; } } } } if ( $opt_cmd ) { print "sudo apt-get install "; for my $app (sort keys %apt_list) { print $app . " "; } } else { for my $app (sort keys %apt_list) { print $app . "\n"; } }
やっていることは非常に単純で、
シェルの履歴から apt-get install を grep で抜き出して、
整えているだけ。
上記のスクリプトを使う場合は
make_apt_install_list.pl
とか適当にファイルを作成して貼り付ける。
“~/.zhistory” の部分をhistoryファイルの名前に適宜変更。
僕は bash と zsh を使っているので、複数ファイルにも対応している。
ファイルの準備ができたら、実行権限を与える。
% chmod +x make_apt_install_list.pl
実行したらずらーっと一覧が出力される。
重複は排除、昇順にソートしてある。
% ./make_apt_install_list.pl cmigemo curl emacs-mozc emacs-mozc-bin emacs24 fcitx fcitx-frontend-qt5 fcitx-libs fcitx-mozc fontforge git libssl-dev screen ttf-vlgothic ubuntu-defaults-ja vim xclip zsh
なお、一気にインストールするコマンドを出力するオプションも用意。(-c)
% ./make_apt_install_list.pl -c sudo apt-get install cmigemo curl emacs-mozc emacs-mozc-bin emacs24 fcitx fcitx-frontend-qt5 fcitx-libs fcitx-mozc fontforge git libssl-dev screen ttf-vlgothic ubuntu-defaults-ja vim xclip zsh
ファイルに出力したい場合などは以下のように。
% ./make_apt_install_list.pl > list.txt
以上。