Friday, July 20, 2007

Linux - FreeBSD - commands

These systems are really close each other. FreeBSD comes from Berkeley and Linux comes from Finland so it's pretty sure some differences need to be - and here they are :)

Disk, filesystem



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

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

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


Networking


Show open ports and apps connected to them:
{linux}$ netstat -apne --inet
{freebsd}$ sockstat

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
{linux}$ dpkg -S /path/to/checked_file

Have we got a package like... (in (k)ubuntu you can use more friendly tools like synaptic, apt-get)
{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/"

Install a binary package
{linux}$ apt-get install package_name
{freebsd}$ pkg_add -r package_name
In FreeBSD you have packages made in distribution release time - unfortunately there are no binary upgrades for released version)

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

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

6 comments:

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.

rduht said...

To prepare for world of warcraft gold his big date,FFXI Gil a young man went 2moons gold up on to the roof AOC Power Leveling of his apartment building in order Atlantica gold to tan himself.Not wanting any tan lines to show, he sunbathed in the nude. Unfortunately,maple story power leveling the young man fell Knight Online Noah asleep while on the roof, world of warcraft power levelingand managed to get a Guild Wars Gold sunburn on his "tool of the trade".aoc power leveling He was determined not to miss his date,flyff power leveling so he put some lotion 2moons dil on his manhood and wrapped it 2moons power leveling in gauze.The blonde showed dog clothes up for the date at his apartment,Maple Story Power Leveling and the young man treated her world of warcraft gold to a home flyff gold cooked dinner,power leveling after which they archlord money went into the living room to watch archlord power leveling a movie.During the movie,last chaos gold however