Posts

command line / bash variable in awk command

 This is how we use a command line / bash variable (named num) in a awk command. We define an awk  variable 'var' with -v option. This also shows use of BEGIN block. awk -F, -v var=$num 'BEGIN{srand(var)} {print $1","$2","rand()}' file_name 

Change nameserver entries in resolve.conf

 We can directly change the contents of the file but they dont seem to be in effect. So I added Google's nameserver in the file as follows :  $ sudo cat /etc/resolvconf/resolv.conf.d/base  nameserver 8.8.8.8 nameserver 8.8.4.4 And then updated the file as follows :  $ sudo resolvconf -u   we can also just update /etc/resolve.conf and it will be in effect immediately. $ sudo sed -i '1 i\nameserver 8.8.8.8\nnameserver 8.8.4.4' /etc/resolv.conf  To remove the changes : $ sudo sed -i '1,2d' /etc/resolv.conf 

renaming all the files in a folder

 IF we want to rename all the files with a part of the file we can do something following: for file in $(ls); do nn=$(echo $file | awk -F'_' '{print($2)}'); mv $file $nn; done

shell loop through dates

 Easy command to loop through the dates :  for i in 2022-01-{01..31} 2022-02-{01..15}; do echo $i; done More comprehensive command : d=2015-01-01 while [ " $d " != 2015-02-20 ]; do echo $d d=$(date -I -d " $d + 1 day" ) done

tp-link archer t3u on ubuntu

Recently got tp-link T3u mini wifi adapter   but as usual ubuntu did not have its drivers. So executed following commands and it worked perfectly.  cd /opt   git clone https://github.com/cilynx/rtl88x2bu.git   cd rtl88x2bu VER=$(sed -n 's/\PACKAGE_VERSION="\(.*\)"/\1/p' dkms.conf) sudo rsync -rvhP ./ /usr/src/rtl88x2bu-${VER} sudo dkms add -m rtl88x2bu -v ${VER} sudo dkms build -m rtl88x2bu -v ${VER} sudo dkms install -m rtl88x2bu -v ${VER} sudo modprobe 88x2bu

sudo access to ldap user

 Typically, if you dont have sudo and "gain" sudo access, you cant just add yourself to sudo group. In that scenario, we need to reboot in "advanced mode" and gain access to root shell. Once in, you can have following :  $ sudo cat /etc/sudoers.d/hpatil  hpatil ALL=(ALL) ALL and then we will have sudo access. 

Bootable USB

In case your laptop has good old booting system and not advanced system like UEFI, you can use following command to create bootable USB. In case your laptop is fancy, you will have to use software like Rufus which works only on "amazing" windows. sudo dd bs=4M if=~/Downloads/ of=/dev/sdc1 status=progress oflag=sync you can find out /dev/sdc1 via df command.