Commands by acavagni (11)


  • 1
    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 0
  • 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

Grep only files matching certain pattern (Advanced)

Encode a string using ROT47
This command will encode a string using the ROT47 cipher.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Watch the progress of 'dd'
run this in another terminal, were xxxx is the process ID of the running dd process. the progress will report on the original terminal that you ran dd on

FInd the 10 biggest files taking up disk space

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Follow the flow of a log file
tailf same as tail -f follow the flow of a log file, showing it in real time to stdout.

write by vim need root privilege

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Determine an image's dimensions
Simple use of ImageMagick identify function.


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: