I wanted to list down all the filenames within a folderA and another folderB inside folderA and saved it to a text file. The code I used is:ls -1 /home/CSV_XXX/* | grep ^'/home/CSV_XXX' >/home/Lists.txtSuppose I've a folder named CSV_XXX in the directory '/home/CSV_XXX' & inside it contains:20161010BDL_EXISTING_CARDS2_20161228.CSVBDL_EXISTING_COLLATERAL_20161228.CSVBDL_EXISTING_CUST_ADDRESS_20161228.CSV...'20161010' is a folder inside CSV_XXX with the directory '/home/CSV_XXX/20161010' & contains:BDL_EXISTING_CARDS2_20161010.CSVBDL_EXISTING_COLLATERAL_20161010.CSVBDL_EXISTING_CUST_ADDRESS_20161010.CSV...However, I couldn't get what I want.During my first attempt, I got:/home/CSV_XXX/BDL_EXISTING_CARDS2_20161010.CSV/home/CSV_XXX/BDL_EXISTING_COLLATERAL_20161010.CSV/home/CSV_XXX/BDL_EXISTING_CUST_ADDRESS_20161010.CSV.../home/CSV_XXX/20161010:without the list of what's in the folder 20161010Also, how can I remove the directory '/home/CSV_XXX/' if I change my mind to remove it in my list?just the lists (including 20161010):BDL_EXISTING_CARDS2_20161228.CSVBDL_EXISTING_COLLATERAL_20161228.CSVBDL_EXISTING_CUST_ADDRESS_20161228.CSV...
How to grep the all filenames in folderA and (folderB inside folderA)?
grep;ls;filenames;string
You may be better using the find commandegfind /home/CSV_XXX -type f -printwill list all the files in all the directories recursively under the CSV_XXX directory.If you only want files matching a pattern then you can do something likefind /home/CSV_XXX -type f -name '*.csv' -printand that will only print filenames ending in .csvIf you want to include directories in the list then just skip the -type f part.To remove the directory prefix;( cd /home/CSV_XXX ; find * -type f -name '*.csv' -print )