Score:-2

On ubuntu while using JavaScript, what command should I enter to delete my files having a common name in them? You can also use wildcards to help me

tn flag

For example, I have four files with the names as "one-beta.txt" , "one-alpha.txt" , "two-beta.txt" , "three-gamma.txt". Now I am supposed to delete my files with the name "beta" in them.

Score:0
aw flag

I am a little confused with the question.

Do you have files in a folder and would like to run a command that deletes all the files in the folder with the name beta?

if so, "rm" is your friend. I am not a big linux or ubuntu person, however, rm have been my friend for a while.

rm beta*.txt

will delete all your files that has beta and ends with txt.

If you are developing a javascript program to delete a file, then it may be a little more involve. I don't currently have that skill but you have to use javascript filereader, and check if files exist, find the files you want to delete then delete them. check out https://javascript.info/file. You can also find additional training on javascript at https://www.w3schools.com/js/default.asp.

Mamoona avatar
tn flag
Brother I have to delete files that are in more than one directories with the common name having beta in them just like I described in the body of my question that I have four files having names "one-beta.txt" , "one-alpha.txt" , "two-beta.txt" , "three-gamma.txt". Now what command should I enter so that I would be able to delete all files in all the subdirectories of my pwd. Is there any such command?
Steven Keller avatar
aw flag
the file names are different so you have to start by running the following command one at a time as root. and be careful. First try the following: **"find . -name *-beta*.txt -type f"** ( "-type f", will list all the files) so you can change the -name to reflect *-alpha, *.gamma* etc, once you are satisfy, then add -delete to delete the files you find. finally you can type **"find /folderpath/*-alpha*.txt -type f -delete"** or **"find . -name *-beta.txt -type f -delete"** ( using path to the folder, speeds up the search) good luck "with great power, comes great responsibilities"
Mamoona avatar
tn flag
Thanks a lot. I have successfully done my task with the following code "find /path/to/your/directory -type f -name '*-beta.txt' -delete" I am posting for anybody else who is facing the same problem
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.