I am trying to write a shell script that deletes a persistent but unnecessary folder in my home directory upon execution. So, I ask you fellow Ubuntu users, what is the terminal command to delete a file/folder?
40535
How do I delete the following directory?  I typed:  rmdir lampp   This error comes up:  rmdir: failed to remove `lampp': Directory not empty   Is there a command to delete all the files in the directory and delete the directory folder?
82660
Suppose I have a dir tree like this:  ROOTDIR     └--SUBDIR1         └----SUBDIR2             └----SUBDIR3   I am looking for a command such that when I input:  $ [unknown command] ROOTDIR   The whole dir tree can be deleted if there is no file but only dirs inside the whole tree. However, say if there is a file called hello.pdf under SUBDIR1:  ROOTDIR     └--SUBDIR1         └--hello.pdf         └----SUBDIR2             └----SUBDIR3   Then the command must only delete SUBDIR2 and below.
21282
I have a folder containing a lot of folders and different files with the following structures :  NASA │ ├── a │   ├── doc1 │   ├── doc2 │   ├── doc3 │   ├── folder1 │   └── folder2 │ ├── b │   ├── doc1 │   ├── doc2 │   ├── doc3 │   ├── folder1 │   └── folder2 │ ├── c │   ├── doc1 │   ├── doc2 │   ├── doc3 │   ├── folder1 │   └── folder2 │ ├─ x ├─ y └─ z          I want to delete the content of the folder (NASA/) except specified folders and files.   For example I want to keep a folder, b folder and x file.     I tried   :   rm !(a/) -r NASA/   And (as explained in the answer ):  find NASA/ -type f ! -iname "x" -delete   But this is not very straight forward and I have to use a bash script.    Am I missing a more easy way ? How can I do this in a single command?
68694
Before I run this, I want to make sure it is correct. I want to delete any .deb files. find /home/andy/.local/share/Trash/expunged/ -type f -exec rm *.deb  This works on all files except .deb files. #!/bin/bash find /home/andy/.local/share/Trash/expunged/ -type f -exec rm {} \; find /home/andy/.local/share/Trash/files/ -type f -exec rm {} \; find /home/andy/.local/share/Trash/info/ -type f -exec rm {} \;  And it works completely with UM 20.04.
89688
I want to make a bash script to delete the older file form a folder. Every time when I run the script will be deleted only one file, the older one. Can you help me with this? Thanks
74158
So, Im working in a UNIX environment and I noticed that inside my working directory, which is miles miles away from my UNIX home, there is a ~.  Now, once in the past, I did rm -rf ~ from my working directory and ended up erasing my home directory completely and had to involve IT.  I do not want to do it again. At the same time, I want to know   Why is ~ created in my working directory? Is it a faulty finger slip while saving (:w! but what happens is :w~ ?!!) Before checking in, there is a script that looks for extra files or folders that p4 is not aware so def this ~ might cause an issue. So how can I remove the ~ from my working directory and at the same time not erase my home?   I do have a backup command called del that I use instead of rm -rf. It just places stuff in a temporary location. I could use that and get rid of the ~. But I'm more interested in knowing why this happens, and how I can remove it?
121060
Quite often, we run an executable that needs to write / read some temporary files. We usually create a temporary directory, run the executable there, and delete the directory when the script is done.  I want to delete the directory even if the executable is killed. I tried to wrap it in:  #!/bin/bash dir=$(mktemp -d /tmp/foo.XXXXXXX) &amp;&amp; cd $dir &amp;&amp; rm -rf $dir /usr/local/bin/my_binary   When my_binary dies, the last process the kernel will delete the directory, as the script is the last process holding that inode; but I can't create any file in the deleted directory.  #!/bin/bash dir=$(mktemp -d /tmp/foo.XXXXXXX) &amp;&amp; cd $dir &amp;&amp; rm -rf $dir touch file.txt   outputs touch: file.txt: No such file or directory  The best I could come up with is to delete the temp directory when the process dies, catching the most common signals, and run a cleanup process with cron:  #!/bin/bash dir=$(mktemp -d /tmp/d.XXXXXX) &amp;&amp; cd "$dir" || exit 99 trap 'rm -rf "$dir"' EXIT /usr/local/bin/my_binary   Is there some simple way to create a really temporary directory that gets deleted automatically when the current binary dies, no matter what?
70861
How can I minimize the Terminal window using a command? For example: I use the clear command to clear the terminal output, which command can I have to use to minimize the terminal window?
54667
I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path.  if [[ $line =~ "$PWD"$ ]] ;then
124229
Sometimes I use, $PROJECT_HOME/* to delete all files in the project. When the environment variable, PROJECT_HOME is not set (because I did su and the new user doesn't have this environment variable set), it starts deleting all files from the root folder. This is apocalyptic.  How can I configure bash to throw error, when I use an undefined environment variable in the shell?
89258
I want to delete the content of a folder without deleting a folder: all files and all sub folders with sub files. This doesn't delete anything  sudo rm -rf /folder1/*   Why not? How to get it to work?
55610
I use terminal for almost all tasks. Let's say I have entered a huge command like this:  sudo a-huge-command   What is the easiest way to delete the whole command with a single shortcut, rather than keep on hitting backspace key?  I'm a Ubuntu newbie looking to use Ubuntu in a professional way.
20691
I have a directory that contains the following:  x.pdf y.zip z.mp3 a.pdf   I want to delete all files apart from x.pdf and a.pdf. How do I do this from the terminal? There are no subdirectories so no need for any recursion.
45158
How would one run a specific command for each file that was found by using the find command? For the purpose of the question lets say that I would simply like to delete each file found by find.
23805
What would happen if I delete the / directory while logged as root into Ubuntu?  Would I get some sort of error to the effect of Error: unable to self-destruct? Or would I actually be able to delete the directory?
74100
I am new to Ubuntu, and was wondering whether it is posible to open a terminal with a path matching your current location in the file manager? In Windows it was very easy, but how do you do it in Linux?
95051
I'm not sure what sudo apt-get autoremove does, but have read that you should use this command to remove any unnecessary packages.  One of the processes I saw was to use sudo apt-get autoremove and then use something like  to remove temp files etc.  Can you explain what sudo apt-get autoremove actually does and is there any advantages of using this command over something like BleachBit or  by themselves?