Search code examples
ls

How do I list all files but only show the fist N characters of the filenames?


How do I list all files but only show the fist N characters of the filenames?

for example if the filname was ABC_2015-01-03-08-00-35.csv in the directory and then I done a ls in that directory I would only get this LTE_2015-01-03 the 1st 14 characters.

I'm thinking I would use the ls command but not sure after that?


Solution

  • You can use cut to do it for you like so:

    ls | cut -c1-14
    

    I'm assuming you don't care about extensions or the like.