Date Tags Linux

Recently, I needed to clean a large list of folders out of a directory while leaving behind some others. Normally, I do most of my deleting on remote servers through a graphical file browser like WinSCP (Windows) or Cyberduck (Mac). I do it this way because I believe that certain tasks are easier done through a gui where we can let our mind's visual/spatial reasoning take over. I also want to avoid a situation where I delete a production servers entire filesystem because of command line syntax mistake on my part!

I couldn't do it this way though as I had not created this server and I could only delete directories using sudo. I also could not login as root or switch to the account that had created the files.

So, what to do I thought?

I thought about creating a Python script but decided against it because I had just finished a few hours of coding. I then figured out this hacked up solution which actually worked fairly well.

  1. Get a list of the folder/file names and put them into a text file named filesToDelete.txt. There are several ways to do this but I happened to be on a PC that day and WinSCP had a handy feature to copy selected filenames to the clipboard. I then had to use nano to create the file over the command line by copy/paste since I couldn't save any files through WinSCP because I would need to use sudo.

    Example view inside file:

    folder1 folder1 folder3 folder4 folder5
    
  2. Some googling lead me to uncovering this command to get what I wanted:

    sudo rm -r $(cat filesToDelete.txt)
    

Comments

comments powered by Disqus