How Linux uses the shell to view all files in the directory and its subdirectories

  
                

In Linux system, in addition to PHP can view the file directory, the shell command can also perform some operations on the file directory. Today, Xiaobian will share with you how to use the shell command to view the directory and its subdirectories. All files.

Use the shell command to view the files in the directory and all subdirectories method:

shell recursively traverse directories

#! /bin/bash

echo “please input the directory:”

read cdir

for dir in $(find $cdir -type d); do

echo change to $dir

cd $dir

ls

echo “----------”

done

cd $cdir

Record a script that traverses all subdirectories and their files under the directory today.

#! /bin/sh

read -p “Input Path:>SPATH

FILELIST() {

filelist=`ls $SPATH`

For filename in $filelist; do

if [ -f $filename ];then

echo File: $filename

elif [ -d $filename ];then

#echo Directory: $filename

cd $filename

SPATH=`pwd`

echo $SPATH

FILELIST

cd . .

else

echo “$SPATH/$filename is not a common file.”

fi

done

}

cd $SPATH

FILELIST

echo “Done.”

Implement traversal of directories and their subdirectories by defining a function.

Now Linux users know how to use the shell command to view all the files in the directory and its subdirectories. If you don't know the user, please refer to the above steps.

Copyright © Windows knowledge All Rights Reserved