Terminal Delete MacOS – Remove All Files with Particular Name but Different Extensions

deletemacosterminal

I have a directory where I have the following set of files:

cheatsheetold.aux
cheatsheetold.log
cheatsheetold.out
cheatsheetold.pdf
cheatsheetold.synctex.gz
cheatsheetold.tex
cheatsheetnew.aux
cheatsheetnew.log
cheatsheetnew.out
cheatsheetnew.pdf
cheatsheetnew.synctex.gz
cheatsheetnew.tex

What I want to do is to remove all the cheetsheetold.

cheatsheetold.aux
cheatsheetold.log
cheatsheetold.out
cheatsheetold.pdf
cheatsheetold.synctex.gz
cheatsheetold.tex

without touching the cheatsheetnew

cheatsheetnew.aux
cheatsheetnew.log
cheatsheetnew.out
cheatsheetnew.pdf
cheatsheetnew.synctex.gz
cheatsheetnew.tex

I already had a look at this other question, but it didn't solve the problem as there is a complete set of extension for both file names

Best Answer

It was not stated in which shell (bash, fish, zsh, csh) you desire to use some sort of wildcard when removing files.

As bash is a prominent shell I state that it would be possible to simply use this command:

rm -- cheatsheetold.*

note that the wildcard * is used after the -- as to avoid any unindented mishaps by bash shell extensions

the command line env | grep 'SHELL' might show you the shell you use. I have also tested the command line in the more POSIX reduced dash shell.

I simply do not use any other shells (like csh and tsh or fish) so I cannot tell how globbing works there.

another way to get an idea which shell is running might be this ps -p $$ where the $$ should be the PID of the current process (the shell) and ps the tool to list processes limited to the PID of the current shell.

https://help.ubuntu.com/community/ShellGlobbing

Related Question