• Home
  • SEM
    • PPC
    • SEO
    • How To
  • Bangladesh
  • School
    • HTTP
    • REP
    • Bots n’ htaccess
    • Source Code
    • Excel 2010
    • HTML XHTML Entities
    • Gmail Operators
    • HTML & ASCII
  • About
    • Privy
    • About This Blog
  • Contact
  • বাংলা

Saidul Hassan

Digital Marketing Evangelist

Home / Bangladesh / How to get a directory listing of all the files beginning with “certain” character(s)

How to get a directory listing of all the files beginning with “certain” character(s)

25 Jun, 2021 By Saidul Hassan · Filed Under: Bangladesh

To list all the files with the .png extension in the dir
ls | grep '\.prj$' | wc -l

Parsing the output of ls is unreliable because ls mangles unprintable characters. Here is a fully reliable way of counting the files matching a certain extension. This shell snippet creates an array containing the file names, then prints the number of elements in the array.
a=(*.prj)
echo ${#a[@]}

Source:http://askubuntu.com/questions/217742/list-files-of-particular-extension

How to get a linux directory listing for files beginning with a certain letter that doesn’t descend into subdirectories?
Suppose you are in a directory that contains many files and many subdirectories.
You want to get a directory listing of all the files beginning with “Screen”. How do you list only the files and directory names in your current directory?
You type ls -d Screen*
Additionally, ls -d Screen*/ will only show the directories.

Another interesting solution with the flexibility of regular expressions be:

ls | grep ^Screen

however, if you add additional parameters to ls it will break. E.g. “ls -l | grep ^Screen” , but not all parameters. ls -a | grep "^\." would print all “hidden” files.

ls -ld: It will give the list of directories, without descending into subdirectories.
Example:

ls -ld Screen*
This command will provide a listing of the files and directories which start with Cust.

Source:http://superuser.com/questions/25910/how-to-get-a-linux-directory-listing-for-files-beginning-with-a-certain-letter-t

Link to this post!
The following two tabs change content below.
  • Bio
  • Latest Posts
My Twitter profileMy Facebook profileMy Google+ profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Saidul Hassan

Managing Partner at Up Arrow Consulting
COO at Up Arrow Consulting, MCC manager, & Technical SEO consultant. Certified Google Partners and Microsoft Bing Ads Accredited Professional, Python enthusiast, wannabe SysAdmin. Graduated from School of Management & Business Administration (SOMBA), Khulna University.
My Twitter profileMy Facebook profileMy Google+ profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Latest posts by Saidul Hassan (see all)

  • Batch script to create directories & moving fixed number of files to those directories - 30 Apr, 2021
  • How to use PrismJS syntax highlighter on WordPress without plugin - 30 Mar, 2020
  • Download an Entire Website for Offline Viewing - 26 Nov, 2019

Share:

  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Pocket
  • Email
  • Print

First published on 24 Jun, 2015 · Last updated 25 Jun, 2021 ·

Batch script to create directories & moving fixed number of files to those directories

30 Apr, 2021 By Saidul Hassan

How to use PrismJS syntax highlighter on WordPress without plugin

30 Mar, 2020 By Saidul Hassan

Download an Entire Website for Offline Viewing

26 Nov, 2019 By Saidul Hassan

How to color highlight .htaccess files in Xed/Gedit

20 Aug, 2018 By Saidul Hassan

HMA Pro VPN Setup for Multiple Locations without User/Password Every time in Linux CLI

14 May, 2018 By Saidul Hassan

  • ♥ Bangladesh ♥
    Log in · Privacy Policy · Contact
    Copyright © 2011 Saidul Hassan

  • DMCA

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.