3 Usefull Oneliners #2 : find IP address, copy trick, run previous command with different arguments

1. awk trick: Find out a network interface’s IP address:

This command displays only the ip of the eth0 interface.

Watch Free Movies
  • ip a s eth0 | grep “inet ” | head -n 1 | awk ‘{print $2}’ | cut -f1 -d’/’

$ ip a s eth0 | grep "inet " | head -n 1 | awk '{print $2}' | cut -f1 -d'/'
192.168.8.187

Read more about the iproute2 command here.

2. cp trick: Make a quick copy of a file, with a specified extension:

cp filename{,.copy}

$ cp file1{,.copy}
$ ls file1*
file1 file1.copy

This is good for adding an extension to a file with a very long filename:

$ touch filewithreallylongfilename
$ cp filewithreallylongfilename{,.doc}
$ ls filewithreallylongfilename*
filewithreallylongfilename filewithreallylongfilename.doc

Read more about the cp command here.

3. Runs previous command and replace one string with the another globally (every where it appears):

This runs the previous command, but replaces the “ssh” string with “skel”, globally.

  • !!:gs/star/wars

$ cd /etc/ssh/
$ !!:gs/ssh/skel
cd /etc/skel/

Read more about the !! shell trick here.

If you liked this article, read the other oneliner articles here.

Scroll to Top