Friday, December 23, 2011

Command Line Tips

Here is some of command line tricks that can help you a lot.
I am working on this post So you will get more and more...

1.) Using vim to see Calender of two years in single window.

#vim -O <(cal 2011) <(cal 2012)
Here -O     Open  one window for each file.

2.) ifconfig eth0;sleep 60;ifconfig eth0)|grep "RX bytes"

# Pass two runs of ifconfig 60 seconds apart through the same grep using a subshell.

[root@server2 ~]#(ifconfig eth0;sleep 60;ifconfig eth0)|grep "RX bytes"
          RX bytes:332299170 (316.9 MiB)  TX bytes:21752930 (20.7 MiB)
          RX bytes:337602454 (321.9 MiB)  TX bytes:21927669 (20.9 MiB

3.) Here is One line coding for getting status of all init.d scripts(services) and store result in a file

root@primary ~] for i in /etc/init.d/*; do echo -e $i status:; echo -e "\t";$i status ;echo -e "\n"; done > ~/daemon_status_list

Dated : 19-Oct-2011
4.) Command to display list of top files or directories size wise.

#for X in $(du -s * | sort -nr | cut -f 2| head -n 2); do     du -hs $X; done 

5.) Execute a command at a given time
#echo "ls -l" | at
e.g. Suppose you want to dispaly the list of current working directory at your current terminal. then use following command:
#echo "ls -l > $(tty)" | at 13:46

You can also make use of this trick according to your requirements.


6) Using column Command:




7.) Using Regular Expression to exclude some of Directories.
[root@test]~# ll -d  /*
drwxr-xr-x   2 root   root      4096 May 31 04:02 /bin
drwxr-xr-x   3 root   root      1024 May 29 00:17 /boot
drwxr-xr-x   3 root   root      4096 May 28 02:33 /customer
drwxr-xr-x  12 root   root      3660 Sep 19 03:28 /dev
drwxr-xr-x  88 root   root     12288 Nov 16 06:49 /etc
drwxr-xr-x   2 root   root      4096 Aug  8  2008 /home
drwxrwxrwx  17 root   root      4096 Oct 31 03:37 /local
dr-xr-xr-x 395 root   root         0 Sep 18 23:26 /proc


Exclude all directory starting from d,p and l
[root@ph132704]~# ll -d  /[!d,p,l]*
drwxr-xr-x  2 root   root      4096 May 31 04:02 /bin
drwxr-xr-x  3 root   root      1024 May 29 00:17 /boot
drwxr-xr-x  3 root   root      4096 May 28 02:33 /customer
drwxr-xr-x 88 root   root     12288 Nov 16 06:49 /etc
drwxr-xr-x  2 root   root      4096 Aug  8  2008 /home

This can be helpful while using du and want to exclude some directories.
[root@test]~# du -sh /[!c-z]*
7.7M    /bin
19M     /boot


!Enjoy CLI Mode

Excuse for typo
Kuldeep Sharma









Kubernetes 1.31 || Testing the Image Volume mount feature using Minikube

With Kubernetes new version 1.31 ( https://kubernetes.io/blog/2024/08/13/kubernetes-v1-31-release/ ) there are so many features releases for...