ディレクトリからファイルを選択しますか? [閉鎖]

ディレクトリからファイルを選択しますか? [閉鎖]

Bashがディレクトリ内にあるときに、実際に名前や名前の一部を入力せずにファイルまたはサブディレクトリを選択するにはどうすればよいですか?

TABを使用してWebページの複数のコンテンツを切り替える方法など、ファイルまたはサブディレクトリを列挙または置き換える方法はありますか?

ファイルやサブディレクトリを開く方法はアプリケーションによって異なりますか?

の場合、

  • 複数のサブディレクトリからサブディレクトリをどのように選択できますかcd

  • 複数のPDFファイルから1つのPDFファイルをどのように選択できますかevince

例えば

$ ls .
  subdir1 subdir2
$ cd 

何も入力せずに選択できsubdir2ますか?理想的には、キーを使って選択して切り替える方が良いでしょう。その後、停止してクリックできます。cdsubdir2Tabsubdir1subdir2subdir2Return

答え1

置く

bind TAB:menu-complete

それからevinceTAB。数回クリックしてTAB別のファイルを見つけてください。

答え2

ファイルは次のように列挙できます。

for file in .* * do;
  # if targeted at files:
  test -f "$file" || continue
  # if targeted at directories:
  test -d "$file" || continue
  # in both cases arises the question: What about symlinks?
done

または(ソート時間を節約するため)

ls --quoting-style=escape | while IFS= read file; do...
  : check type like above
done

find . -type f -maxdepth 1 -printf %f\\n | while IFS= read -r file; do...

find . -type d -maxdepth 1 -printf %f\\n | while IFS= read -r file; do...

(このfind亜種は奇妙なファイル名を処理しません。)

関連情報