I need to list all csv file in a directory and I have to goole how to do it every time I need it. So I’ll write a post to remind myself.
find . -maxdepth 1 -name "*.csv"
Since I only want to list file in current directory not any sub directory. I have to use the maxdepth flag, as find is recursive by default. But there is one small issue with this, that is a “./” will be in the output. If I want to send the output to another program the “./” might cause issues.
Sample output with leading “./”
./dirty2.csv
./clear.csv
./dirty.csv
find . -maxdepth 1 -name "*.csv" | sed "s/^\.\///"
We can use sed to remove the “.\” in front of those csv files. We have to escape the “.” and the “/”.
Sample output without leading “./”
dirty2.csv
clear.csv
dirty.csv