bash型の最初の文字でファイル名を一覧表示するスクリプト

bash型の最初の文字でファイル名を一覧表示するスクリプト

ユーザーの入力を受け取り、表示するファイル名の最初の文字を指定して、指定された文字で始まるファイル名のみをリストするスクリプトが必要です。ファイルサイズとファイル名を印刷し、すべてを.txt一度にファイルに送信するだけです。

出力テキストを特定のディレクトリに移動するには、次のように指定します。 /ect/myscrpits/output.txt

これが私がこれまでにしたことです。

#!/bin/bash

if [ "$1" == " " ]
then
echo "Usage: Type a single letter at the end for a list of files that start with that letter. The list is sorted from largest to smallest."
echo "Example: ./bwalla_.sh a"

else
while
read letter
ls -l "$letter*" |awk '{print $5,$9;}' > bwalla_output.txt

fi 

ベストアンサー1

読み取り機能を使用してユーザー入力を受け取り、入力を変数に保存し、lsを使用して変数にファイルを表示します。

例えば

#!/usr/bin
echo "Type the letter: "
read letter
ls -l "$letter"* | awk '{print $5,$9}' > output.txt

おすすめ記事