Useful Linux Commands

From JasonAntmanWiki
Jump to: navigation, search

This page is, effectively, a compendium of my pocket notebook of useful commands under *nix operating systems. Some of them are very simple, and others are rather complex kludges that I have amassed over time.

Contents

Hardware

dmesg - "diagnostic message" - gives kernel diagnostic message output. Handy for finding out about devices, drivers, etc. For example - to find out about your serial ports, run dmesg | grep tty.

setserial -g /dev/ttyS[01] - List information on the currently active serial ports.

Files

ls -ltu this is the ls -l command with -t (sort by time modified) and then modified by -u (sort by time accessed). Good to look through a directory and see the unused files.

grep -n PATTERN FILENAME - grep -n shows the line numbers with the output. So, if you were looking for comments in code containing the phrase "TODO" and wanted to search all of the files in the current directory, you could grep -n TODO * and you would get a listing showing the relevant lines, with their filenames and line numbers.

File Newline Conversion - files from different OSs use different characters to signal the end of a line. Unix uses the Line Feed / New Line (LF, or Hex 0xA), Mac uses Carriage Return (CR, or hex 0Xd), and Windows/DOS uses a CR LF pair. As a result, if you open a text file created in Windows on a *nix box, you will see "^M" at the end of the lines, a translation of the extra CR character. Craig Stuart Sapp, of Stanford University, has created the "flip" utility, which will convert between the various line feed formats. It is available from http://ccrma-www.stanford.edu/~craig/utility/flip/ as both source and a pre-compiled Linux, Mac, or Windows binary. Once installed in /bin, usage is simple like: flip -u filename.txt to convert filename.txt to Unix line feeds.

Operating System

Finding version of SuSE Linux - cat /etc/issue

Packages

Query Installed Packages - rpm -qa for query all. Lists all installed RPMs Useful to pipe into grep.

Find information on a package - rpm -qi packageName.

List configuration files for a package - rpm -qc packageName.

Dump ALL file data for a package - rpm -q --dump packageName.

Just list files provided by a package - rpm -ql packageName.

To extract a single file from an RPM archive: rpm2cpio RPM_file | cpio -id individual_file(s)

Compression

TAR GZip an entire directory - tar -Ppczf filename.tar.gz /path/to/directory. Where filename.tar.gz is the archive file to create (in the current directory) and /path/to/directory is the full path to the directory to use as input. The arguments in "-Ppczf" are as follows: P - (optional) - use full (absolute) paths. p - preserve permissions. c - create new archive. z - filter through GZip. f - use following filename for output.

Bring Down a Frozen/Locked System

So, your Linux box locks up. I found this article that details a kernel-based method to bring it down, slightly more gracefully than pulling the plug.

Press the SysRq and Alt keys simultaneously, then type REISUB in sequence.

Fun Stuff

as root, run visudo. Add the line Defaults insults. sudo will now have an attitude.

Views
Notice - this is a static HTML mirror of a previous MediaWiki installation. Pages are for historical reference only, and are greatly outdated (circa 2009).