
特定のディレクトリ内のファイルが必要で、次のスクリプトを使用します。
echo "give name of directory: "
read directory
if [ -d "$directory" ]
then
echo "thanks again"
else exit
fi
find /-type f $directory
残念ながら、これは機能しません。
答え1
find $directory -type f
サブディレクトリを含む、そのディレクトリ内のすべてのファイルを検索します。
答え2
私は推測しますが、おそらくこれがあなたが望むものでしょう:
echo "give name of directory: "
read directory
if [ -d "$directory" ]
then
echo "thanks again"
else
exit
fi
find $directory -type f
find
ルートディレクトリ/を見ました。
答え3
コマンドがfind
正しく書かれていません。
find /-type f $directory
しなければならない:
find "$directory" -type f
このfind
コマンドは再帰的です。正確な特定のディレクトリ内のファイルにのみ興味がある場合は、次を使用します。
find "$directory" -maxdepth 1 -type f
最後に、より簡単なバージョンを追加してください。
echo "give name of directory: "
read directory
if [ -d "$directory" ]
then
echo "thanks again"
find "$directory" -maxdepth 1 -type f
fi