What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using rpm from sorted by
Terminal - Commands using rpm - 48 results
sudo -E rpm -Uvh "http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm"
2015-10-29 14:06:48
User: zlemini
Functions: rpm sudo

In this case the current user has proxy variable set which allows access to the rpm on the internet but needs root privs to install it.

Running sudo -E preserves the current user proxy var and allows the rpm install to be executed with sudo.

fileinfo() { RPMQF=$(rpm -qf $1); RPMQL=$(rpm -ql $RPMQF);echo "man page:";whatis $(basename $1); echo "Services:"; echo -e "$RPMQL\n"|grep -P "\.service";echo "Config files:";rpm -qc $RPMQF;echo "Provided by:" $RPMQF; }
2015-05-11 16:46:01
User: nnsense
Functions: basename echo grep rpm whatis

Many times I give the same commands in loop to find informations about a file. I use this as an alias to summarize that informations in a single command. Now with variables! :D

qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
2015-05-11 16:32:16
User: nnsense
Functions: grep rpm

I use this as an alias to get all .service files related a single installed file/conf (if it has services, of course).

For rpm based systems ;)

rpm -e --allmatches gpg-pubkey-1aa043b8-53b2e946
2014-12-09 21:27:08
User: krizzo
Functions: rpm
Tags: GPG rpm yum pubkey

This will remove the gpg-pubkey-1aa043b8-53b2e946 from rpm/yum and you'll be prompted to add it back from the given repo.

rpm -qa gpg-pubkey --qf "%{version}-%{release} %{summary}\n"
2014-12-09 21:23:28
User: krizzo
Functions: rpm
Tags: GPG rpm yum pubkey

This will list all the gpg keys that were accepted and installed for yum.

for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
2014-04-30 16:11:14
User: sonny108
Functions: cat echo grep rpm

Found it online and could be very useful

rpm -qa --queryformat '%{SIZE}\n' | awk '{sum += $1} END {printf("Total size in packages = %4.1f GB\n", sum/1024**3)}'
2013-12-14 20:22:41
User: skytux
Functions: awk rpm

It is not the installed size in files, but the size of RPM packages.

rpm -qa --queryformat '%{size} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16
2013-03-19 21:10:54
User: mpb
Functions: head nl rpm sort

Interesting to see which packages are larger than the kernel package.

Useful to understand which RPMs might be candidates to remove if drive space is restricted.

rpm -q --queryformat="%{NAME}: %{OPTFLAGS}\n" <rpm>
2012-12-05 22:18:03
Functions: rpm

\n Separates out the architectures on different lines.

sudo rpm -e `rpm -qa | grep keyword`
2012-10-22 16:06:39
User: mstock
Functions: grep rpm sudo
Tags: rpm

This should be an option to rpm, but isn't. I wind up using it a lot because I always forget the full name of the packages I want to delete.

rpm -qa | sort | sed -n -e "s/\-[0-9].[0-9]*.*//p" | uniq
2012-06-04 12:36:39
User: tuxknowledge
Functions: rpm sed sort

This will list all installed packages on a RedHat/CentOS based system, sort them alphabetically, Parse off the version numbers, and delete any duplicate entries.

This is good if you need to build out a mirrored system or rebuild a failing system.

whichpkg() { rpm -qf "$@"; }
2011-07-05 23:39:32
User: flatcap
Functions: rpm
Tags: rpm

Find the package a file belongs to on an rpm-based distro.

summpkg() { rpm -qfi "$@"; }
2011-07-05 23:39:24
User: flatcap
Functions: rpm
Tags: rpm

Find information about the rpm package which owns a certain file.

diff rpm_output_from_other_computer <(rpm -qa|sort)
2011-06-25 11:45:15
User: xeor
Functions: diff rpm

Description is moved to "Sample output" because the html sanitizer for commandlinefu breaks the examples..

sudo rpm -if "http://rpm_server/rpm_repo/this-app.rpm"
rpm -qa kernel
rpm -q --whatprovides $filename
2011-02-09 23:28:15
User: mpb
Functions: rpm

For Linux distributions using rpm (eg Mandriva), this command will find the rpm package name that provides a file.

rpm -qp --scripts package.rpm
rpm -q --queryformat %{VERSION}\\n pkgname
2010-06-03 01:54:17
User: mrwill
Functions: rpm

if you want to see all information about a package use: rpm -qi pkgname

full list of querytags can be accessed by the command: rpm --querytags

you can also customize the query format how ever you like with using more querytags together along with escape sequences in "man printf"! you can also use more than one package name.

for example this command shows name and version in to columns: rpm -q --queryformat %-30{NAME}%{VERSION}\\n pkg1 pkg2

rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
rpm -qa --qf "%-30{NAME} %-10{SIZE}\n" | sort -n | less
rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -nr | less
rpm --querytags | egrep -v HEADERIMMUTABLE | sort | while read tag ; do rpm -q --queryformat "$tag: [%{$tag} ]\n" -p $SomeRPMfile ; done
2010-03-25 05:40:48
Functions: egrep read rpm sort

If you want to relocate a package on your own, or you just want to know what those PREIN/UN and POSTIN/UN scripts will do, this will dump out all that detail simply.

You may want to expand the egrep out other verbose flags like CHANGELOGTEXT etc, as your needs require.

It isn't clear, but the formatting around $tag is important: %{$tag} just prints out the first line, while [%{$tag }] iterates thru multi-line output, joining the lines with a space (yes, there's a space between the g and } characters. To break it out for all newlines, use [%{$tag\n}] but the output will be long.

This is aside from rpm2cpio | cpio -ivd to extract the package files.

rpm -qf /lib/modules/*
2010-03-01 05:00:56
User: megacoder
Functions: rpm

Exploit that RPM database just sitting there, taking up space.

rpm -qf /etc/*-release
2010-03-01 01:24:07
User: megacoder
Functions: rpm

This should work on any RPM-based distribution. It's more reliable than trying to parse the content of the files.