How to Delete a File via SSH

86 views
Skip to first unread message

Daniel Taylor

unread,
Apr 21, 2021, 8:59:39 AM4/21/21
to Brennan Forum
I have identified a bad music file on my B2's HDD.  When I try to delete it either via the WebUI or NAS, it fails and the B2 goes into HDD Read Only mode.  Before I resort to removing the HDD and connecting it to my computer, I'd like to take a shot at deleting the file over SSH. I have Putty installed on my computer and I've used it only to the point of connecting to the B2.  But that was well over a year ago.

Once I have an SSH connection, I don't know the commands to navigate and locate the file and then how to delete it.  I've searched the forum, but that specific info may be too far back in time to be easily located.  Would one of you who is familiar with the R.Pi/Linux command set please post and help me out?

Peter Lowham

unread,
Apr 21, 2021, 9:49:43 AM4/21/21
to Brennan Forum
Hi Daniel,

When you log in via Putty you will be at a # prompt.  the 'cd' command is 'change to directory';  'ls -la' lists the directories and files in the directory.

#pwd       (print working directory displays the current active directory)
/root       (this indicates that you are in your 'root' diectory)
#cd /media/hdd1/music     (this will take you to the B2's 'music' directory & note the leading / in front of media)
#pwd
/media/hdd1/music       (just to check that you are in the correct directory!)
#ls -la    (lists the contents of the directory, this will list all of the artist folders)

List of artists

#cd 'Eric Bibb'    (This places you into the artist directory; I have used Eric Bibb to show that if the directory name has spaces in it you need to use single quotes; note no leading / this time)
#ls -la          (you will see a list of this artist's albums)

List of albums

#cd '<Albumname>'       (Substitute the album name for your album and use single quotes around the album name)
#ls -la            (you will see the list of album tracks and the bad track should be in this list)

List of tracks

#rm '03 - Shine On.flac'     (rm is the delete command; use single quotes and you need to match upper and lower case and spaces and dashes exactly)
#ls -la     (check that the track has been deleted)
#cd ..      (takes you up one directory level)

When you are done, then

#exit    (to log out of Linux)

Let me know if any of this is confusing and I'll try to clarify!

Regards,
Peter.

Daniel Taylor

unread,
Apr 21, 2021, 10:23:39 AM4/21/21
to Brennan Forum
Peter, Thank You!  That is a wonderful tutorial in exactly what I need for the task at hand.  That's going into my notes for sure.  You even clarified some things that I had not thoought of yet, but would certainly have come up.  Big thanks!

Peter Lowham

unread,
Apr 21, 2021, 11:24:11 AM4/21/21
to Brennan Forum
Hi Daniel,

No problem, I hope that this works for you.  It should do; I recently had two tracks that had corrupted filenames that would not not delete at GUI level but 'rm' blitzed them, so all was well. 

Regards,
Peter.

Daniel Taylor

unread,
Apr 21, 2021, 12:47:40 PM4/21/21
to Brennan Forum
The commands I learned from you allowed me to navigate to where I needed to go, and then I could delete the bad file.  However, when I tried to copy a good version of that same file to replace the bad one, I got a "write only" error.  I'm sure that at the Linux command line level, that's the equivalent to the B2's Read Only mode.  I don't know what triggered that, but after rebooting, I was able to copy the file over via NAS.  Then after a Scan Disk, the track appeared in the WebUI and played okay.  Looks like it's back to normal.  Now to try that Export again.

Peter Lowham

unread,
Apr 21, 2021, 1:16:22 PM4/21/21
to Brennan Forum
Hi Daniel,

 'Write only' is one Linux level access permission status.  Every directory or file has three permission flags 'Read'' 'Write' and 'Execute' and you can have any combination of these..  So in the attempt to copy the file, Linux has found that your 'user' does not have permission to 'read' the file.  I must say that is is unusual as in your situation as you logged in as 'root' which has 'superuser' privileges and will normally be able to 'override' these permissions. 

It would take a deeper level analysis to understand why this happened.

@Mark F; Mark, if you see this, can you comment?

Regards,
Peter.

Daniel Taylor

unread,
Apr 21, 2021, 1:53:48 PM4/21/21
to Brennan Forum
In retrospect, I think I probably remembered the error condition wrong.  It might have said "Write Access Denied" or similar.  In my case, "write only" makes no sense, since I was trying to write to the disk.  <headslap>

Mark Fishman

unread,
Apr 21, 2021, 2:43:05 PM4/21/21
to Brennan Forum
"write access denied" would correspond to read only -- which would be very odd, since you were able to delete the bad file... You have to write to a directory to delete an entry in it.

Try a reboot. Then, if it happens again, I want to see the output from ls -la in that directory. Maybe the mode bits and owner/group info will tell us something.

Daniel Taylor

unread,
Apr 21, 2021, 4:45:32 PM4/21/21
to Brennan Forum
The circumstance has passed.  I'm happy to think that I just got the message wrong by not paying enough attention.  The problem is fixed and I'm able to play the replaced song and the rest of the album too.
Reply all
Reply to author
Forward
0 new messages