Commands by acavagni (11)


  • 0
    date | md5sum | sed -r 's/(..){3}/\1:/g;s/\s+-$//'
    acavagni · 2019-07-13 10:39:21 0
  • This is a slightly modified version of the knoppix5 user oneliner (https://www.commandlinefu.com/commands/view/24571/draw-line-separator). Show Sample Output


    1
    seq -s '*' 40 | tr -dc '[*\n]'
    acavagni · 2019-07-01 07:24:47 0

  • 0
    eval "unset $(printenv | grep -ioP '(?:https?|no)_proxy' | tr '\n' ' ')"
    acavagni · 2019-06-28 10:40:41 0
  • I use it after a clean CentOS 7 minimal server installation to automatically populate the /etc/hosts file. Not sure why the installation does not add this entry by itself. Tested on CentOS 7 with the simplest use case: 1 static ip address and the hostname provided during installation. Show Sample Output


    0
    echo "$(ip addr show dev $(ip r | grep -oP 'default.*dev \K\S*') | grep -oP '(?<=inet )[^/]*(?=/)') $(hostname -f) $(hostname -s)"
    acavagni · 2019-06-15 16:40:38 1
  • The vaule is expressed in megabytes Show Sample Output


    1
    echo $[ ($(dpkg-query -s $(dpkg --get-selections | grep -oP '^.*(?=\binstall)') | grep -oP '(?<=Installed-Size: )\d+' | tr '\n' '+' | sed 's/+$//')) / 1024 ]
    acavagni · 2019-06-02 16:35:34 0
  • I put this command on my ~/.bashrc in order to learn something new about installed packages on my Debian/Ubuntu system each time I open a new terminal Show Sample Output


    1
    dpkg-query --status $(dpkg --get-selections | awk '{print NR,$1}' | grep -oP "^$( echo $[ ( ${RANDOM} % $(dpkg --get-selections| wc -l) + 1 ) ] ) \K.*")
    acavagni · 2019-06-01 13:24:07 0
  • It uses the following GNU grep options: "-o" which shows only the matching part of the line and "-P" which allows the use of Perl regular expressions. Show Sample Output


    4
    ip a | grep -oP '(?<=inet |addr:)(?:\d+\.){3}\d+'
    acavagni · 2019-03-21 20:53:06 0
  • This command could seem pretty pointless especially when you can get the same result more easily using the rpm builtin queryformat, like: rpm -qa --qf "%{NAME} %{VERSION} %{RELEASE}.%{ARCH}\n" | sort | column -t but nonetheless I've learned that sometimes it can be quite interesting trying to explore alternative ways to accomplish the same task (as Perl folks like to say: There's more than one way to do it!) Show Sample Output


    3
    rpm -qa | sed 's/^\(.*\)-\([^-]\{1,\}\)-\([^-]\{1,\}\)$/\1 \2 \3/' | sort | column -t
    acavagni · 2019-03-14 21:11:45 0
  • It can be used to pinpoint the path(s) where the largest number of files resides when running out of free i-nodes Show Sample Output


    1
    find / -type f ! -regex '^/\(dev\|proc\|run\|sys\).*' | sed 's@^\(.*\)/[^/]*$@\1@' | sort | uniq -c | sort -n | tail -n 10
    acavagni · 2019-03-06 20:36:14 0
  • useful for discarding even those comments which start with blanks or those empty lines which contain blanks Show Sample Output


    6
    grep -vE '^\s*(#|$)' textfile
    acavagni · 2019-03-05 21:40:02 0
  • Useful to see at glance which directory under the root file is using most space Show Sample Output


    1
    find / -maxdepth 1 -type d | xargs -I {} sh -c "mountpoint -q {} || du -sk {}" | sort -n
    acavagni · 2019-03-04 11:59:10 0

What's this?

commandlinefu.com 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

show git commit history

Purge configuration files of removed packages on debian based systems
also search with aptitude search '~c'

Simple example of the trap command

Watching Command
If you need to keep an eye on a command whose output is changing, use the watch command. For example, to keep an eye on your load average

Command to logout all the users in one command
Logs all users out except root. I changed the grep to use a regexp in case a user's username contained the word root.

Force the script to be started as root
Will run the script as root and exit if the wrong or no password is given. Also will keep the parameters active if any where given.

Generate a random password 30 characters long
Find random strings within /dev/urandom. Using grep filter to just Alphanumeric characters, and then print the first 30 and remove all the line feeds.

Change active bond slave
This forces a bonded interface to switch to another slave in the bond as its active slave.

Generate an XKCD #936 style 4 word password
The improvement of this command over Strawp's original alternative is that you can specify the size of the words, in this particular case words between 3 and 5 character's long. It also excludes words that contain apostrophes, if you'd rather keep those words simply substitue [^'] for .

Reduce PDF size


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: