Awesome Linux tricks and tips.

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

Get just your Internet facing IP address.

[email protected]:~/Documents$ curl -s '' | 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 | awk 'NR==1 {print $NF}'

Print the ARP table of your machine.

[email protected]:~$ cat /proc/net/arp
IP address       HW type     Flags       HW address            Mask     Device    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         UG        0 0          0 enp3s0     U         0 0          0 enp3s0   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 | 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:

Print the last 10 commands run on your machine.

[email protected]:~$ fc -l -10
879      date -d "$(curl -s --head | 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