list only files in current directory
i need to figure out how to list only the files in a current dir
e.g. say i'm in /tmp in /tmp there is /sub1 /sub2 file1 file2 file3 i need to know how to use either find /tmp -type f or ls to list only the files in /tmp - not the sub-dir's or their contents on the output just file1 file2 file3 how do i do this? tia |
ls
This is the command to list files in any given directory. Cool |
yeah, but it also lists the directories. I need a switch or a way to list the files, and only the files in a given directory. I need this to use the output as a variable in a script.
files=`find ${DIR} -type f ` for files in ${files} do " i need to know how to use either find /tmp -type f or ls to list only the files in /tmp - not the sub-dir's or their contents" |
I see ;) I don't know how easy that'll be as Linux sees both Files and Directories all as Files. I'll move this to Programming as it's not related to Redhat, and you'll likely get a better response there.
Moving to Programming Cool |
What about just:
ls -a|grep -v "/" |
Quote:
I suppose this would do it fo you ls -l | grep -v "^d" | awk '{print $9}' or if you want to eliminate even links n other stuff and want only regular files.... then this should do it for you ls -l | grep "^-" | awk '{print $9}' |
how about a little bash script?
Code:
#!/bin/bash |
find . -type f -maxdepth 1 -print
|
excellent - thanks alot for all the suggestions - gave me some great insight
|
All times are GMT -5. The time now is 09:01 AM. |