Skip to content

Tag: unix

Sort on specific part of filename in shell script

I have a list of files which I want to delete except 2 of the most recent ones. The files are named as “filename_dd_mm” for example “filename_19_05”. If I do It sorts them according to the day. What I want is to sort them by month first and then the day. Can someone please guide me to …

Modify config files with sed in bash

I am trying to set net.ipv4.ip_forward to 1 in /etc/sysctl.conf.The following works fine but it sure missing some edge cases For e.g if the sysctl.conf contain any one of the following it won’t match #net.ipv4.ip_forward=1 ##net.ipv4.ip_forward=1. Is there a more reliable way to modify settings in confi…

How to change date format in linux/unix text file

I have sample.txt file in my linux system.all the data that is present in my file are in the following date format I want to convert all this date format in my sample.txt file to YYYY-MM-DD Format. Answer It’s quite simple with date -d, e.g. Input File Example Use/Output

Compute base64 encoded hash from a given hash?

I created a file and input some random string into it. Now if I use openssl to compute base64 hash [sha256], I run this: which returns me KHN0ZGluKT0gMzJjYjA1MTgzNDNhZmY2N2FlMmY5YzUwNDcwNGRiNGE5Njc5MzIyZWVlNTBmMjBiNTMzNjZlYTBiMDY2MWNlZgo= Now I process this hash stepwise, as, which gives me (stdin)= 32cb05183…

Complex rsync filtering (includes and excludes)

I got directories and files that look like this I only want to copy the 20170409_*/schedule, 20170410_*/schedule, 20170411_*/schedule folders and contents. This mostly works: However this also copies the following: How do I omit the files and the dateTimeFolders I haven’t included and only get the dateT…