Commands by patko (7)

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

If (and only if) the variable is not set, prompt users and give them a default option already filled in.
The read command reads input and puts it into a variable. With -i you set an initial value. In this case I used a known environment variable.

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Get your local IP regardless of your network interface
Shows only IP-addresses of ifconfig except I fixed the script to work on more systems and configs short info /inet/!d; #grep inet /127.0/d; # grep -v 127.0 /dr:\s/d; # grep -v dr: s/^.*:\(.*\)B.*$/\1/ # remove everything exept between : and B

Block all IPv4 addresses that has brute forcing our ssh server
For ipv6 use: grep -oE "\b([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}\b"

Outputs files with ascii art in the intended form.
Files containing ascii art (e.g. with .nfo extension) are typically not correctly reproduced at the command line when using cat. With iconv one can easily write a wrapper to solve this: $ #!/bin/bash $ if [ -z "$@" ]; then echo "Usage: $(basename $0) file [file] ..." $ else iconv -f437 -tutf8 "$@"; fi $ exit 0

Copy from host 1 to host 2 through your host

Unlock VMs in Proxmox
Unlock your VMS to avoid problems after some failed tasks ended.

Sort file greater than a specified size in human readeable format including their path and typed by color, running from current directory
1. find file greater than 10 MB 2. direct it to xargs 3. xargs pass them as argument to ls

Find the package that installed a command
Put this one-line function somewhere in your shell init, re-login and try $ whatinstalled This is an elaborate wrapper around "dpkg -S", with numerous safeguards. Symlinks and command aliases are resolved. If the searched command is not an existing executable file or was installed by some other means than dpkg/apt, nothing is printed to stdout, otherwise the package name.

Backup a file with a date-time stamp
$ buf myfile.txt This is useful when you are making small but frequent changes to a file. It keeps things organised and clear for another administrator to see what changed and at what time. An overview of changes can be deduced using a simple: $ ls -ltr

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: