|
Linux commands
Contents
Resources
Disk operations -- see also newbie guide
fdisk -l |
list all disks and partitions on your system, mounted
or not |
cfdisk /dev/hda |
partition the drive |
hddtemp /dev/hda |
harddrive temperature (above 40C
shortens life) |
du -ah | sort -n
|
display hard disk usage per directory
(can take ages!)
|
kdirstat |
display hard disk usage (use this)
|
parted |
a utility for partitioning; allows shrinking (cfdisk
doesn't seem to) |
fips |
utility to reduce partitions? |
resize_reiserfs |
increase or decrease reiserfs partition |
mke2fs |
make an ext2 file system (careful) |
mkfs.xfs /dev/sdc1
|
make an xfs file system (xfs_admin -L tv6 /dev/sdc1)
|
fsck .ext2 /dev/hda8 |
check data integrity (not tried this one -- be
careful) |
e2fsck |
check integrity of an ext2 partition |
e2salvage |
utility for salvaging ext2 partitions (homepage)
See also the package testdisk -- it may be better |
tune2fs -j /dev/hda3 |
add a journal to ext2
(turn ext2 into ext3) |
tune2fs -O ^has_journal /dev/hda4 |
remove a journal from an ext3 file system
(you can add / remove a journal without affecting data) |
reiserfsck |
check integrity of a reiserfs partition |
reiserfsck --check --logfile chck.log
/dev/sdb1 |
run this first -- if it exits with
status 0, you're fine |
reiserfsck --fix-fixable --logfile
fixable.log /dev/sdb1 |
run this if the previous line exits with
status 1 |
mkswap /dev/hda2 |
create a swap file on an existing
partition |
swapon /dev/hda2 |
turn on the swap file |
mount |
list all mounted drives with permissions |
mount -a |
mount drives according to /etc/fstab (root only) |
mount nicco |
mount nicco as listed in /etc/fstab at default mount
point (see samba) |
mount /dev/hda8 vm |
mount the physical drive partition /dev/hda8 in the
directory (mount point) vm |
mount spello:/mnt/tv1 /mnt/tv1 |
mount the tv1 drive from spello, not
from cyberspace (when you need to specify) |
mount /dev/hdb cdrom |
To run a CD, insert it in the CD ROM and type this
string |
mount -n -o remount/rw / |
force a remount of a read-only drive |
mount -o loop -t iso9660 filename.img /mountpoint |
To mount an ISO image via loopback: |
umount mantaray |
unmount the drive mantaray |
hdparm -v /dev/hda |
list disk parameters, such as whether DMA
is enabled |
df -h |
displays the used and free space on all mounted drives |
di |
better than df |
du -s |
list the combined size of files in a directory |
du --max-depth=1 |
list the size of all immediate
subdirectories |
insmode rd |
insert the ramdisk module |
|
|
Find the largest files on your drive:
find / -mount -size +10000k
This found a dozen files on /dev/hdc8. Or just issue
large
You can modify the /usr/local/bin/large script to suit your purpose.
Sort files by date -- or remove duplicates
ls -c -lt
sort temp.log | uniq > podcast.log
Undelete a file
- e2undel works on ext2 file systems -- see man e2undel for
details
- If possible, unmount the partition where the file was
deleted
- e2undel -d /dev/hda7 -a -s /tmp
Global replace in multiple files
To replace all instances of
editor@cogweb.net
with
"webmaster at cogweb dot net"
use the K-File-Replace Plugin in Quanta -- press Ctrl-Alt-f (not
tested)
You could also use this command in each directory (didn't bother to
make it recursive):
perl -p -i -e 's/editor\@cogweb\.net/\"webmaster\
at\ cogweb\ dot\ net\"/g' *.html
perl -p -i -e 's/editor\ at\ cogweb\.net/\"webmaster\ at\ cogweb\ dot\
net\"/g' *.html
Of course you could put it in a small bash script to make it recursive;
for a start see /vm/scripts/replace.sh.
umount
For stubborn hard drives or CDs that won't unmount, try
running "lazy unmount" first:
umount -l
This removes the drive in "lazy" mode -- the mount-point "vanishes" for
all programs whose working directories are not within that mount point.
Once all the files are closed the filesystem is fully unmounted.
If this doesn't work, you can also kill processes that hold up the
unmounting:
fuser -m
/mnt/vm # whatever the
mount point is
to find out which PIDs are using it. Once you kill those
processes you should be able to umount it -- typeically, however, they
are simply
konsole instances that you should log out of, or change directory out
of the mounted drive.
To accomplish both in one stroke, issue
fuser -k /mnt/vm
the -k option should identify and kill the processes that
are running on that filesystem (file or directory).
Note that if you have exported a file system through NFS,
you won't be able to unmount it afterwards unless you first unexport it:
exportfs -u clitunno:/mnt/tv1
To
reexport the volume, just issue "exportfs clitunno:/mnt/tv1". You can
of course also unexport all volumes, but this is generally not what you
want:
just stop nfs-kernel-server
Then unmount the drive and reexport the other volumes (this is clutzy):
just start nfs-kernel-server
If you don't leave the nfs-kernel-server down for more than a few
seconds or maybe minutes, the connections will resume cleanly without
human intervention, but it's still better to use exportfs to do a
volume at a time.
DOS commands: note that PartitionMagic 6 will corrupt
reiserfs partitions. See also Lilo.
Environmental variables
To add a new directory to the default path, issue
export PATH=$PATH:/usr/local/bin
See bash programming examples in /vm/video/scripts
Set default editor (/usr/bin/mcedit-debian is nice for cron,
or you could use nano):
update-alternatives --config editor
Characters turned to odd symbols
cat'ing a binary file can cause all the characters you type
to show up as odd symbols. Cause: The binary file contained a 016 (so,
Shift Out) character. Solution: Print a 017 (Shift In) character. You
can use
echo -ne "\\017"
to do this. Even better, make it a shell script called 'fix' for easy
access. Reason: Shift Out is canceled by a Shift In.
You can also try to issue
reset
That should be enough. If not, write
setterm -reset
if you just lose a cursor; this is aliased to ungarble on my user.
Terminating processes (see also Freeze and crash recovery strategies)
There are several ways to terminate a program in Linux,
either because it is hanging, or because you're maintaining the system
remotely, or for some other reason.
Method 1: On the command line
In a console, issue "ps aux" to find the PID (process ID), and issue
kill <PID>
If that doesn't do the trick, try
kill -9 <PID>
You can also do this through the program top, which displays
all running processes. Press k and enter the PID to terminate the
process.
Finally, you can kill all processes related to a particular
application by issuing
killall <application name>
The application name has to be the one listed in top or ps aux.
Method 2: Same thing with a GUI
Alternatively, in KDE you can press Ctrl+Esc and get a
window with all running processes, select the offender and press Kill.
Method 3: Forget the PID, I just want to get rid of the thing
Finally, in KDE you can also press Ctrl+Alt+Esc and get a "skull and
bones" icon -- move it over the offending application and click to
terminate it.
kill all processes for some user:
su - johndoe -c 'kill -9 -1'
Terminating a hanging application does not cause problems in Linux --
there's no point in rebooting.
Frozen terminals
If everything freezes, check out instructions in
/usr/src/linux/Documentation/sysrq.txt (assuming you have another
computer handy).
Sysrq can also be used to set logging levels:
ALT+SYSRQ+0 should set the log level so that you don't see
anything. Depending on what priority those messages are logged
at, ALT+SYSRQ+2 or 3 might be enough, and still let critical messages
show on the console. See also setterm(1).
If a reboot or shutdown command isn't working, try "reboot -nf" (doesn't sync) or else
echo s > /proc/sysrq-trigger
echo u > /proc/sysre-trigger
echo s > /proc/sysrq-trigger
echo b > /proc/sysrq-trigger
This will "sync", "umount/remount read-only", "sync",
"immediate hardware reboot". Should always work, as long as sysrq
is enabled in a 2.6 kernel. On the keyboard, this should work by
hitting Alt+PrtScr+S, +U, +S, +B
Submit a bug report
Launch "gdb <application that crashed>" as root, and then type:
(gdb) set args --gst-debug-level=0 >/dev/null
(gdb) run
You should lose the gdb prompt for a second, then the program
should
segfault, and you should get the gdb prompt back. Then run
in gdb:
(gdb) thread apply all bt full
and paste the output in the bug report.
File operations
File permission changes that involve changing users and
groups will generally not take effect until the user has logged
completely out of his or her session, from x-windows all the way out of
the console.
cat |
display the contents of a file |
chmod 664 <filename> |
change permissions |
chmod 4755 <filename> |
set suid root for executable |
chown <user.group> <filename> |
change who owns a directory or file |
chmod u+s /usr/sbin/<filename> |
set uid root (allow non-root users to run the program
with root privileges) |
cp |
copy <original> <target> -- see also scp |
cp -R |
copy directories and files recursively -- for large
jobs, use tar |
cp -s <file> <file> |
make a symbolic link between two files (or
directories) |
dd if=/dev/sda of=/dev/sdb
|
clone an OS drive
|
diff <file1> <file2> |
show the difference between two files
(cf. kompare, xdiff, et al) |
diff -q -r <dir1> <dir2>
|
list which files are different in two
directories |
diff -ruNp |
create a diff patch for lkml etc
|
dmesg |
see the boot messages (dmesg | lpr -- print the file) |
du -s |
list the combined size of files in a directory |
du | grep keyword |
find file names that contain the keyword
string |
egrep '^flags.*(vmx|svm)' /proc/cpuinfo
|
determine if CPU supports virtualization (elegant regular expression)
|
egrep '(txt|avi)' filename
|
use egrep to locate the string 'txt' and/or 'avi' in a file -- see bash
|
file <file name> |
determine file type and list detailed
characteristics |
find -type l |
find symbolic links |
find / -name -mount string* -print | less |
find file names (works, but slow -- see locate) |
find -type f |
find file names |
find -iname string* |
find library files? Not sure about the iname switch. |
find ~/ -name \*finger-eat\* -print |
This will find files with the string
finger-eat in my directory recursively
|
find / -iname \* 2> /dev/null
|
list all files, pipe errors to /dev/null
|
fmt -u myessay.txt |
remove double spaces in text files |
fmt one -w 50000 >one2.txt |
remove newlines in paragraphs -- better
to use
kword's old style import filter, then cut & paste
txt2html --extract one >one.html and cut & paste |
ftff string |
find files in the current directory tree
-- a case insensitive and fault tolerant way of 'find . -name xxxx
-print'. |
ftwhich |
finds files in current PATH, fault
tolerant search algorithm |
gawk |
Find and Replace text within file(s)
|
grep -C 3 <string> |
Find a string and the 3 surrounding lines (context) |
grep -n <string> <file> |
Search the contents of a file or set of files |
grep <string> * -r |
Search all files in all subdirectories
for the string |
rgrep <string> * -r |
Search for literal string, no regex (eg
a$*b?) |
grep ^$ *
|
Search for blank lines
|
grep "[0-9]" memo
|
Search for numbers -- see guide
|
gs -dNOPAUSE -sDEVICE=pdfwrite
-sOutputFile=merged.pdf *.pdf -c quit |
Merges all .pdf files in the directory;
you can also use pdftk (does lots) or pdfmerge |
gs -dNOPAUSE -sDEVICE=pswrite
-sOutputFile=foo%2d.ps x*.ps -c quit |
Splits a ps (or pdf) file into
individual pages |
gunzip <filename.wad.gz> |
untar command -- it makes its own
directory; cf. tar
(note that lynx can read .gz files) |
finger john@foo.bar.com | grep -i -A 2
smith | less |
Ignore case and output 2 lines for each
match |
ldd <program name> |
list dependent libraries |
locate <file> |
fast find, uses a database -- details below
|
locate /etc/*session |
find all files in all subdirectories under /etc that
contain "session" |
look
|
display lines beginning with a given string
|
ls -c |
with -lt: sort by, and show, ctime (time of last
modification of file status information)
with -l: show ctime and sort by name
otherwise: sort by ctime |
ls -lh |
human-readable |
ls -x |
list file names only, multiple columns |
ls -1 |
list file names only, in a single colum |
ls -R |
list all subdirectories with all files in multiple
colums |
ls -lR |
list all subdirectories with all files in single
colums, with times |
ls -ltc |
list files by modification date! |
ls -l -S -r
|
list files by file size, reversed
|
lsof |
list open files |
ldd <program> |
list library dependencies . |
ln -sf <file1> <file2> |
creates a symbolic link to file1 called file2 (FAT32
file systems don't handle this) -- cf. realpath
|
lsmod |
list loaded kernel modules |
md, rd |
make and remove directories |
modinfo <module> |
show module information |
rmmod -r video1394 |
unload the module video1394 |
insmod <module> |
load any module |
modprobe <module> |
load a module that is defined in /etc/modules.conf |
/etc/modprobe.preload |
list modules preloaded in the kernel
(not tested) |
ldconfig |
update library links |
pico -w +644 <file> |
open file at line 644 |
ps ax | grep xfs |
finds processes and searches for xfs, listing only
that |
realpath <file>
|
show the real path of a file, not symlinks
|
rpm -Uvh <filename> |
install an rpm file |
rpm -q <package> |
find package version installed |
rm -r |
remove files and directories recursively |
rm */<string>
|
remove all files matching string in all immediate subdirectories
|
scp <original> <paco:/target>
scp file cogweb@cogweb:
|
copy a file to another computer using ssh (use sftp
to copy scattered files in different directories) -- you may need the
colon to indicate this is remote |
lsmod | sort -nrk 2
|
sort numeric reverse by second column
|
sort temp.log | uniq > podcast.log |
sort and remove duplicates
|
strings `which xfs` | grep "^/" |
lists files that contain xfs, including the
configuration file |
tar -C /home/httpd_real -c |
the best way to copy whole directory trees? |
tar -cvvf foo.tar foo/ |
put all files in the directory foo/ into
the tarball foo.tar (watch your space!) |
tar zxvf <filename.tar.gz> |
untar command -- it makes its own
directory |
touch <file> -d "2005-06-10 04:50"
|
change the last modification date of a file
|
uniq -cd phone_list.txt |
remove duplicates in a list (source) |
wc <filename> |
word count (lines, words, and characters) |
lynx -dump http://some.web.page | wc |
word count in online document through lynx |
|
|
Masks
022 => drwxr-xr-x
033 => drwxr--r--
044 => drwx-wx-wx
055 => drwx-w--w-
066 => drwx--x--x
077 => drwx------
Find text in files
grep -i -I passion * -r
will find all non-binary ( -I ) files with the string
passion, ignoring case ( -i ) in any file recursively. It searches
whatever is mounted, including the novell file system.
Note that all packages that get installed get copied to the
installer's ./kpackage directory. This might be convenient -- no need
to keep the originals anywhere else.
Pressing ctrl-C in pico gives you the line number of the
cursor
For helpful hints, see http://home.c2i.net/dark/linux.html
vi -- see http://ist.uwaterloo.ca/ec/unix/viprimer.txt.
- esc ZZ -- save
- gg -- go to start of file
- G -- go to end of file
- ? -- search backwards
- :%s/old/new/g -- replace old with new globally (\n is line feed)
- : set nowrapscan
- :q! -- quit without saving
- :wq -- write and quit
How do I find files on my system?
The simple answer is one of these:
locate string
find / -name *string* -mount -print | less
There are two methods to search for files on your Linux
machine, one method being the locate command and the other being the
find command. If you wish to use the locate command, you must first
update the locate database by running the following command in a
terminal as root:
/usr/bin/updatedb
This will create an index of all the files and their
locations
on your hard drive. Once updatedb has completed running, you may now
search your drive for a specific file by running the following command
in a terminal:
/usr/bin/locate filename
It
may be useful to customize the locate and updatedb commands for various
users. Set permissions in /var/cache/local so that another user
can write to it and add this sort of thing to the user's .bashrc
alias locate='locate -d /var/cache/locate/locatedb-steen'
alias updatedb='updatedb --output=/var/cache/locate/locatedb-steen --localpaths=/vx/fuma'
That lets the user maintain his own file database that contains his
files rather than irrelevant system files. Meanwhile, user root can use
the default setup and search all files.
Another way to search your linux system is with the find
command. To find a file on your sytem with the find command, in a
terminal run the follwoing:
/usr/bin/find / -name filename
Be sure to replace "filename" with the actual name of the
file.
find / -name "httpd.conf" -ls
http://www.linuxhelp.net/
How to split files
$ split -b 200k aa.tar.gz aa.tar.gz.pieces.
$ for i in aa.tar.gz.pieces.* ; do echo $i | mutt <EMAIL:
PROTECTED> -= a $i ; done
$ rm aa.tar.gz.pieces.*
If you don't have mutt you can use
$ for i in aa.tar.gz.pieces.* ; do uuencode $i $i | mail
<EMAIL: PROTECTED>= ns.it ; done
Network
arp -a |
display the ARP cache (recent connections) |
exportfs host:/mnt/tv1 |
export a volume to another host |
exportfs -u host:/mnt/tv1 |
unexport the volume, so you can unmount it |
host <system name> |
show IP address or name |
ifconfig |
internet configuration |
lpstat -t |
show cups printers (see printers) |
lpstat -t -h graywhale |
show cups printers on a remote system |
ethstatus |
see traffic speeds |
netstat |
show connections |
netstat -in |
show interface table |
netstat -rn |
show routing table |
netstat -tlnp |
show all listening ports |
nmap <system name> |
list open ports on local or remote system |
rpcinfo -p |
show nfs processes (see nfs) |
screen |
multiply the console -- see details & dtach
|
sftp student@killerwhale |
log into user@host with the ssh secure
shell ftp |
showmount -e |
show nfs exports (see nfs) |
showmount gubbio |
nfs exports on gubbio |
xdpyinfo -display $HOST:0.0 |
find out if you have display rights |
xterm -display gubbio:1 |
start xterm in gubbio's vncserver :1 (done
from gubbio) |
wget -c |
resume a wget download |
test $DISPLAY && dcop kdesktop
default logout |
shut down x-windows in the terminal
(remotely) |
|
|
Talking to another user
- write <user name>
- talk <user name> (requires the talkd daemon)
- talk root pts/3 (if you have several with the same user name)
- mesg y (allow people to write to you)
- echo "say something" | wall (writes to everyone on the machine)
These are handy commands to communicate with another
user on your machine.
Managing users and groups
adduser |
add a user and home directory (see man
page) |
adduser steen root |
add user steen to group root |
deluser |
delete a user and its home directory and
mail account |
chfn
|
change a user's full name
|
groupadd |
create new group |
groupdel |
remove group |
groups |
show group membership of current user |
groups <user> |
show group membership names (groups are
listed in /etc/passwd and /etc/group) |
id <user> |
show group membership ids and names |
last |
list the last users of the system |
pwconv
|
regenerate a lost or corrupt /etc/shadow
|
useradd |
add user (also creates home directory if
this is default) |
userdel |
delete user |
usermod root -G root |
remove root's membership in all groups
except root |
users |
show user names |
kdesu -u root -- etherape |
run a program as another user |
kcmshell 'System/kdm' |
edit KDM interface |
su -p root
|
become root, but preserve
current environment
(allows you to run x-apps etc.)
|
System Information (start with lspci
and kinfocenter)
chkconfig cpufreqd off |
control cpu frequency daemon (not tried
this command) |
df -h |
displays the used and free space on all mounted drives |
du -s |
list the combined size of files in a directory |
fc-list |
list availble fonts |
glxinfo |
get information about a GLX extension and
OpenGL renderer |
hdparm -v /dev/hda |
list disk parameters, such as whether DMA
is enabled |
hwinfo |
hardware information galore, based on a
probe |
kcmshell 'clock' |
reset the time (you can do this in remote X) |
kinfocenter |
use KDE to see system information |
ldd <program name> |
list dependent libraries |
ldconfig -v | grep string |
display dependent libraries, find the
version of one |
less /proc/config.gz |
see configuration of the running kernel |
ls -l /usr/bin/rc* |
list all the rc program calls |
lshw |
list all hardware specs
(new Mar 03 and inaccurate at times) |
lspci |
list pci devices (use update-pciids
occasionally) |
locale |
shows current locale definitions (reset
with "just reconfigure locales") |
locale -a |
show available locales (set with export
LC_ALL=POSIX) |
locale charmap |
shows the currently defined character map
(ANSI_X3.4-1968 means ASCII) |
man 7 locale
|
syntax for accessing manual pages from a
certain section
|
more /proc/cpuinfo |
list current CPU information |
more /proc/fb |
list current frame buffer device information |
more /proc/interrupts |
lists IRQs |
more /proc/meminfo |
list current memory usage |
more /proc/mounts |
list mount points with all variables (more
than fstab shows) |
more /proc/mtrr |
list current mtrr information |
more /proc/partitions |
lists all partitions -- possibly also
unmounted ones? |
more /proc/version |
list operating system information (cf.
uname) |
pnpdump |
finds lots of stuff! |
pstree |
shows the currently running processes as a tree |
procinfo
|
shows lots of info from /proc
|
rpm -q <package> |
find package version installed |
screendump 4
|
display content of virtual terminal 4
|
setxkbmap -model pc105 -layout no -variant
basic |
Set Norwegian keyboard (useful in IceWm) |
setxkbmap -model inspiron -layout us
-variant pc105euro |
Set US keyboard (see options in KDE
Control Panel's international keyboard selector) |
just reconfigure sl-modem-daemon |
reconfigure the modem to a new country |
tzconfig |
set new time zone |
uname -r |
prints OS version information (cf. more
/proc/version) |
xset -q |
display information about x-windows
settings (see man xset) |
System debugging
Compile in CONFIG_MAGIC_SYSRQ and then when the load goes up
do
alt + sysrq + t
Check the call traces, for instance from from events/0
Debian admin (cf. popular
admin packages)
See also
apt-cdrom add |
adds the current CD to
/etc/apt/sources.list |
apt-get build-dep pine
apt-get -b source pine |
retrieve pine and build dependencies, and
build it |
echo $LANG |
show current language setting (= locale) |
export LANG=POSIX |
set language for locale |
export LC_ALL=POSIX |
set all other values of locale |
just list | grep <string> |
show installed packages that match |
just list-names <string> |
show any packages that match |
just status <package name> |
show installed status of package |
just show <package name> |
show information on package |
just whichpkg <filename> |
which package provides this file or
program? |
just changelog |
list the changelog of a package to assess
if you want to get it |
apt-listchanges
<full package path and name> |
list the changelog of a package to assess
if you want to get it |
just findpkg
just unofficial |
search for an unofficial Debian package at
apt-get.org |
just install <package name> -s |
simulate an installation |
just show-upgrade |
simulate an upgrade |
just show-dist-upgrade |
simulate a distro upgrade, e.g. from woody
to sid |
just update (cf. dselect update)
|
get the latest list of packages |
just toupgrade |
see what is available to upgrade |
just upgrade |
upgrade packages |
just install <package name> |
install a package |
just fix-install |
use if installation is interrupted |
just fix-configure |
use if configuration is interrupted |
dpkg --configure -a |
use if configuration is interrupted -- may do a better job than just fix-configure
|
apt-get -o Debug::pkgProblemResolver=true
dist-upgrade |
run debug on the dist-upgrade command |
just install libarts1=1.1.4-2 |
install a particular version (could force
a downgrade) |
just status | grep 3.2.3-2 | grep 3.3.0-1
| cut -f1 > list && just install-file list |
upgrade all packages of a certain version
to another version if available |
just status | grep 3.3.0-1 | grep 3.3.0a-1
| cut -f1 | xargs just install |
same as above in one line |
just dependees |
list all dependent files |
just show-remove <package name> |
simulate removal |
just remove |
uninstall package, keep configuration files |
just purge |
uninstall package and configuration files |
just purge-depend |
uninstall package, configuration files,
and all dependent packages |
just force <package name> |
use to override warnings |
just force <package file.deb> |
ditto with local package |
dpkg -i --force-depends <package
name> |
use to override dependencies |
dpkg -i --force-depends
<packagefile.deb> |
ditto with local package (stronger) |
dpkg -r --force-depends <package name>
|
force removal
|
just hold <package name> |
put a package on hold (don't update) |
just unhold <package name> |
unset a hold (in /var/lib/dpkg/status) |
just reconfigure <package name> |
reconfigure package |
just reconfigure locales |
set default character set |
just reconfigure console-common |
set keymap at boot |
gkdebconf |
frontend for reconfigure |
|
|
apt-show-versions |
|
dpkg-repack |
recreate a debian package from an
installed package |
just auto-clean |
remove all non-current packages from
/var/cache/apt/archives |
dpkg-divert |
move symlinks for a package (not tested) |
just clean |
remove all packages from
/var/cache/apt/archives |
Some init.d scripts fail to start with "just start". I believe "just
start" calls "invoke-rc.d", as in "invoke-rc.d exim4 reload". So
sometimes this invoke-rc.d isn't working and you have to run the script
directly with "/etc/init.d/exim4 reload".
Building packages from source
Software
- devscripts
- dh_make
- dpkg-dev
- fakeroot
Building non-debian packages
- ./configure --help
- dh_make -s
- pico debian/rules for ./configuration options
- fakeroot dpkg-buildpackage
When building packages, you may need to edit the debian/rules file and
comment out some commands to get it to compile.
Building debian packages
Various packages build in different ways. For instance, I had to patch
ntsc-cc in the xawtv package source by doing this:
Gerd Knorr: Just put the patch into
dist/<some-name>.diff and rebuild.
I tried that and issued fakeroot dpkg-buildpackage from
/share/software/tarballs/xawtv/xawtv-3.94 -- the source remained tarred
and gzipped. The build process asked for the file to patch (it wasn't
correct in the patch), and I entered "vbistuff/ntsc-cc.c", which it
accepted and then built the Debian package. The patched file ended up
in /share/software/tarballs/xawtv/xawtv-3.94/work/xawtv-3.94/vbistuff
Here's another example:
apt-get source schroot
cd schroot-0.99.2
patch -p0 < /tmp/schroot-dchroot-compat-command.patch
dpkg-buildpackage -rfakeroot -us -uc
sudo dpkg -i ../dchroot_0.99.2-2_amd64.deb
Note the dpkg-buildpackage syntax.
Alternatives system
For
the "alternatives" system, you can now use the GUI galternatives (as
root). This system determines which application provides a service that
can be provided by more than one application. Useful for seiing
what is the default editor or browser for instance, though you may need
to do changes in nano. The values are set in
both /var/lib/dpkg/alternatives and /etc/alternatives -- it's a
complicated system.
Boot parameters
Determine order of module loading: snd_via82xx.index=0 saa7134.index=1
Miscellaneous
Delayed job execution
- Recurring jobs on a machine that is always on: cron
- Recurring jobs on a machine that is turned off: anacron
- Occasional jobs to be done at specific future times:
- at -- run the job at the time set, for example:
- at 5:00 -f /usr/local/bin/dv2xvid
- at now + 10 minutes -f record.sh
- atq -- see the at queue
- atrm -- terminate an at job
- batch -- run a job when system resources free up
- batch -f /usr/local/bin/dv2xvid
The batch command could in theory be useful for file compression --
start a new job once the previous has completed -- but I haven't tested
if it will in fact wait for the current job to end. The at command
certainly works. See man at for details.
CVS
cvs -d:pserver:cvs@cvs.xxx.com:/xxx login
cvs -z 3 -d:pserver:cvs@cvs.xxx.com:/xxx co module
The -z 3 sets compression level.
Examples of other useful options (see the CVS documentation
for details):
- cvs update -A (update from the head of the tree, and ignore
tags)
- cvs -n update (test only, don't make changes)
- cvs update -r Wine-YYMMDD (get the revision with the tag
for a Wine snapshot)
- cvs update -D date (get the revision associated with an
arbitrary date)
Job management
test $DISPLAY && dcop kdesktop default logout -- shut
down x-windows remotely
cron jobs -- see crontab and /etc/cron
Lots of good info on command line management: http://amath.colorado.edu/computing/unix/jobs.html
To run a program in the background, add a & at the end
of the command.
myprog > output.dat & -- run myprog in the
background, sending any stdout to the file `output.dat'
math -noinit -batchinput -batchoutput < cmmds > rslts
&
-- run Mathematica in the background, taking commands from
the file `cmmds' and writing all output to the file `rslts'
Run two or more instances of x-windows at the same time on one
machine:
first user # startx
second user # startx -- :1
The first user's session will be in Ctrl-Alt-F7
The second user's session will be in Ctrl-Alt-F8
at jobs
These are useful for starting jobs at some future
time:
at now + 3 hours -f /usr/local/bin/dv2xvid
at now + 2 minutes -f /usr/local/bin/grab
Normal procedure would be to create a shell script that calls the functions you want.
You can also use this to run something in the background:
at now -f /usr/local/bin/dv2xvid
backgrounding and foregrounding jobs -- try this (for details, see lesson):
while true; do saytime; sleep 600; done &
while true; do saytime; sleep 20; done &
while true; do saytime; sleep 1800; done &
jobs
fg 2
Ctrl-Z
jobs
bg 2
jobs
This is of course useful for managing dvgrab jobs, or transcode jobs.
If you start a job and then later want to background it, press Ctrl-z
first and then write bg. You can resume with fg.
Interrupt signals
This is useful for instance for terminating dvgrab remotely.
- typing ctrl-c sends the interrupt signal SIGINT to your
current foreground process
- The complete list of signals can be found on the signal(7)
manual page
- Issue man 7 signal to see it or enter kill -1 for a short
version of this list
- If no signal is specified on the kill command line, SIGTERM
is sent
- If SIGTERM was caught or ignored, send SIGKILL, which will
always work
It looks like you can be explicit about this:
kill -SIGINT 20371
kill -SIGTERM 20371 (default, doesn't need to be specified)
kill -SIGKILL 20371
Or you can use the numbers (details below):
kill -2 <dvgrab PID> (this is the SIGINT number)
kill -3 <less PID> (this is the SIGQUIT number -- useful for less)
- A related command is killall, which takes the name of the
process as an argument
- This is a convenient way to terminate all processes with
the same name
- You can specify path if you want to kill only a subset of
processes by that name
Here's the list of the first few signals, from kill -l:
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL
5) SIGTRAP 6) SIGABRT 7) SIGBUS 8) SIGFPE
9) SIGKILL 10) SIGUSR1 11) SIGSEGV 12) SIGUSR2
13) SIGPIPE 14) SIGALRM 15) SIGTERM 17) SIGCHLD
Note that SIGINT is 2. Issuing killall -2 dvgrab will create
clean files.
|
|