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
rpm -q --qf "%{VERSION}\n" redhat-release
2009-03-25 16:46:14
User: atoponce
Functions: rpm
2

In this case, I'm getting the package version for 'redhat-release', but of course, this can be applied to any package installed on the filesystem. This is very handy in scripts that need to determine just the version of the package, without the package name and all the sed and grep hackery to get to the data you want. To find out all the support format strings that 'rpm --qf' supports:

rpm --querytags
rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'
2009-03-24 20:42:17
User: llama
Functions: rpm
Tags: rpm
0

The queryformat option can be used in a number of ways to find things like duplicate packages, wrong arch, or the exact package to pass to rpm -e, yum remove, etc.

rpm -Va | grep -v "\.\.\.\.\.\.\.T"
rpm -qa --queryformat "%{NAME} %{ARCH}\n"
2009-03-18 15:19:21
User: angrox
Functions: rpm
2

Lists all installed RPM packages with name and architecture, which is useful to check for compability packages (+ required i386 packages) on a 64bit system.

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
2009-03-17 13:38:20
User: mpb
Functions: grep rpm
4

Find out which RPMs were installed on a particular date.

These would (naturally) include update RPMs.

This example shows searching for "Thu 05 Mar" (with grep).

Alternatively, pipe it to less so you can search inside less (with less's neat text highlighting of the search term):

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | less # (this example) search term: Thu 05 Mar

rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
2009-03-15 22:18:17
User: mpb
Functions: head nl rpm sort
2

Low on disk space? Check the largest installed RPMs for delete canditates.

rpm -qa \*code\*
2009-03-11 21:16:23
User: alcik
Functions: rpm
Tags: rpm
2

You can use wildcard with rpm search but you have to do 2 things:

1. use "-a" switch (means "all") with query ("-q") switch - argument is a pattern to use while searching for package names of all installed packages

2. protect wildcards, so that shell could not eat them - escape it with backslash ("\") or enclose all pattern between apostrophes ("'"):

rpm -qa 'co*de'

As you can see above it is possible to insert wildcards into middle of the pattern.

If you want, you can add "-i" or another rpm query options, "-i" will print package information for all installed packages matching pattern.

rpm -qif `which more`
2009-02-27 08:59:07
User: alcik
Functions: rpm
Tags: rpm which
3

Replace 'more' command with any command which is in your PATH.

rpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg
2009-02-26 14:32:12
User: piscue
Functions: grep rpm xargs
1

rpm, sometimes, is not wildcard friendly. To search files installed from package this could be useful.

change PACKAGENAME to any package do you want to search

rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'|egrep 'compat|glibc|gcc|libst|binu'|sort
2009-02-23 10:17:47
User: ovalerio
Functions: rpm
1

This command is very helpful when we need to duplicate a test scenario and first we want to find out the installed libraries together with the version and release numbers and architecture. (look example)

Command can be tuned by choosing just the names of libraries we are interested in. For example glibc and gcc.

rpm -qa --queryformat 'Installed on %{INSTALLTIME:date}\t%{NAME}-%{VERSION}-%{RELEASE}: %{SUMMARY}\n'
rpm -e --allmatches filename.rpm
2009-02-12 23:09:24
User: sohaileo
Functions: rpm
1

If somehow if you get more than 1 same name rpm package install, then it cannot be removed by using simple rpm -e as it gives you more than one rpm matches error. The --matches will help to remove all the same name rpm packages.

rpm -qlp <package.rpm>
2009-02-07 23:11:59
User: al3x
Functions: rpm
0

allows to check inside rpm file w/o installing it

rpm -qa --qf '%{name}'
rpm -qa --last
rpm --query --filesbypackage [packagename]
find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned"
2009-02-05 19:33:43
User: wwest4
Functions: find grep rpm sort
0

shows all RPMs with files in the current directory & its subdirectories.

rpm -qa --last
2009-02-05 16:00:56
User: systemj
Functions: rpm
2

the newest rpms are at the top; individual packages can also be queried this way:

rpm --last -q package