Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Monday, October 10, 2022

Some useful grep tricks I keep having to look up

 As I've said, this blog is meant for things I find myself repeatedly doing.  Especially, when I am doing them on different *nix systems I end up googling and eventually finding my same references:

This stackoverflow thread tends to be my main one to use for when I need to look for files containing as specific thing in them.  For instance, I often forget the full syntax in proc means for SAS.  

So I go to my code bases and execute the following:

      find . -name "*.sas" | xargs grep "proc means" | less

I also sometimes need to find files that contain specific things in them and copy them to a specific location.  I found this stackexchange thread useful (although not totally clean yet):

      find . -name "*.sas" | xargs grep -l "proc means" | xargs cp -t ~/destination




Saturday, September 19, 2015

Setting up ssh keys

UPDATE (15/09/2024):  Just found an even cleaner shell command on Ubuntu Documentation:

By default, the public key is saved in the file ~/.ssh/id_rsa.pub, while ~/.ssh/id_rsa is the private key. Now copy the id_rsa.pub file to the remote host and append it to ~/.ssh/authorized_keys by running:

ssh-copy-id username@remotehost

I keep forgetting this quick one-liner, so I thought I'd add it to my list of useful tricks.  I usually just Google it, but How-To Geek is an awesome resource (link)

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'


Sunday, March 29, 2015

Remove all old linux kernels, headers and modules for Debian based systems

This has come up often for me with my linux machines, so I'll just blog a blog on the topic.  I came across two useful posts:

RemoveOldKernels

Ubuntu Cleanup: How to Remove All Unused Linux Kernel Headers, Images and Modules

The former is useful, but it only removes the kernels.  I want to remove all headers, etc. associated with them.  So, before I run the command from the latter blog post, I just want to confirm what I'm going to remove, as should you, with the following code (note, not as root just to be even more cautious):
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
 Perfect, now I can just run the one-liner from that latter blog post:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Boom, I just got rid of over 3 GB's of old linux kernels on my system.