Results 1 to 6 of 6
G'day everyone,
I'm having trouble figuring out how to list the contents of a directory and exclude any subdirectories.
Currently I have:
Code:
ls --width=1 ${FILEDIR}/ | grep -v '^Thumbs.db' ...
- 08-02-2010 #1Just Joined!
- Join Date
- Jan 2010
- Location
- Sydney, Australia
- Posts
- 51
ls exclude directories
G'day everyone,
I'm having trouble figuring out how to list the contents of a directory and exclude any subdirectories.
Currently I have:
The output is the correct format, any help someone can give me with this would be awesome.Code:ls --width=1 ${FILEDIR}/ | grep -v '^Thumbs.db' $1 > ${FILES}
Cheers,
Griffo
- 08-02-2010 #2Just Joined!
- Join Date
- Jan 2010
- Location
- Sydney, Australia
- Posts
- 51
I'm sorry, I meant to take the variables out when I posted to make it a little easier to read. When the script runs, it uses the values below.
Code:ls --width=1 /mnt/ | grep -v '^Thumbs.db' $1 > files.txt
- 08-02-2010 #3Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
Not sure ls can do that (I've never mmanaged to make it do it), but this should work
Code:find /mnt -name "*" ! -type d -maxdepth 1 -printf "%f\n"
In a world without walls and fences, who needs Windows and Gates?
- 08-02-2010 #4Just Joined!
- Join Date
- Jan 2010
- Location
- Sydney, Australia
- Posts
- 51
Thanks for the reply, it works and it is the correct format to use in my script. But...when I pipe or direct the output to another program or file I receive an error on my display even though the file I'm creating is fine. Using the command you provided, I've added grep to strip Thumbs.db from the list.
The error I get is:Code:find /mnt -name "*" ! -type d -maxdepth 1 -printf "%f\n" | grep -v '^Thumbs.db' $1 > files.txt
I'm not sure if the version of find is an issue here, I'm using Debian Lenny (but will soon be upgrading to Squeeze).find: warning: you have specified the -maxdepth option after a non-option argument -name , but options are not positional (maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments.
It would be great if I could get rid of this error message, any ideas you have would be greatly appreciated.
Cheers,
Griffo
- 08-03-2010 #5Linux Newbie
- Join Date
- Sep 2004
- Location
- UK
- Posts
- 160
try
I get the same error/warning message if the find returns no results, the above seems to fix/(get rid of) it.Code:find /mnt -maxdepth 1 -name "*" ! -type d -printf "%f\n"
In a world without walls and fences, who needs Windows and Gates?
- 08-03-2010 #6Just Joined!
- Join Date
- Jan 2010
- Location
- Sydney, Australia
- Posts
- 51
Perfect, that's exactly what I was after. I piped it to grep and sent the output to a file and no error message.
Thanks mate,
Griffo


Reply With Quote