Commands using rpm (53)

  • 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 Show Sample Output


    4
    rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
    mpb · 2009-03-17 13:38:20 1
  • Replace 'more' command with any command which is in your PATH. Show Sample Output


    3
    rpm -qif `which more`
    alcik · 2009-02-27 08:59:07 2

  • 3
    rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n
    octopus · 2010-04-19 07:44:49 1
  • 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
  • the newest rpms are at the top; individual packages can also be queried this way: rpm --last -q package


    2
    rpm -qa --last
    systemj · 2009-02-05 16:00:56 0
  • 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. Show Sample Output


    2
    rpm -qa \*code\*
    alcik · 2009-03-11 21:16:23 1
  • Low on disk space? Check the largest installed RPMs for delete canditates. Show Sample Output


    2
    rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
    mpb · 2009-03-15 22:18:17 0
  • Lists all installed RPM packages with name and architecture, which is useful to check for compability packages (+ required i386 packages) on a 64bit system. Show Sample Output


    2
    rpm -qa --queryformat "%{NAME} %{ARCH}\n"
    angrox · 2009-03-18 15:19:21 0
  • 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 Show Sample Output


    2
    rpm -q --qf "%{VERSION}\n" redhat-release
    atoponce · 2009-03-25 16:46:14 1
  • It's all said in the title. Show Sample Output


    2
    rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -nr | less
    betsubetsu · 2010-04-14 07:28:41 0

  • 2
    rpm -qa --qf "%-30{NAME} %-10{SIZE}\n" | sort -n | less
    betsubetsu · 2010-04-14 07:30:37 0

  • 2
    rpm -qp --scripts package.rpm
    gerard · 2011-01-04 14:38:14 2
  • For Linux distributions using rpm (eg Mandriva), this command will find the rpm package name that provides a file. Show Sample Output


    2
    rpm -q --whatprovides $filename
    mpb · 2011-02-09 23:28:15 0
  • 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 Show Sample Output


    2
    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; }
    nnsense · 2015-05-11 16:46:01 3
  • 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.


    1
    rpm -e --allmatches filename.rpm
    sohaileo · 2009-02-12 23:09:24 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. Show Sample Output


    1
    rpm -qa --qf '%{name}-%{version}-%{release}.%{arch}\n'|egrep 'compat|glibc|gcc|libst|binu'|sort
    ovalerio · 2009-02-23 10:17:47 0
  • 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 Show Sample Output


    1
    rpm -qa | grep PACKAGENAME | xargs rpm -q --filesbypkg
    piscue · 2009-02-26 14:32:12 0
  • On Fedora clean the boot directory; erase older kernel


    1
    rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
    Nick · 2009-03-28 21:41:15 1

  • 1
    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
    freeman · 2009-08-01 21:00:43 2
  • 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 Show Sample Output


    1
    rpm -q --queryformat %{VERSION}\\n pkgname
    mrwill · 2010-06-03 01:54:17 0
  • Description is moved to "Sample output" because the html sanitizer for commandlinefu breaks the examples.. Show Sample Output


    1
    diff rpm_output_from_other_computer <(rpm -qa|sort)
    xeor · 2011-06-25 11:45:15 0
  • 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.


    1
    sudo rpm -e `rpm -qa | grep keyword`
    mstock · 2012-10-22 16:06:39 0
  • \n Separates out the architectures on different lines. Show Sample Output


    1
    rpm -q --queryformat="%{NAME}: %{OPTFLAGS}\n" <rpm>
    robinsonaarond · 2012-12-05 22:18:03 0
  • 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. Show Sample Output


    1
    rpm -qa --queryformat '%{size} %{name}-%{version}-%{release}\n' | sort -k 1,1 -rn | nl | head -16
    mpb · 2013-03-19 21:10:54 0
  • 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 ;) Show Sample Output


    1
    qf2s() { rpm -ql $(rpm -qf $1)|grep -P "\.service"; }
    nnsense · 2015-05-11 16:32:16 0
  •  1 2 3 > 

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

Sort output by column
(separator = $IFS)

MSDOS command to check existance of command and exit batch if failed
This is a command to be used inside of MS-DOS batch files to check existence of commands as preconditions before actual batch processing can be started. If the command is found, batch script continues execution. If not, a message is printed on screen, script then waits for user pressing a key and exits. An error message of the command itself is suppressed for clarity purpose.

Remote mysql dump all databases with ssh

truncate deleted files from lsof
While the posted solution works, I'm a bit uneasy about the "%d" part. This would be hyper-correct approach: $ lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{sub(/.$/,"",$4);printf ">/proc/%s/fd/%s\n", $2,$4}' Oh, and you gotta pipe the result to sh if you want it to actually trim the files. ;) Btw, this approach also removes false negatives (OP's command skips any deleted files with "txt" in their name).

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"

Colored status of running services
Replace service --status-all 2>&1 by service --status-all 2>/dev/null to hide all services with the status [ ? ]

Get IPv4 of eth0 for use with scripts
Simple and easy. No regex, no search and replace. Just clean, built-in tools.

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" }

Filter IP's in apache access logs based on use
The first sort is necessary for ips in a list to be actually unique.

return external ip
curl inet-ip.info -> 113.33.232.62\n curl inet-ip.info/ip -> 113.33.232.62 curl inet-ip.info/json -> JSON print curl inet-ip.info/json/indent -> JSON pretty print curl inet-ip.info/yaml -> YAML format curl inet-ip.info/toml -> TOML format http://inet-ip.info


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: