Quantcast
Channel: Count number of files that are not symbolic links in output from "locate" - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 5

Answer by Kusalananda for Count number of files that are not symbolic links in output from "locate"

$
0
0

Rather than parsing the output of locate (which is fragile and may miss things that have changed since its database was last updated, or that are not available to all users), use find.

The following will find all .c files in the current directory that are regular files (not symbolic links):

find . -type f -name '*.c'

Given the directory structure

.|-- file-a.c|-- file-b.c|-- file-c.c|-- file-d.c|-- link-b.c -> file-b.c`-- link-d.c -> file-d.c

This would return

./file-a.c./file-b.c./file-c.c./file-d.c

To count them:

find . -type f -name '*.c' | wc -l

or, if you have filenames with newlines in their names,

find .//. -name '*.c' -type f | grep -c //

Doing the same for symbolic links would involve changing the -type f to -type l.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>