How do I remove all files except for a specific type?

Status
Not open for further replies.

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
Hi there! Here's my story:
I've got a FreeNAS that is 99% full and I need to clean it out. All of the data is kept in /media/Archive and I need to remove everything except all the .BAM files in that directory. What commands do I need to use in order to complete this action? I'm not sure if there are different subfolders or not. I'm using putty rightnow connect to it and unfortunately don't know many ubuntu terminal commands. Its running on build FreeNAS-9.2.1.2-RELEASE-x64 (002022c).
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
ubuntu terminal commands
Good, because no such thing exists (unless Ubuntu started including some weird-ass new default shell).

If there's only a handful of extensions you want to get rid of, try

rm -rf *."extension you want to get rid of"
 

Ericloewe

Server Wrangler
Moderator
Joined
Feb 15, 2014
Messages
20,194
Good, because no such thing exists (unless Ubuntu started including some weird-ass new default shell).

If there's only a handful of extensions you want to get rid of, try

rm -rf *."extension you want to get rid of"
Note: don't just blindly type that in. I'm assuming a minimum knowledge of Unix shells (heck, or even MS-DOS).
 

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
I think you misunderstood me. I'm looking to remove everything except one file type.
 

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
I can't even access the directory I need to get into.
 

Attachments

  • primbio freenas 02.png
    primbio freenas 02.png
    27.9 KB · Views: 279

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
Your media directory doesn't have anything in it. That's what ls shows you
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
If it is mounted at /media you have a bigger problem. Default mount point on FreeNAS is /mnt


Why are you logging in as Archive?

Oh boy this is going to be rough....
 

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
Well when I try to get to the media folder or the mnt as the root user I can't get to it.
 

Attachments

  • primbio freenas 03.png
    primbio freenas 03.png
    19.2 KB · Views: 250

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
Because you are typing the wrong path.

It's /mnt

You are not in / by default which means mnt doesn't exist in the directory you are in.....

Please take a minute to understand what you are doing. You are about to do a whole lot of irreversible damage..
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
If you've never used any *nix shell before, this isn't a good time for you to try to learn. Don't you have some other sort of access to that directory (i.e., is it shared via CIFS/AFP/NFS)? If so, connect to it over the network from a client machine and use that client's file manager (Windows Explorer, Mac's Finder, etc.) to handle the files.

I don't think your problem is that you can't access the directory you need; it's that you don't know what directory you need. That's going to be a problem.

If you absolutely have to do it from the command line, start by posting the output of 'ls /mnt/Vol01'.
 

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
Its shared as NFS shares called Archive01 & Archive02. Unfortunately the software that we use can only import stuff from the NFS shares. It won't deleted files hence why I was trying todo it in putty. If you guys have an easier way I'm all ears here and on a time crunch to resolve this (NOT THAT YOU GUYS AREN'T IN YOUR LIVES).
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504

SparkyTech

Cadet
Joined
Jul 9, 2015
Messages
6
Actually I figured out that I could access it using the NFS client in windows server but I'm not sure what the path should use. Would they be:

Archive01: mount -user:root -p:* \\archive01\media\archive *

Archive02: mount -user:root -p:* \\archive02\media\archive *

Or is it the IP of the FreeNAS then the media\archive path?
 

danb35

Hall of Famer
Joined
Aug 16, 2011
Messages
15,504
NFS mounts under *nix would be serverip_or_name:/path/to/directory, like this:
192.168.0.20:/mnt/tank/nfs_share

I have no idea how Windows borks that up.
 

rogerh

Guru
Joined
Apr 18, 2014
Messages
1,111
I don't know about windows NFS, but CIFS would be \\192.168.1.210\Archive01 and then navigate to the folders below that. It is a bit unclear what Archive01 and Archive02 are shares of. I agree that ls /mnt/poolname/ would be useful from Putty connected to the FreeNAS server, and perhaps some lower level listings.

Edit: please don't type rm -rf in putty until you have discussed exactly what you are going to type, done at least one auto-complete in typing the path, and preferably typed something like xrm -rf (which doesn't do anything) until you are absolutely sure it is ok to navigate back down the line and delete the x. And don't have any spaces in the path unless you are sure you need them and done other things to make them work as expected.
 
Last edited:

j_r0dd

Contributor
Joined
Jan 26, 2015
Messages
134
Code:
find /yourdirectory/ -type f -not -name '*BAM' -exec rm {}\;


Don't blame me for anything bad. Always test these things first.
 
Joined
Jan 9, 2015
Messages
430
Status
Not open for further replies.
Top