Tuesday 20 July 2021

List of tools I should remember to use

 

ripGrep - duh!

 

http - curl alternative

bat - cat

fd - find

sk - 'skim' fuzzy finder



Tuesday 18 May 2021

Controlling Fan speed on your laptop

For DELL Fan speed:

 

Use i8kutils:

* sudo apt-get install i8kutils    


i8kfan

Try and run:

* /usr/bin/i8kfan 

to see what the fans are set at (0/1/2)


To edit i8kconfig:

* sudo vim /etc/i8kmon.conf    

 

To view CPU temps :

* sensors


Thursday 6 May 2021

Mysteries of strace

From this nice puzzle

 To figure it out, you can use the -T flag to strace which tells us how long each system call takes. The number in angle brackets (<......>) at the end of each line is how long that system call took, in seconds. Here's what that looks like:

 $ strace -tt -T -f  -p $(pgrep python) 
15:56:15.517327 accept4(3, {sa_family=AF_INET, sin_port=htons(48564), sin_addr=inet_addr("5.6.7.8")}, [16], SOCK_CLOEXEC) = 4 <1.889267> 
15:56:17.407185 getsockname(4, {sa_family=AF_INET, sin_port=htons(8000), sin_addr=inet_addr("1.2.3.4")}, [128->16]) = 0 <0.000018>

Saturday 10 October 2020

Trouble logging in:

 

Check these files for login history & reason for login fails:

/var/log/auth.log
/var/log/secure
 
Useful guide on setting up an SFTP server 
https://www.techrepublic.com/article/how-to-set-up-an-sftp-server-on-linux/

Monday 23 September 2019

Slicing giant files



Use 'dd' to copy (in this case 3) blocks of data from the giant file to the output:

dd  if=giant.json count=3 of=output.json

trucate could also work.

For JSON jq is a great tool:

Here we are catting json and selecting entries with messages length > 0
cat ~/giant.json  | jq -cn --stream 'fromstream(1|truncate_stream(inputs))' | jq 'select((.messages | length) > 0)

Tuesday 30 July 2019

Use of * in bash

Bash will parse and expand special args before your commands.

Hence echo * will list files in your dir like ls.


Consider the following interresting case copied from SO. A directory has these contents:
  • test (regular file)
  • test1 (directory)
  • test2 (directory)
  • test3 (directory)
If you then type `mv *` something seemingly weird happens: test3 is there, but the rest is gone. While weird at first, it makes sense once you understand what bash actually passes to `mv`. Because of the asterisk, bash interprets mv * as mv test test1 test2 test3, and when mv gets that list, it'll assume that the last arguement is the destination, which is where all of the files would've been moved.

Thursday 20 June 2019

Clear up space, remove old ubuntu packages:

Clear up space, remove old ubuntu packages:

sudo apt-get update && sudo apt-get autoclean && sudo apt-get clean && sudo apt-get autoremove