Episode: 3427 Title: HPR3427: Ranger for the Win! Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr3427/hpr3427.mp3 Transcribed: 2025-10-24 23:11:08 --- This is Hacker Public Radio Episode 3427 for Tuesday, the 21st of September 2021. Today's show is entitled, Ranger for the Win. It is hosted by BDUZ and is about 18 minutes long and carries a clean flag. The summary is, in this episode, I go over some typical use cases for the Ranger File Manager. This episode of HPR is brought to you by an honesthost.com. Get 15% discount on all shared hosting with the offer code HPR15. That's HPR15. Better web hosting that's honest and fair at an honesthost.com. Hello Hacker Public Radio fans, this is Be Easy once again. I promised the episode, and here I am. This one is a use case in using Ranger, so I was waiting for the opportunity when I do something that I have to do with some backup of some client data. I have done it a couple of different ways, one of them writing a script that will do it, and I can write it in Python, write it in Bash, but for this week I wanted to do it in Bat and using Ranger because it is really great and it really shows you a lot of what you can do with Ranger, and so the use case is I have multiple directories on my local drive, and I want to take them, zip them, and put them on another external USB hard drive. And so like I said, there's lots of ways to do this, but an interactive way is using Ranger, which is a great command line file management program. So I am in the directory of where the files go. I'm just going to go in here and type Ranger, and it gives me, I don't do it half screen, so I can see everything. So it gives me three panels, the one to the farthest left is the previous folder. So like the parent folders, files and folders, the middle one is the current files and folders, and then to the right is a preview of what is highlighted currently. So if I am currently have a directory highlighted, it's going to show me what is inside of that directory. If I have a file highlighted, it's going to show me what is in that file, and there's lots of different built-in plugins called scopes that are used to view those files, and you can make your own. And so I have a previous episode called Converted to Text, and I use a lot of the programs inside of my Converted to Text episode as custom scopes to be able to view different file types. So if I highlight over like a JPEG, it'll, depending on what setting I have it on, it either show me a ASCII art version of that picture, or it'll show me inside of the, inside of the actual terminal, an actual picture, depending on what terminal you're using, and if you have the setting on. If I go over any type of text file, it'll look to see if it's a file that it recognizes. If it is, it'll try to use highlighting on it, and using the highlight command line tool. If it's a PDF, it'll use, and you have pop-up popular utils installed. It will do a read, like a PDF to text, and put it on the screen for you. I added a little part from the original config to say dash dash layout, so that it'll preserve the layout of the original PDF inside of the ASCII art. So it's really easy to go through a bunch of list of files going up and down and seeing what's inside of those files. And so like I said, use case number one is what we're going to work on right now. And so like I said, I have a folder open right now that is the root directory of where I want to find everything. I'm going to do Alt 2. It's going to open a second tab. By default, it opens that second tab in the same place where you already are. So now I'm going to go back and I'm using them binding some using H to go back. And I can also use the arrow keys if I want to. So I can use the arrow keys to go over to and then go over to my slash media folder where you know, it auto-mounts stuff. So I am going to go media to that device to the client folder. And then so now I'm in the client folder. So now if I do Alt 1, it'll bring me back to tab 1. If I do Alt 2, it'll bring me to tab 2. So it can easily go between the two tabs. So now I'm back at tab 1. I'm going to go to the process folder. And there's a bunch of files in there. A bunch of CSV files, if I go to Alt 2, I'll go inside the process folder. How do I have them lined up in there? Oh, it's just a bunch of CSV files and all I do is turn them into GZIP files. So what I'm going to do is I'm going to press V, which is going to highlight all of this like a select all. And then I'm just going to do exclamation point, which brings up a shell. And you'll see at the bottom of the command it says Shell. And I'm just going to do space. And I'm just going to say GZIP. And then percent sign S. And percent sign S means the selected. And so I'm just going to do that click Enter. And now all those files just turning to the GZ CSV files. Now I'm just going to do V again, which is going to highlight all of them. And then DD, if you know your Vim bindings DD means cut. And then I'm going to do Alt 2. I'm inside that process folder on the other and in the other hard drive now. Pp if you know what pp does it pace pp puts all those files in there. So now I just without having to do any commands, but also not using a GUI with inside GZIP to all the files. And then move them into another folder and another hard drive. So I do control one again, not control, but just Alt 1 again. I can do the same thing for the other folders that have another thing you can do instead. So I have one folder where I will instead of just GZIPing I will actually put all of them into a zip folder first. So I can go I can go colon and then just type in MK there. And then the dirt name, which is going to say this was for August. I'm going to do 08. And now it just made it, oops, accidentally. I'm going to delete it. I called it, I had fat fingers and I added extra character at the end. So let me just go do they get colon MK there, 08. And now I've made it. So now if I just go V again, it's going to highlight everything, but I don't want to highlight 08. So I press space to title the selection. Now I can go DD, go into the 08 folder, PP, and then go back out to where the 08 folder is and have it selected and just go exclamation point. So it brings up Shell. And I want to say Shell, what I want to do, I want to do zip zip. And I'm going to say dash R. And so I'm just using command line now. And I want to say percent S dot zip. And percent S. So what that's going to do is going to do is going to file the the zip command. So zip dash R means recursively going to this folder and zip everything into the file called it's going to be called 08.zip because I just said the percent S, which is that selected file name or that selected items name and then space and then percent S, which is that same term. So if you're doing this on the command line, you would be doing, I would be doing zip dash R 08.zip space 08. And when I click enter on there, it gzips that whole folder. And now everything, there's a 08.zip and there's still a 08 folder as well. Now there's two different things I could do to get rid of that 08 folder. I could have inside of that command, I could have done colon and then or and then I could have done ampersand ampersand and remove. But you know, sometimes you don't want to remove it right away. And but now that I haven't done that, there's two different things I could do. If I have it selected and I do colon delete, delete actually deletes. But if I have the the trash CLI command installed and I click the Dell button on my keyboard, it will put that item in my trash can instead of actually deleting it permanently off the computer. And so if that's something that you're into, go ahead and you can do Dell. I'm going to leave mine with straight delete. So that's another thing you can do. So like I said, interactive way to, you know, find files that you want to package up, pack them all up and zip them up. Another thing I can do, say I'm in another folder. Oh, the last thing to do is take that folder, DD and alt to, where am I go back to, I'm in the raw folder. So go back to the raw folder over this one. And I can do the same thing, oops, 2021, 2021. And go ahead and pp the data back over. So now all those files are in the right location. Oh, yeah, that's that's the rest of them. So as you can see, that's really helpful. Now what about some other more clever things you can do? Well, okay, like I said, you can so say I'm in a folder that has a whole bunch of files. So I'm in a file folder that has a bunch of CSV files. I can look up and down in those files. I can see all the data that's in them. I can say, oh, you know what? There's a bunch of files that I wish had a different name. I don't want to do with any of this real data. So let me go to a folder that I don't care about. Let me go to, let me go to like downloads or something. There we go. So now I'm in my downloads folder. And I have, oh yeah, these don't mean anything. So I have this folder. I was taking this course for one of my licenses and have a bunch of files in there that are all labeled like AQAAO10203. Okay, that's great. .pdf. What if I want to rename all these files? Well, this is one of the great use cases for for ranger. So if I can either pick the ones that I want or I can just pick them all by doing V. I do colon and I type in bulk rename. If I just type in bulk BULK and do tab, it should complete. Yeah, bulk rename. So if you have, it's going to open up all the list of all those files in your editor. So I use them. So it's going to open all those file names in VIM. So now I'm in VIM with just those file names selected. If I do something like, so something that's cool you can do in VIM is do control V which puts you in visual block mode and then go down to all the way to the bottom of that list. I think shift I will put me in insert mode and it'll be inserting this to all the lines at the same time. I'm just going to put the course name dash and then get head escape to get out of out of insert mode. Now all the files, all those lines of now have code because of COVID course, COVID dash before the rest of the file name dot PDF. And I can go through here and I can do, you know, anything you can do in VIM, I can do I can go into substitution mode where you know, do colon percent S slash and then do regular expression to replace stuff. Whatever you want to do to these file names, when I'm all done, I just well, I don't do WQ, I do X to get out colon X to get out. It brings up another screen that says this is the command I'm about to run. It's going to run these sort of commands on every line is mv-bi-dash-the original file name, the new file name, and it gives you all the list of them. So if you it's your like last chance to say, okay, this is what the program is about to do, it's about to rename all these files in the same way. Please, and it says please double check everything and clear the file to abort. So that means just delete all these all these files out of here to abort. So delete all the lines in this file in this temp file and that will make it so it's not going to do this action. But I don't want to do that. So I'm just going to colon X again and now I have a screen that says all these files have been renamed enter. When I go back, I can see the new names of all those files. You don't know how many times I use this. So many times I'll be I'll get I get a whole bunch of files from one of my clients or from some other place and they all have funky names, but there's like one little part that I want to keep and or they are they are not using zeroed names. So it's like one two three four set of zero one zero two zero three. And I go into Ranger and I just go in here and find the ones that I want to rename rename them. And and so you can imagine how much time I can save after I renamed them, I can go in here, make a zip file, zip them back up, or I could you know do anything else that I want to do with these files. So what what good would a what a file manager be if you can't actually open the files. So like you can preview them like I said just by highlighting them if we have the right type of scope installed. So let's see let me look let me go back to where it was. All right. And now I have a zip file highlighted and I can enter the right. I can see all the things inside the zip file because I have a tool installed. A tool is a is a utility used to and I use this tool by itself all the time. It's it's something that's used to manage all types of compressed files. A and a tool is for archive. So it's highlighted a zip file. So what it's doing is doing a it's doing the ALS sub command of a tool which is give me a LS a list of all the files. So to the right I can see all the files in there. If the list is really long I can click I and it'll bring me into a full screen version of what that preview looks like. It's not an edit mode it's just a full screen version. But if I choose a different file let's choose like this PDF I can I can see all the data inside this PDF. Well a lot of the data it has a limit to how far it scrolls down. But yeah once I'm in there I'm in my pager now so I'm just in less reading reading the file in its format that it's supposed to be in. But let's click I again and get back to the normal mode. If I just press to the right again so I can't go any further over to the right because I'm in the furthest the deepest part of this directory but I have a file highlighted. So if I hit over to the right on that file it's going to use my desktops opener to open that file. So I just use I just used I don't know document viewer to which is called events to open up the file. So that's another great thing that you can do. So I'm like okay I have a bunch of files I want to rename a bunch of them. Oh I'm looking inside of this one file I don't like the data that I see in this one so I'm going to go edit it. Oh these other three I'm going to rename and then when I'm all done I want to select them all and zip them into a folder and move them to a different location. Just some of the things that you can do in Ranger and once I found Ranger I don't know I think I found it like 2013 or 14 I use it every day and sometimes when I'm on a different computer it doesn't have it I just get annoyed because I don't have my favorite tool it's even though I use a lot of other stuff in my day to day if I didn't have Ranger I would be probably half as productive as I am now. So that's just it that I have on this episode I'll add a couple links in the show notes for some of the tools that I use. So like I said eight tools if you install eight tools it's going to automatically do things if you install Kaka utils it'll automatically do ASCII art for your for your images. If you install highlight it'll automatically highlight things but if you and if you do poplar utils it'll automatically do PDFs but I have things installed like like Doc X to text ODT to text and like XLS to CSV SLS X to CSV just so I can it'll it'll take a excel or ODT file and turn it or ods file and turn it to a CSV file so you can actually look at it. Very useful stuff and like I said I use this every day. All right if that's it I have for for you today and if you have any thoughts or questions go ahead and put it in the comments for the show or make a show of your own. Once again this is be easy and as I always say keep hacking. You've been listening to Hacker Public Radio at HackerPublicRadio.org. We are a community podcast network that releases shows every weekday Monday through Friday. Today's show like all our shows was contributed by an HBR listener like yourself. If you ever thought of recording a podcast and click on our contributing to find out how easy it really is. Hacker Public Radio was founded by the digital dog pound and the infonomicon computer club and is part of the binary revolution at binwreff.com. If you have comments on today's show please email the host directly leave a comment on the website or record a follow-up episode yourself unless otherwise status today's show is released on the creative comments, attribution, share a light 3.0 license.