Hide

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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using rpm from sorted by
Terminal - Commands using rpm - 43 results
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
0

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
0

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
1

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
1

\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
1

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
0

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
0

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
0

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
0

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
1

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
1

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
0

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
-5

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

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

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

rpm -ivh 'http://www.website.com/path/to/desired_software_package.rpm'
yum clean all ; rpm -Uvh http://download.fedora.redhat.com/pub/fedora/linux/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm ; yum -y upgrade ; reboot
for i in `rpm -qva | sort ` ; do ; echo "===== $i =====" ; rpm -qvl $i ; done > /tmp/pkgdetails
2009-07-14 20:34:55
User: tkunz
Functions: echo rpm sort
0

This will create the file /tmp/pkgdetails, which will contain a listing of all the files installed on your RPM-based system (RedHat, Fedora, CentOS, etc). Useful should the RPM system/database become corrupted to find which package installed which files.

rpm -qa --queryformat "%{NAME} %{ARCH}\n"
rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
2009-03-28 21:41:15
User: Nick
Functions: grep rpm uname xargs
1

On Fedora clean the boot directory; erase older kernel