Awesome Linux tricks and tips.

Posted: March 29, 2016. At: 11:32 AM. This was 2 years ago. Post ID: 8834
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

Convert a Linux text file to DOS format with AWK.

[jason@darknet:~] cat dodo-ip.txt | awk '{sub(/$/,"\r")};1' > dodo2.txt

Convert a DOS text file to UNIX format.

[jason@darknet:~] cat dodo2.txt | awk '{sub(/\r$/,"")};1' > dodo3.txt

Get your Internet facing IP address from the command line. This shows all information.

[email protected]:~/Documents$ curl ifconfig.me/all

Get just your Internet facing IP address.

[email protected]:~/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.

[email protected]:~$ 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.

[email protected]:~$ 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.

[email protected]:~$ date
Tuesday 29 March  11:18:33 AEDT 2016

Get the current time and date from the Internet using the command line.

[email protected]:~$ 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.

[email protected]:~$ sudo awk -F: '{ print $1 }' /etc/passwd | wc -l
[sudo] password for jason:
42

Print the last 10 commands run on your machine.

[email protected]:~$ 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.

[email protected]:~$ echo "You have `ls | wc -l` files in `pwd`"
You have 18 files in /home/jason

No comments have been made. Use this form to start the conversation :)

Leave a Reply