Question

I am currently trying to remove a number of files from my root directory. There are about 110 files with almost the exact same file name.

The file name appears as wp-cron.php?doing_wp_cron=1.93 where 93 is any integer from 1-110.

However when I try to run the code: sudo rm /root/wp-cron.php?doing_wp_cron=1.* it actually tries to find the file with the asterisk * in the filename, leaving me with a file not found error.

What is the correct notation for removing a series of files using wildcard notation?

NOTE: I have already tried delimiting the filepath with both single ' and double quotes ". This did not avail.

Any thoughts on the matter?

Was it helpful?

Solution

Take a look at the permission on the /root directory with ls -ld /root, typically a non-root user will not have r-x permissions, which won't allow them to read the directory listing.

In your command sudo rm /root/wp-cron.php?doing_wp_cron=1.* the filename expansion attempt happens in the shell running under your non-root user. That fails to expand to the individual filenames as you do not have permissions to read /root.

The shell then execs sudo\0rm\0/root/wp-cron.php?doing_wp_cron=1.*\0. (Three separate, explicit arguments).

sudo, after satisfying its conditions, execs rm\0/root/wp-cron.php?doing_wp_cron=1.*\0.

rm runs and attempts to unlink the literal path /root/wp-cron.php?doing_wp_cron=1.*, failing as you've seen.

The solution to removing depends on your sudo permissions. If permitted, you may run a bash sub-process to do the file-name expansion as root:

sudo bash -c "rm /root/a*"

If not permitted, do the sudo rm with explicit filenames.

OTHER TIPS

Brandon,

I agree with @arkascha . That glob should match, so something is amiss here. Do you get the appropriate list of files if you use a different binary, say 'ls' ? Try this:

ls /root/wp-cron.php?doing_wp_cron=1.*

If that returns the full list of files, then you know there's something funny with your environment regarding rm. This could be an alias as suggested.

If you cannot determine what is different or wrong with your environment you could run the list of files through a for loop and remove each one as a work-around:

for file in `ls /root/wp-cron.php?doing_wp_cron=1.*`
do
rm $file
done
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top