Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#374037 - 30/03/2023 20:23 rm -rf but suppress the file names?
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31599
Loc: Seattle, WA
Uncle google isn't helping with this one, perhaps my search terms are wrong.

Both of these two command variants print too much information. In some cases it's printing so many file names that it slows down the output. All I really need to see is the total number of files deleted (even if it's zero). Does anyone know if there's a way to do that with the RM command?

Code:
dir=/c/Users/vmAdmin/front-end-build/caches/*
echo Cleaning $dir;rm -rfv $dir;echo Cleaned $dir;echo


Code:
dir=/c/Users/vmAdmin/front-end-build/caches/*
echo Cleaning $dir;rm -rf $dir;echo Cleaned $dir;echo
_________________________
Tony Fabris

Top
#374038 - 30/03/2023 20:57 Re: rm -rf but suppress the file names? [Re: tfabris]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14494
Loc: Canada
The 'v' (verbose) flag is what is causing the names to be printed. Just get rid of the 'v'.

Top
#374039 - 30/03/2023 21:05 Re: rm -rf but suppress the file names? [Re: tfabris]
Tim
veteran

Registered: 25/04/2000
Posts: 1526
Loc: Arizona
Could you count the files in the directory before deleting them?

Something like:
Code:
echo "Cleaning $dir"; ls $dir |wc -l; rm -rf $dir; echo "Cleaned $dir"

Top
#374040 - 30/03/2023 21:26 Re: rm -rf but suppress the file names? [Re: tfabris]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14494
Loc: Canada
Since the -r flag is also being used, rm will nuke subdirectories too. So to get an accurate count of actual FILES to be deleted, one could do this before the rm command:

find . -type f | wc -l

Cheers

Top
#374041 - 30/03/2023 21:46 Re: rm -rf but suppress the file names? [Re: mlord]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31599
Loc: Seattle, WA
Originally Posted By: mlord
The 'v' (verbose) flag is what is causing the names to be printed. Just get rid of the 'v'.


When I tried it, it merely formats the filenames a little differently when I remove the V.
_________________________
Tony Fabris

Top
#374042 - 30/03/2023 21:54 Re: rm -rf but suppress the file names? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31599
Loc: Seattle, WA
Weird, now trying it again, it seemed to NOT print the file names when I removed the V. Maybe it's due to different systems.

I'm doing all of this through the "Git Bash" prompt on some Windows systems, maybe the behavior differs.
_________________________
Tony Fabris

Top
#374043 - 30/03/2023 22:09 Re: rm -rf but suppress the file names? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31599
Loc: Seattle, WA
Aha, I see my problem. Bad syntax, it was the echo command that was printing all the directories, not the RM command.

dir=/c/Users/afabris/Desktop/testfolder/*
echo Cleaning $dir;

That prints a list of the directories inside testfolder. Not sure why "dir" isn't just a string there, apparently that's an aspect of Bash that I didn't understand before.
_________________________
Tony Fabris

Top
#374044 - 31/03/2023 01:05 Re: rm -rf but suppress the file names? [Re: tfabris]
mlord
carpal tunnel

Registered: 29/08/2000
Posts: 14494
Loc: Canada
A bash command line can look like this:

VARxyz=1234 command arg1 arg2 ...

So when you do this:

dir=/c/Users/afabris/Desktop/testfolder/*

You are really doing this:

dir=/c/Users/afabris/Desktop/testfolder/file1 /c/Users/afabris/Desktop/testfolder/file2 /c/Users/afabris/Desktop/testfolder/file3 ...

So.. "/c/Users/afabris/Desktop/testfolder/file2" is the "command" and "/c/Users/afabris/Desktop/testfolder/file3"... are the args..

Neat, eh! smile

Do this instead:

dir="/c/Users/afabris/Desktop/testfolder/*"

Top