Small time saving grep trick for newbs like me who are reinstalling at least once a day on average...
The most tedious part of the Arch install process is cutting out all the superfluous servers out of /etc/pacman.d/mirrorlist using nano (for why no Vim on the live image?!). Of course, there's probably some trick to nano that I don't know, but whatever.
I thought to myself just now, as I reinstalled for the nth time, that there must be an easier way. So I did a little man grep and discovered that with the -A switch you can make grep return as many lines as you like that trail positive results.
What that means for our Mirrorlist is that you can search for your country's name, and bounce all results with the next line as well into a new file:
cat /etc/pacman.d/mirrorlist | grep -A 1 Canada > mirrorlist
You need the trailing line because the line that contains the country's name is a comment, whereas the actual server address is on the next line. If you were parsing a file which had three-like sections, you would then similarly use -A 2, and there is also a function to copy leading lines, in case the field you're searching for is nested within a function or section of regularly-formatted lines. After you've cut out the separators (or maybe you know the trick to do it automatically in the same command line - I was too lazy to look it up, but I'm sure it's pretty durn simple, actually, now that I think of it...), replace the old mirrorlist with the generated one:
mv mirrorlist /etc/pacman.d/mirrorlist
Only issue is that it adds a '--' in between the discontiguous results, but it's a lot easier to open up a file that contains only mirrors from your own country, and then cut out the separators and the slowest servers. In my case, Canada only has 6 mirrors, so I just had to delete the separator lines.
It's only about 30 seconds of work saved, but if you're doing this daily like I currently am, it's handy in that otherwise tedious moment. It will also make you more curious about what other handy functions are hidden in those commands you're using every day. and curiosity leads to greater bash-fu.
About this post
- Posted
- Archived
- Score
- 5 · 100% up
- Kind
- Text
- ID
- 2tw0wi
26 comments
Just one question comes to mind: why are you reinstalling daily?
Cause I learn by breaking stuff. Sometimes (all the time) when I'm learning something new, I end up messing with this or that config file, and realize that I have foo'd the bar good and well. I imagine there is an easy command that will wipe all config files and reduce the system back to base group, but I dunno it yet.
Also, it is a minor goal to be able to install Arch without having to consult the Installation guide, which I currently still do. No reason, I just don't like that I need to rely on a paper to do something that basic.
Because it's fun, dammit!
BTRFS snapshots work well for that.
Virtual Machines, yo.
I have like 6-7 linux distros in various stages of disrepair on virtualbox. Saves a lot of effort and moments of panic when you think you accidentally wiped your data drive with cfdisk
All the fun of distro hopping with none of the drawbacks. Also, when you learn a new neat trick, you can apply it to your working system right away.
In order to pare down the mirrorlist on the live image, I simply install reflector and use it to create a good, clean mirrorlist.
Seconding reflector. Great tool, though I forget its name since I use it so infrequently.
alias it in your bashrc?
Can you install stuff in the live image? I think I tried once and couldn't. I'll have a look at that.
Yes.
Newbs? I've been using Linux for 3 years and consider myself a low-level expert on it, but still reinstall every 3-7 days.
...why?
Same reason as OP. Fun, and the overwhelming amount of experience in installation.
Also, I'm a distrohopper to the third degree.
The comment was mostly to forestall anyone thinking that I was presenting myself as any kind of expert. I just discovered something cool.
Backup files before messing with them? That made it easy to configure booting directly with efibootmgr really easy, I just backedup my file and restored them from the livecd when they wouldn't work.
I haven't really understood your problem, but:
cat file | grep patteris equivalent togrep pattern file--, just dogrep -A 6 Canada mirrorlist | grep -v '\-\-'-A 6 would return each Canada server, plus the two servers after that, and an extra comment besides.
However, the -v, good to know, thank you. I also had no idea you could use grep that way. Like I said, newb... :>
You could also install vim during the install, I suppose. :-) Both in the chroot and in the live environment.
I just cut the highest rated mirror from the list and pasted it at the top. Takes about 5 seconds.
Neat. I think the two things I would like on my install disk is a personal copy of my wireless settings and a pacman list that only has the https servers. I thought about just storing my prefered text files on the USB stick, but there are many ways to do things!