Tuesday, December 23, 2008
List only file and not directory - ls command
Not sure if "ls" offers any standard option to list only file names and not the directories.
Some of the ways I found useful to list only files and no directories in my current directory.
Using find:
$ find . -type f -maxdepth 1
And if you want to avoid the hidden files.
$ find . -type f -maxdepth 1 \( ! -iname ".*" \)
And one more way derived from "ls -l" output
$ ls -l | awk 'NR!=1 && !/^d/ {print $NF}'
Please provide any alternatives if you have for the same (Please post in the comment section). Thanks.
Labels:
awk newbie,
bash shell newbie,
find command,
Linux Commands,
linux ls
Subscribe to:
Post Comments (Atom)
© Jadu Saikia www.UNIXCL.com
11 comments:
I often use "ls -l | grep -v ^d" to list only files.
@Max, ya that's one more way. Thank you.
nice tips
thanks
Bookmarked
@Dedy, you are welcome, thanks :-)
And to list only directories and no files, -d option of ls can be used.
I use "ls -l | awk '/^-/ {print $NF}'" to list without symlinks.
Ah, excellent. Way better output than `tree` or `ls -lAR`. Came in useful while trying to find a way to list changed files recursively: `find . -type f \( ! -iname ".*" ! -ipath "*.svn*" \) -newerct '5 minutes ago'`
ls -d */
Done
/bin/ls -ld .//./* |\
sed -n '
:outer
/^-/!d;s|\.//\./||
:inner
p;$d;n
//!binner
bouter
'
Post a Comment