Debian Essential Commands Reference
Contents
- Help
- Package management
- System Configuration
- Files and directories
- Users and Groups
- Networking
- Hardware
- Disks and Partitions
- Troubleshooting - logging
- Archival
- Copying Files Between Machines
- Processes
- Modules
- Resource usage
- PCMCIA / Cardbus
- Miscellaneous
- Time and Date
- Network Packet Capture
- Finding Info About Hosts
- To do
Help
info <program-name>
man <program-name>
Package management
Useful switches for aptitude:
-s- simulate actions, but do not actually perform them-V- show which versions of packages are to be installed-Z- show the change in installed size of each package-D- show the dependencies of automatically changed packages-v- display extra information. (may be supplied multiple times)
Update the list of available packages from the apt sources: aptitude update
Install specific packages: aptitude install <package> <package> <package>
Upgrade installed packages to their most recent version. Installed packages will not be removed unless they are unused; packages which are not currently installed will not be installed: aptitude upgrade (use with -svVZD for a simulated run with lots of detail; use with -vVZD to run for-real with lots of detail)
Upgrade installed packages to their most recent version, removing or installing packages as necessary:
aptitude dist-upgrade
Try hard to fix the dependencies of broken packages, even if it means ignoring the actions requested on the command-line: aptitude -f install
Search for a package by name or part of name: apt-cache search <package>
Display detailed information about a package: apt-cache show <package> or aptitude show <package> or dpkg -p <package>
Display information about a package's version, dependencies and reverse dependencies: apt-cache showpkg <package>
Display more detailed information about a package's versions available and where they'll be installed from: apt-cache policy <package>
list all files included with a particular package: dpkg -L <package>
Find which package provided a particular file: dpkg -S <file> or use or use http://packages.debian.org or on #debian !find <file> <Debian version name>
Display information about a package including its configuration files:
dpkg -s <package>
Add Apt download sources: apt-setup
(this command not available in Sarge but not Testing/Etch)
Add a CD/DVD to your sources list: apt-cdrom add -d /...
List all installed packages and their versions: dpkg -l
Reconfigure a package: dpkg-reconfigure <package>
Choose a specific priority for questions:
dpkg-reconfigure -plow|medium|high|critical <package>
List all installed packages with version number and a summary of their purpose:
dpkg -l
See if a particular package is installed and what version it is:
dpkg -l | grep <package>
Find the location of a package: whereis <package>
List package signing keys: apt-key list
System Configuration
tasksel
debconf
Debian base system configuration. (not included in Testing/Etch): base-config
Set the system time: date --set=13:17
/etc/hosts and /etc/hostname contain the name of the machine.
Files and directories
Find all files containing specific text in the current directory and all those below, case insensitively:
grep -i "<string of text>" * -r
List files and directories, without hiding entries with a .; listing entries by columns;
appending an indicator to entries to signify their type: ls -aCF
List files and directories, with information on permissions and (human readable) file sizes:
ls -lh
Display how large the contents of directories are:
du --max-depth=1 -h (I need to check --max-depth=1 totals up everything in every sub-directory)
Find a file, looking everywhere down from the current position:
find -name <filename> or find -name <filename*>
Find a file: locate - (use updatedb after you've made changes to the files on the system, such as when installing a package)
Change mode: chmod
Change ownership: chown
Change a file's creation date:
touch -m -d 19-sept-2007 <file>
Change a file's creation time:
touch -m -d 08:17:10 <file>
Change a file's creation date and time:
touch -m -d "11/20/2003 12:48:00" <file>
Copy files from source directory to target directory, replacing files in target if older than those in source, deleting source files as it progresses (requires the rsync package be installed); like if you were able to 'mv -u <source directory>/* <target directory>/ -r' but you can't in BASH:
rsync -avz --update --remove-source-files <source directory>/ <target directory>
Users and Groups
Add a user: adduser <user>
Delete a user: deluser <user>
Add a group: addgroup <group>
Delete a group: delgroup <group>
Add a user to a group: adduser <user> <group>
Delete a user from a group: deluser <user> <group>
Change a user's UID: usermod -u <new UID> <username>
Networking
Configure a network interface: ifconfig - i.e. ifconfig eth0 netmask 255.255.255.0 broadcast 10.0.0.255 route? gateway? 10.0.0.1
Disable a network interface: ifdown eth0
Enable a network interface: ifup eth0
Restart all networking: /etc/init.d/networking restart
Look for a DHCP server and renew the IP address: dhclient
Find your IP address: if you're root you have ifconfig in your path; non-root users can still
use it to find the IP address by running it directly: /sbin/ifconfig.
Find your IP address: ip addr
Show open ports and whether they listen on just localhost or for remote connections: netstat -l -t -p
Display the routing table: netstat -r
Probe a machine for open ports: nmap -v -A <IP address or hostname>
Hardware
List all PCI (and PCMCIA) devices: lspci
List all USB devices: lsusb
List some PCMCIA device information: lspcmcia
Turn on DMA (use with caution): hdparm
Scan hardware (needs installing): discover
Get a listing of the devices found on the USB do: cat /proc/bus/usb/devices
echo "scsi add-single-device 1 0 5 0" > /proc/scsi/scsi
^ ^
| |
SSCI-bus --+ +----- SCSI-id
Linux provides a simple mechanism to probe a SCSI device on demand. The kernel will probe and recognize the device. This needs to be done as root. (The first zero stands for the first SCSI-channel on your adapter and the last one for the LUN).
Another method (if you're using modules and if the scanner is the only device on the bus) is to unload the modules (SCSI-card and SG) and reload them.
Take a look at scsidev, a utility that comes with Debian distributions. http://www.garloff.de/kurt/linux/scsidev/ SuSe nowadays comes with a script rescan-scsi-bus.sh. And finaly, Oliver Rauch has a tool available. See http://www.rauch-domain.de
scsiadd (not installed by default)
- Scan SCSI bus:
scsiadd -s - Add device at this address:
scsiadd -a <host> <channel> <id> <LUN> - Remove device at this address:
scsiadd -a <host> <channel> <id> <LUN>
Disks and Partitions
Setting Up Partitions
List partitions on a disk: fdisk -l
Partition a disk / Define or redefine the partition's filesystem type that will be used on it:
# cfdisk /dev/<disk device reference i.e. sdb>
Choose 'Type' → choose the filesystem type such as '83 Linux', '0B W95 FAT32', '0C W95 FAT32 LBA' (I need to research the difference between these two), '07 HPFS/NTFS' (AKA NTFS) → choose Write
Format a partition. When you create partition(s), decide what filesystem you want to use.
The most likely you'll want for GNU/Linux is ext3, but you may for example be formatting flash media which usually use FAT.
Format partitions using the correct tool for the particular file system.
(two -c's cause it to do a read-write bad block test before creating the file system and it takes a long time. You can speed it up by using just one -c so it does just a read test, or remove both -c's to not test for bad blocks at all)
- ext3:
mkfs.ext3 -c /dev/<disk partition reference i.e. hda1>
(AKA mke2fs) - MSDOS FAT12 and FAT16:
mkfs.msdos -c /dev/<disk partition reference i.e. hda1>
(AKA mkdosfs and mkfs.vfat)
Note: requires the dosfstools package to be installed. - MSDOS FAT32:
mkfs.msdos -c -F 32 /dev/<disk partition reference i.e. hda1>
(AKA mkdosfs and mkfs.vfat; Note that a FAT32 filesystem cannot be too large)
Note: requires the dosfstools package to be installed. - NTFS (version 1.2, AKA NTFS4):
mkfs.ntfs /dev/<disk partition reference i.e. sdb1>
(AKA mkntfs)
Note: requires the ntfsprogs package to be installed.
Note: mkfs.ntfs doesn't use the -c flag the same way other varients do
Label a partition
- ext3:
e2label /dev/<disk partition reference i.e. hda1> <label> - ext3:
mkfs.ext3 -L <label> /dev/<disk partition reference i.e. hda1> - MSDOS FAT12, FAT16 or FAT32:
mkfs.msdos -n <label> /dev/<disk partition reference i.e. hda1> - NTFS:
mkfs.ntfs -L <label> /dev/<disk partition reference i.e. hda1> <label>
Copying Partitions
Copy one partition to another:
dd if=filename.img of=/dev/fd0 bs=1024 conv=sync; sync
- copy a floppy disk image to a floppy disk (but is the '; sync' necessary?)
Troubleshooting - logging
Print the last 10 lines of a particular file:
tail <file>
With more than one file, precede each with a header giving the file name. Useful for looking at log
files.
Run a command repeatedly, displaying its output (the first screen-full):
watch <command>
This allows you to watch the program output change over time. By default, the program is run every 2
seconds.
Set the level at which logging of messages is done to the console:
dmesg -nlevel1
(-1 prevents all messages, except panic messages)
Archival
tar/gzip
- archive a location:
tar -vcpzf <filename>.tar.gz <location>-v: verbosely list files processed-z: filter the archive through gzip-p: preserve permissions-f: use stdin/stdout-c: create a new archive
- extract an archive:
tar -xzf <filename>.tar.gz-z: filter the archive through gzip-p: preserve permissions-f: use stdin/stdout-c: create a new archive
- list contents of a .tar.gz / .tgz file: tar -tz <file>
- list contents of a .gz file: gzip -l <file>
Copying Files Between Machines
Securely copy a single file from 'server' (logged into as root) to this computer:
scp root@server:/etc/passwd .
Securely recursively copy a directory from 'server' (logged into as root) to this computer:
scp -r root@server:/etc/* .
Securely copy a single file from 'server' (logged into as root) to this computer, preserving
modification times, access times, and modes from the original file:
scp -pr root@server:/etc/* .
Processes (known as 'services' in Windows)
htop
top
pstree
/etc/init.d/<package> restart | start | stop
ps - report a snapshot of the current processes
ps auxps aux | grep <package>pgrep <program>
kill - kill a running process. See ps.
pkill <package>killall <program>
Modules (known as 'drivers' in Windows)
Get information about a running module: modinfo <module>
Specifically, get the version of a running module: cat /sys/module/<module>/version or modinfo <module> |grep -i version
Install a loadable module in the running kernel: insmod
Show the status of modules in the kernel: lsmod
modprobe
Show lots of information about a kernel module: modinfo <module>
modutils
Configure modules: modconf
Resource Usage
ps aux
ps axjf
pmap -d <process ID>
PCMCIA / Cardbus
cardctl status
cardctl info
Miscellaneous
Display system information: uname -a
Become super user (AKA root): su
Show swap usage: swapon -s
Time and Date
Manually set system time and date
Set the time, example:
date -s 11:25
Set the date, example:
date -s 10/20/2007
Set the time and date, example:
date -s "10/20/2003 11:25:00"
Network Packet Capture
Display a synopsis of packets transferred through an ethernet interface:
# tcpdump -i <ethernet interface i.e. eth1>
You can pipe through grep if you're looking for a particular IP address
Finding Info About Hosts
Get DNS A (IP address) record for a domain:
dig <domain name to search for>
Get DNS A (IP address) and NS (nameserver) records for a domain:
dig <domain name to search for> any
Get DNS MX (mail exchange) record for a domain:
dig <domain name to search for> mx
Reverse DNS lookup for a domain - map IP address to a name:
dig -x <IP address to lookup>
Get registrant, registrar, registration and renewal dates
whois <domain name to search for>
Get detailed host information (name, address, IP address block)
whois <IP address to lookup>
Detect operating system, server software and versions:
nmap -A <IP address to scan>
Note: with dig you can use '@<name server domain name>' when troubleshooting DNS issues to query a specific DNS server, from root name servers downwards.
Note: with dig you can use '+trace' to show the full delegation path.
To do
cp --archive
mount -t smbfs -o username=winadmin,password=winadmin //server/winadmin /media/server