1847583 Members
3305 Online
110265 Solutions
New Discussion

Listing files

 
Pando
Regular Advisor

Listing files

I have the files with the following pattern:

(1.) Device_time_batch.txt
(2.) Device_time_batch.txt

where: batch = 4 digit number
prefix = GS or anything

I need to list all devices only with batch and exclude / delete batch with prefix.

Maximum points to all correct replies!
4 REPLIES 4
Marcel Boogert_1
Trusted Contributor

Re: Listing files

Hi there,

$ ls -l Device_time_????.txt

Regards, MB.
Marcel Boogert_1
Trusted Contributor

Re: Listing files

Hi again,

to remove the files with prefix use something like:

$ find . -type f -name 'Device_time_??????.txt' -exec rm {} \;

Regards, MB.
Sridhar Bhaskarla
Honored Contributor

Re: Listing files

Hi Fernando,

Try simple find before you add 'rm' to it. Good thing is that you have "_" as the seperator so you may not have to worry too much.

find /directory -name "Device_time_[0-9][0-9][0-9][0-9].txt"

Assuming that your time doesn't include a "_" in it.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Gerhard Roets
Esteemed Contributor

Re: Listing files

Hi Fernando

The first thing i would do before
$ find . -type f -name 'Device_time_??????.txt' -exec rm {} \;
that is to
$ find . -type f -name 'Device_time_??????.txt' -exec echo {} \;

Just as sanity sake to see what i will be impacting.

HTH
Gerhard