Some very useful Linux tricks and tips.
Convert a Linux text file to DOS format with AWK.
┌──(john㉿DESKTOP-PF01IEE)-[~] └─$ awk '{sub(/$/,"\r")};1' hello.txt > dodo2.txt |
Convert a DOS text file to UNIX format.
[jason@darknet:~] awk '{sub(/\r$/,"")};1' dodo2.txt > dodo3.txt |
Get your Internet-facing IP address from the command line. This shows all information.
jason@jason-desktop:~/Documents$ curl ifconfig.me/all |
Get just your Internet-facing IP address.
jason@jason-desktop:~/Documents$ curl -s 'http://checkip.dyndns.org' | sed 's/.*Current IP Address: \([0-9\.]*\).*/\1/g' |
Print the IP address of your computer on the LAN.
jason@jason-desktop:~/Documents/ipinfo$ ip route get 8.8.8.8 | awk 'NR==1 {print $NF}' 192.168.100.5 |
Print the ARP table of your machine.
jason@jason-desktop:~$ cat /proc/net/arp IP address HW type Flags HW address Mask Device 192.168.100.1 0x1 0x2 28:c6:8e:47:af:54 * enp3s0 |
Another way to print the routing table for your LAN.
jason@jason-desktop:~$ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.100.1 0.0.0.0 UG 0 0 0 enp3s0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 enp3s0 192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 enp3s0 |
Get the current date and time in the terminal with the Linux command line.
jason@jason-desktop:~$ date Tuesday 29 March 11:18:33 AEDT 2016 |
Get the current time and date from the Internet using the command line.
jason@jason-desktop:~$ date -d "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')" Tuesday 29 March 11:21:02 AEDT 2016 |
Count the number of entries in the /etc/passwd file.
jason@jason-desktop:~$ sudo awk -F: '{ print $1 }' /etc/passwd | wc -l [sudo] password for jason: 42 |
Print the last 10 commands run on your machine.
jason@jason-desktop:~$ fc -l -10 879 date -d "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')" 880 date 881 ps ax 882 cd 883 cd linux-4.6-rc1/ 884 mc 885 psa x 886 ps ax 887 cd 888 sudo awk -F: '{ print $1 }' /etc/passwd | wc -l |
Print a count of the files in a directory.
jason@jason-desktop:~$ echo "You have `ls | wc -l` files in `pwd`" You have 18 files in /home/jason |