Friday, 20 July 2007

Linux - FreeBSD - Solaris - Windows commands

Update: Added Solaris (both OpenSolaris and SunOS) and Windows (where applicable) coverage for this set of commands.
Update 2: Coverage for redhat-fedora-centos Linux line / yum package manager.

Linux groups:
* Redhat base: Redhat, Fedora, Centos (yum/rpm packages)
* Debian based: Debian, Ubuntu, Kubuntu (dpkg/.deb packages)


Check what groups do I belong to?

{linux, freebsd, solaris}$ groups
{windows - active directory}> dsquery user -samid %USERNAME%|dsget user -memberof

Disk, filesystem

Disk usage
{linux}$ du -sh
{freebsd}$ du -sh

Count subdirectories in current directory:
{linux}$ du --max-depth=1
{freebsd}$ du -d1
{SunOS}$ du

Typical approach to find biggest directories/files on disk:
{linux}$ du --max-depth=1 -kx|sort -n
{freebsd}$ du -d1 -kx|sort -n

Find some kinds of files (regex is a mask for full path, no need for begin/end marks)
{linux}$ find . -regextype posix-extended -type f -regex ".*\.(java|class)"
{freebsd}$ find -E . -type f -regex ".*\.(java|class)"

Show open files and programs:
{linux}$ lsof
{freebsd}$ fstat

Real time disk usage (is there something which shows results for every disk in linux?):
{linux}$ vmstat 3
{freebsd}$ iostat 3

Swap info:
{linux}$ free
{freebsd}$ swapinfo


Show open ports and apps connected to them:
{linux}$ netstat -apne --inet
{freebsd}$ sockstat
{SunOS}$ netstat
{windows}$ netstat -b
netstat -b -v # slower but with tree of dependencies

Kernel issues

Show loaded modules:
{linux}$ lsmod
{freebsd}$ kldstat

Load kernel module:
{linux}$ modprobe SomeModule
{freebsd}$ kldload SomeModule

Remove loaded module:
{linux}$ rmmod SomeModule
{freebsd}$ kldunload SomeModule

Program development

Trace the system calls of a program:
{linux}$ strace
{freebsd}$ truss
(strace is also available in /usr/ports/devel/strace)

libraries - show all paths + libs:
{linux}$ ldconfig -p
{freebsd}$ ldconfig -r

Packages management

Different linux distros make it own way. I'll focus on debian-based distributions like Debian, Ubuntu, Kubuntu etc.

Find which package this file belongs to?
{freebsd}$ pkg_info -W /path/to/checked_file
{debian ubuntu}$ dpkg -S /path/to/checked_file
{redhat centos}$

Have we got a package like... (in (k)ubuntu you can use more friendly tools like synaptic, apt-get, kPackageKit)
{linux}$ apt-cache search your_name
{freebsd}$ cd /usr/ports; make search key=your_name
make search name=pear display=name,path
you can also try simple locate (only in package names):
{freebsd}$ locate -i your_name | grep "/usr/ports/"
{redhat centos}$ yum search name
yum provides name

Install a binary package
{debian ubuntu}$ apt-get install package_name
{redhat centos}$ yum install name
{freebsd}$ pkg_add -r package_name
{windows}$ msiexec /i package.msi
In FreeBSD you have packages made in distribution release time - unfortunately there are no binary upgrades for released version)

Update binary packages
{debian ubuntu}$ apt-get update; apt-get upgrade
{redhat centos}$ yum update

Install a package from sources
{debian ubuntu}$ apt-src
{freebsd}$ cd /usr/ports/path/package; make install clean

...The more I see the less I know...


Anonymous said...

On Debian and derivatives, to check what package a file belongs to:
dpkg -S /path/to/file

Rob said...

To search the ports tree in FreeBSD you can use several make search commands, have a look at man 7 ports for more info

Adam Bartosik said...

Thanks for debian/ports info. Do you know other day-to-day issues they are different on linux/freebsd?

dann said...

You can use pkgsrc to install source packages on Linux, similar to FreeBSD ports, I think.

zoltarx said...

Alternative to handy command in linux "which" would be "cmdwatch" in freebsd.

Anonymous said...

thanks for sharing this site. various kinds of ebooks are available in this site