3 Usefull Oneliners #1 : find duplicate UIDs, find the package a file belongs to, create a mkdir cd function

1. awk trick: Find duplicate User IDs (UIDs), from the /etc/passwd file.

This command will display only the duplicate UID, and nothing more:

  • awk -F: ‘{print $3}’ /etc/passwd | sort | uniq -d

$ sudo useradd -u 999 mike7
$ sudo useradd -o -u 999 mike8
$ awk -F: '{print $3}' /etc/passwd | sort | uniq -d

2. dpkg trick: Find the package a command belongs to in Debian based Linux distros.

This will display package and the command’s binary:

  • dpkg -S $(which command_here)

$ dpkg -S $(which ls)
coreutils: /bin/ls
$ dpkg -S $(which ifconfig)
net-tools: /sbin/ifconfig
$ dpkg -S $(which skill)
procps: /usr/bin/skill

3. Create a function to mkdir and cd to the directory:

To make the mkd function persistent, add this line in your ~/.bashrc file:

  • mkd () { mkdir -p “$@” && cd “$@”; }

$ echo 'mkd () { mkdir -p "$@" && cd "$@"; }' >> ~/.bashrc
$ bash
$ mkd ~/1/2
$ pwd

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

Liked it? Take a second to support Geekster on Patreon!
Tagged with: , , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *


Support LinuxG via Patreon
Support LinuxG.net on Patreon!


Subscribe to get the latest Linux news and how to guides directly on your e-mail!