環境
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
$ bash --version
GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)
鶏頭なので,思い立ったらちょこちょこ加筆すると思う.
manuals
man - an interface to the on-line reference manuals
apropos - search the manual page names and descriptions
whatis - display one-line manual page descriptions
build-in commandsのmanual
cd,bg, evalなどのbuild-in commandsのいくつかは
$ man eval
No manual entry for eval
となるが
$ man builtins
もしくは
$ help eval
からマニュアルを参照可能.
manualの日本語
$ sudo apt-get install manpages-ja
を入れておけば日本語のmanualを参照できるが,terminalのlocale をen_US.UTF-8にしているので
$ alias man="env LANG=ja_JP.UTF-8 man"
としえおけば翻訳されたmanualを参照できる.日本語manualが無い場合は英語のmanualが参照される.original(英語)のmanualを参照したいときは
$ \man
のようにスラッシュを先頭につければ,aliasを無視して実行できる.
設定(~/.bashrc or ~/.bash_profile)
デフォルトのterminalだと
username@hostname:<path>$
のように表示されるがディレクトリ階層が深くなると冗長的なので
PROMPT_DIRTRIM=1
とすれば,current directory 以下は省略される. また,user名は自明なので省略する.
export PS1="[@\h \w]\\$ "
詳細は@IT > Linux & OSS > Linux Tips Index > bashのプロンプトを変更するには
ssh
sshの鍵生成はed25519を使う
$ ssh-keygen -t ed25519
apt-clone
$ sudo apt install apt-clone
からapt-cloneをinstallして
$ sudo apt-clone clone .
とすれば,current directory に apt-clone-state-<hostname>.tar.gzができるので新環境で
$ sudo apt-clone restore apt-clone-state-<hostname>.tar.gz
を実行すればapt環境をcloneできる.なおWolframEnginは
not installable: wolframscript
となったので,手動で設定する必要がありそう.
cd
$ cd -
で一つ前にいたディレクトリに戻れる.深いディレクトリで誤ってcdしてしまった場合等に対応できる.
ln
ln -s で作成したシンボリックリンクの解除は
$ unlink
type
を使えば,alias しているものの詳細やパスが取得できる
$ type gnuplot
gnuplot is aliased to `rlwrap -a -c -b"\"\"\\'\\'" gnuplot'
gnuplotをこのようにaliasしているのはtab保管(readline)がdefaultだとうまく機能しないので.
zip/unzip・unar
日本語を含むzipを展開すると文字化けする場合がある.
man を見てもよくわからないのだがGoogle先生にお伺いするとunzip は -O オプションで(CHARSET specify a character encoding for DOS, Windows and OS/2 archives)
$ unzip
unzip | |
---|---|
-O | CHARSET specify a character encoding for DOS, Windows and OS/2 archives |
-I | CHARSET specify a character encoding for UNIX and other archives |
とあるので
$ unzip -O utf8 hoge.zip
としてみると問題なく展開できた.
unar
zip関係の文字コードの知ったのがunarを使えば,文字コードの問題のみならず,tar.xx などの様々な圧縮形式に対応した圧縮ファイルを展開できるみだいだ.unarはaptでinstallすることができる.tar.xxの圧縮・解答に関するオプションは全く覚ええられないので,非常に便利.
$ unar hoge.tar.xz
find
unzip した際に,ディレクトリ内にファイルが散乱してしまうことが多々ある.find には
$ find . -maxdepth 1 -cnewer hoge.zip
とすれば,current directry の最終ステータス更新が hoge.zipよりも新しいファイルを列挙できる.ただし,hoge.zip を含むようなのでxargs などを使って削除する場合はzipファイルを退避させたほうが良いだろう.なお,findのmanををざっくりまとめると,
日本語 | 英語 | |
---|---|---|
-amin n | 最終アクセス日時が n 分前であれば真を返す | File was last accessed n minutes ago |
-atime n | 最終アクセス日時が n 日前であれば真を返す | File was last accessed 24*n hours ago |
-anewer file | 最終アクセス日時が、file の内容更新日時よりも新しければ、真を返す | Time of the last access of the current file is more recent than that of the last data modification of the file |
-cmin n | 最終ステータス変更日時が n 分前ならば真 | File's status was last changed n minutes ago. |
-ctime n | 最終ステータス変更日時が n 日前ならば真 | File's status was last changed 24*n hours ago |
-cnewer file | 最終ステータス変更日時が、file の内容更新日時よりも新しければ、真を返す | Time of the last status change of the current file is more recent than that of the last data modification of the file |
-mmin n | 最終内容更新日時が n 分前であれば真 | File's data was last modified n minutes ago |
-mtime n | 最終内容更新日時が n 日前であれば真 | File's data was last modified 24*n hours ago |
-mnewer file | file よりも最近に内容を更新されていれば、真を返す | Time of the last data modification of the current file is more recent than that of the last data modification of the file |
とある.ファイルの最終アクセス(atime),最終ステータス変更(ctime),最終内容更新日時(mtime)はlsで調べることができ,
$ ls -l # default mtime
$ ls -l --time=ctime or ls -lc
$ ls -l --time=atime or ls -lu
で確認できることができるようである.atime, ctime, mtimeがいつ更新されるのか正確に理解していないが,mtimeやatimeはhoge.zipよりも古い場合が多々あるので,findで処理するためにはctimeを使えば確実そうだ.
ある時期(2024-11-01)からある時期(2024-11-08)までの間のファイルを探す際には
$ find . -type f -newermt 2024-11-01 ! -newermt 2024-11-08
のようにすれば良い.cpなどを組み合わせる場合は
find . -type f -newermt 2024-11-01 ! -newermt 2024-11-08 -exec cp {} ~/path/to/somewhere/ \;
最後の \;
はexecの終了を表すため必要.
pdf編集
qpdf はaptでinstallでき,マニュアルが充実しているが,日本語の解説も詳しい.
ページの回転
$ qpdf in.pdf out.pdf --rotate=90:1,3,5
とすればp1, p3, p5のページが時計回りに90度回転することができる.マニュアルにはページ番号を省けば全ページ回転するとあるが,私の環境ではできなかったので最初と最後のページを明示的に示せば
$ qpdf in.pdf out.pdf --rotate=90:1-48
前ページ回転する.なお,seqと組み合わせて
$ qpdf in.pdf out.pdf --rotate=90:`seq -s ',' 1 2 48`
とすれば奇数ページだけ回転させることが出来る.総ページ数をコマンドラインで取得するには
$ qpdf in.pdf --show-npages
48
で取得できる.
結合,抽出
結合
$ qpdf --empty --pages in-A.pdf 1-3 in-B.pdf 2-3 -- out.pdf
ページ数をはしょれば,in-A.pdfの後に in-Bがマージされる
$ qpdf --empty --pages in-A.pdf in-B.pdf -- out.pdf
特定ページの抽出は
$ qpdf --empty --pages in.pdf 1-3 -- out.pdf
のようにすればよい.
debian 10 server (NAS)
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 1048576
net.core.wmem_max = 1048576