Appendix B: BASH Command Index


This appendix provides a whistle-stop tour of commands that can be used at the BASH shell. This is a highly selective listing, which is to say it is a guide to commands that see day-to-day use on average desktop systems. In a similar fashion, although some command options are listed, they’re strictly limited to those that receive regular deployment.

The descriptions of each command are deliberately simple. It’s important to note that the quantity of space a command is given is not an indication of its importance or usefulness. To this end, commands in the list with an asterisk after their name offer far more than the brief description here hints at. In such cases, I strongly advise you to refer to the command’s man page for more information.

Various conventions are used in the list:

  • Italics: You should substitute your own details wherever italicized words appear.

  • $: Commands that can and might be run by ordinary users are preceded with a dollar sign ($).

  • #: Commands that require root privileges, or that are ordinarily run by root, are preceded with a hash (#).

Commands that present dangers to the system through misuse are clearly marked. Such commands should not be used without research into the command’s usage and function.

Command

Notes/Command Options

Example of Typical Use

$ alias

Create or display command aliases

alias list='l'

$ apropos

Search man pages for specified words/phrases

apropos "word or phrase"

$ bzip2

Compress specified file (replaces original file with compressed file and gives it .bz2 file extension)

-d: Decompress specified file

-k: Don’t delete original file

-t: Test; do a dry run without writing any data

bzip2 myfile

$ bzip2recover

Attempt recovery of specified damaged .bz2 file

bzip2recover myfile.tar.bz2

$ cal

Display calendar for current month (or specified month/year)

cal 4 2005

$ cat

Display a file on screen or combine and display two files together

cat myfile

$ cd

Change to specified directory

cd /usr/bin

$ cdparanoia *

Convert CD audio tracks to hard disk files

-B: Batch mode; convert all tracks to individual files

-S: Set CD read speed (2, 4, 8, 12, and so on; values relate to CD-drive spin speed; used to avoid read errors)

cdparanoia –S 8 –B

# cdrecord *

Burn audio or CD-R/RW data discs (the latter usually based on an ISO image; see mkisofs)

-dev=: Specify the drive’s device number (can be discovered by running cdrecord with the --scanbus option)

--scanbus: Scan to see which CD-R/RW drives are present and return device numbers

cdrecord dev=0,0,0 –speed=16 -v myfile.iso

-speed=:

Specify the write speed (2, 4, 6, 8, and so on)

-v: Verbose output; obligatory for feedback on cdrecord's progress

 

# cfdisk *

DANGEROUS! Menu-based disk-partitioning program

cfdisk /dev/hda

# chgrp

Change group ownership of a file/directory

-R: Recursive; apply changes to subdirectories

chgroup mygroup myfile

# chkconfig

Administer or display services that comprise current run level

chkconfig servicename on

$ chmod

Change permissions of a file/directory (where a=all, u=user, g=group, r=read, w=write, x=executable)

-R: Recursive; apply to subdirectories

--reference=: Copy permissions from specified file

chmod a+rw myfile

$ chown

Change file ownership to specified username

-R: Recursive; apply to subdirectories

chown username myfile1

# chroot

Change the root of the file system to the specified path

chroot /home/mydirectory

# chvt

Switch to the specified virtual terminal (equivalent of holding down Ctrl+Alt and pressing F1–F6)

chvt 3

$ clear

Clears terminal screen and places cursor at top

clear

$ cp

Copy files

-r: Recursive; copy subdirectories and the files therein

-s: Create symbolic link instead of copying

cp myfile1 directory/

$ crontab

Edit or display the user’s crontab file (scheduled tasks)

-e: Edit the crontab file (create/amend)

-l: List crontab entries

-r: Delete the crontab file

-u: Specify a user and edit their crontab file

crontab -e

$ date

Display the date and time

date

$ df

Display free disk space within file system

-h: Human readable; display sizes in KB, MB, GB, and TB, as appropriate

-l: Restrict to local file systems, as opposed to network mounts

df -h

$ diff

Display differences between specified files

-a: Consider all files text files (i.e. don’t halt when asked to compare binary files)

-i: ignore lowercase and uppercase differences

diff myfile1 myfile2

$ diff3

Display differences between three specified files

diff3 myfile1 myfile2 myfile3

$ dig

Look up IP address of specified domain

dig mysite.com

# dmesg

Display kernel message log

dmesg

# dosfsck *

Check and repair MS-DOS–based file hard disk partition (see also fsck)

-a: Repair without asking user for confirmation

-r: Repair file system asking user for confirmation when two or more repair methods are possible

-v: Verbose; display more information

dosfsck -rv /dev/hda4

$ du

Show sizes of files and folders in kilobytes

-h: Human readable; produce output in MB, GB, and TB

-s: Summary; display totals only for directories rather than for individual files

du -h /home/myuser

$ eject

Eject a removable storage disk

-t: Close an already open tray

eject /media/dvd-rom

$ emacs *

Start the emacs text editor program

emacs myfile

$ ex *

Start a simple text-editor program used principally within shell scripts

ex myfile.txt

$ exit

Log out of shell (end session)

exit

$ fdformat

Low-level format a floppy disk (this won’t create a file system; see also mkfs)

fdformat /dev/fd0

# fdisk *

DANGEROUS! Hard-disk partitioning program

-l: List partition table

fdisk /dev/hda

$ fg

Brings job running in background to foreground

fg 1

$ file

Display information about specified file, such as its type

file myfile

$ find *

Find files by searching directories (starting in current directory)

-maxdepth: Specify the number of subdirectories levels to delve into, starting from 1 (current directory)

-name: Specify name of file to search for

-type: Specify file types to be returned;

-type d returns directories and -type f returns only files

find -name "myfile"

$ findsmb

Search network for Windows file sharing (SMB) computers

findsmb

$ free

Display information about memory usage

-m: Show figures in MB

-t: Total the columns at bottom of table

free -m

# fsck *

Check file system for errors (usually run from rescue disc)

fsck /dev/hda1

$ ftp *

FTP program for uploading/downloading to remote sites

ftp ftp.mysite.com

$ fuser

Show which processes are using a particular file or file system

-v: Verbose; detailed output

fuser -v myfile

$ grep *

Search specified file for specified text string (or word)

-i: Ignore uppercase and lowercase differences

-r: Recursive; delve into subdirectories (if applicable)

-s: Suppress error messages about inaccessible files, etc.

grep "phrase I want to find" myfile.txt

# groupadd

Create new group

groupadd mygroup

# groupdel

Delete specified group

groupdel mygroup

$ groups

Display groups the specified user belongs to

groups myuser

$ gzip

Compress files and replace original file with compressed version

-d: Decompress specified file

-v: Verbose; display degree of compression

gzip myfile

# halt

Initiate shutdown procedure, ending all processes and unmounting all disks

-p: Power off system at end of shutdown procedure

halt -p

# hdparm *

DANGEROUS! Tweak hard disk settings

hdparm /dev/hda

$ head

Print topmost lines of text files (default is first 10 lines)

-n: Specify number of lines (such as -n 5)

head myfile.txt

$ help

Display list of common BASH commands

help

$ history

Display history file (a list of recently used commands)

history

$ host

Query DNS server based on specified domain name or IP address

-d: Verbose; return more information

-r: Force name server to return its cached information rather than query other authoritative servers

host 65.19.150.100

$ hostname

Display localhost-style name of computer

hostname

$ id

Display username and group info of specified user (or current user if none specified)

id myuser

Command

Notes/Command Options

Example of Typical Use

# ifconfig *

Display or configure settings of a network interface (assign an IP address, subnet mask, and activate/deactivate it) down: Disable interface (used at end of command chain)

netmask: Specify a subnet mask

up: Enable interface (used at end of command chain)

ifconfig eth0 192.168.0.10 netmask 255.255.0.0 up

$ info *

Display info page for specified command

info command

# init

Change current run level

init 3

$ ispell *

Program that spellchecks specified file

-b: Back up original file (provided original file is altered and subsequently saved)

ispell myfile.txt

$ jobs

Display list of jobs running in background

jobs

# kernelversion

Display kernel version number

kernelversion

$ kill

Kill specified process

kill 1433

$ killall

Kill process(es) that have specified name(s)

-i: Confirm before killing process

-v: Verbose; report if and when successful

killall processnumber

$ last

Display details of recent logins, reboots, and shutdowns

last

$ ldd

Display system files (libraries) required by specified program

ldd /usr/bin/program

$ less

Interactively scroll through a text file

-q: Quiet; disable beeps when end of file is reached or other error encountered

-i: Ignore case; make all searches case-insensitive unless uppercase letters are used

less myfile.txt

$ ln

Create links to specified files, such as symbolic links

-s: Create symbolic link (default is hard link)

ln -s myfile1 mfile2

$ look

Spell-check specified word (or part of word)

-f: Ignore uppercase and lowercase

look word

$ lpr

Print file (send it to the printer spool/queue)

-V: Verbose; print information about progress of print job

lpr myfile.txt

$ lpstat

Display print queue

lpstat

$ ls

List directory

-a: List all files, including hidden files

-d: List only directory names rather than their contents

-h: Human readable; print figures in KB, MB, GB, and TB

-l: Long list; include all details, such as file permissions

-m: Show as comma-separated list

ls -h mydirectory

# lsmod

Display currently loaded kernel modules

lsmod

$ lsof

Display any files currently in use

-u: Limit results to files used by specified user

lsof -u username

$ mail *

Program that can send and also receive mail

-s: Specify subject prior to creating new mail

mail user@mydomain.com

$ man

Display specified command’s manual

man command

$ mc *

Semigraphical file-browsing program based on Norton Commander

mc

$ md5sum

Display MD5 checksum (normally used to confirm a file’s integrity after download)

md5sum myfile

# mkfs *

DANGEROUS! Create specified file system on specified device (such as a floppy disk)

-t: Specify type of file system

mkfs -t vfat /dev/fd0

$ mkisofs *

Create ISO image file from specified directory (usually for burning to disc with cdrecord)

-o: Options; this must appear after command to indicate that command options follow

-apple: Use Mac OS extensions to make ensuing disc readable on Apple computers

-f: Follow symbolic links and source actual files

-J: Use Joliet extensions (make ISO compatible with Windows)

-R: Use Rock Ridge extensions (preferred Linux CD-ROM file system)

-v: Verbose; display more information (-vv for even more info)

mkisofs -o isoimage.iso -R -J -v mydirectory

# modinfo

Display information about kernel module

modinfo modulename

# modprobe

Insert specified module into the kernel, as well as any others it relies on

-k: Set module’s autoclean flag so it will be removed from memory after inactivity

-r: Remove specified module as well as any it relies on to operate

modprobe modulename

$ more

Interactively scroll through text file (similar to less)

more myfile.txt

# mount *

Mount specified file system at specified location

-o: Specify command options, such as rw to allow read/write access; various types of file systems have unique commands

mount /dev/hda4 /mnt

$ mv

Move (or rename) specified files and/or directories

-b: Back up files before moving

-v: Display details of actions carried out

mv myfile mydirectory/

$ netstat *

Show current network connections

netstat -a

$ nice

Run specified command with specified priority

-n: Specify priority, ranging from the highest priority of -20, to 19, which is the lowest priority

nice -n 19

$ nohup

Run specified command and continue to run it, even if user logs out

nohup command

$ passwd

Change user’s password

passwd

$ ping

Check network connectivity between local machine and specified address

-w: Exit after specified number of seconds (such as -w 5)

ping mydomain.com

$ printenv

Display all environment variables for current user

printenv

$ ps *

Display currently running processes

a: List all processes (note that command options don’t require preceding dash)

f: Display ownership of processes using tree-style graphics

u: Limit results to processes running for and started by current user

x: Include processes in results not started by user but running with the user ID

ps aux

$ pwd

Display current directory

pwd

# reboot

Reboot computer

reboot

$ renice

Change a process’ priority while it’s running (see nice)

renice 19 10704

$ rm

Delete single or multiple files and/or directories

-r: Recursive; delete specified directories and any subdirectories

-f: Force; don’t prompt for confirmation before deleting (use with care!)

rm -rf mydirectory

# rmmod

Delete module from kernel

rmmod modulename

# route *

Add and create (or view) entries in routing table (see ifconfig)

route add default gw 192.168.1.1

# rpm *

Red Hat Package Manager; installs specified RPM package(s)

-e: Uninstall specified package

-h: Graphically indicate progress when installing/upgrading

-i: Install package

--nodeps: Ignore dependency errors (use with care!)

-qa: Display listing of installed packages

-qp: Display details of specified package

-U: Upgrade package (will install if package not already installed)

-v: Verbose; display detailed output

rpm -Uvh packagename

# runlevel

Display current run level

runlevel

# sax2 *

Configure X (keyboard, mouse, and display); note that this is a SUSE Linux-specific GUI tool

-V: Specify initial resolution and refresh rate (such as -V 800x600@60)

sax2

$ screen *

Program that runs pseudo shell that is kept alive regardless of current user login

-ls: Display list of currently running screen sessions

-R: Reattach to already running screen session or start new one if none available

screen

$ sftp *

Secure Shell FTP; like FTP but running over an ssh connection (see below)

sftp username@192.168.1.14

$ shred

Overwrite data in a file with gibberish, thereby making it irrecoverable

-u: Delete file in addition to overwriting

-v:Verbose; show details of procedure

-f: Force permissions to allow writing if necessary

shred -fv myfile

$ sleep

Pause input for the specified period of time (where s=seconds, m=minutes, h=hours, d=days)

sleep 10m

$ smbclient *

FTP-style program with which you can log in to a SMB (Windows)-based file share

smbclient //192.168.1.1/

$ sort

Sort entries in the specified text file (default is ASCII sort)

sort myfile.txt -o sorted.txt

$ ssh *

Log in to remote computer using secure shell

ssh username@192.168.1.15

$ startx

Start GUI session when in run level 3 (at shell login)

startx

$ su

Temporarily log in as specified user; log in as root if no user specified

-: Adopt user’s environment variables, such as $PATH

su -

$ sudo

Execute specified command with root privileges (provided the facility has been set up)

sudo command

# SuSEconfig

Update system according to settings in SuSE Linux-specific config files

SuSEconfig

$ tac

Display specified text file but in reverse (from last to first line)

tac myfile.txt

$ tail

Display final lines of specified text file

-n: Specify number of lines to display (such as -n4)

tail myfile.txt

$ tar *

Combine specified files and/or directories into one larger file, or extract from such a file

-c: Create new archive

-j: Use bzip2 in order to compress (or decompress) files

-f: Specifies filename (must be last in chain of command options)

-r: Add files to existing archive

-x: Extract files from existing archive

-z: Use gzip to compress (or decompress) files

tar -zcf myfile.tar.gz mydirectory

$ tee

Display piped output and also save it to specified file

ls -lh| tee listing.txt

$ top *

Program that both displays and lets the user manipulate processes

top

$ touch

Give specified file current time and date stamp; if it doesn’t exist, create a zero-byte file with that name

touch myfile

# traceroute

Discover and display network path to another host

traceroute 192.168.1.20

$ umask

Set default permissions assigned to newly created files

umask u=rwx,g=r,o=

# umount

Unmount a file system

umount /media/cdrom

# useradd

Add new user

-m: Create home directory for user

useradd -m username

# userdel

Delete all mention of user in system configuration files (effectively deleting the user, although files owned by him/her might remain)

-r: Remove user’s home directory

userdel -r username

$ unalias

Remove specified alias

-a: Remove all aliases (use with care!)

unalias command

$ uname

Display technical information about current system

-a: Display all basic information

uname -a

$ unzip

Unzip a Windows-compatible Zip file

-l: Display archive content but don’t actually unzip

unzip myfile.zip

$ uptime

Display uptime for system, as well as CPU load average and logged-in users

uptime

$ vi *

Text editor program

vi

$ wc

Count the number of words in a file

wc myfile.txt

$ whatis

Display one-line summary of specified command

whatis command

$ whereis

Display information on where a binary command is located, along with its source code and man page (if applicable)

-b: Return information only about binary programs

whereis -b command

# xf86config *

Command-line program that configures X system, including mouse, keyboard, and display

xf86config

$ xhost

Configure which users/systems can run programs on the X server

+: When followed by a username and/or system name, gives the user/system permission to run programs on the X server; when used on its own, lets any user/system use the X server

-: Opposite of above

xhost +

$ xinit

Start elementary GUI session (when in run level 3)

xinit

# yast2 *

Start the YaST2 program

-i: Install specified RPM

yast2

$ zip

Create Windows-compatible compressed Zip files

-r: Recursive; includes all subdirectories and files therein

-u: Updates Zip with specified file

-P: Encrypts Zip with specified password

-v: Verbose; display more information

-#: Set compression level (from 0, which is no compression, to 9, which is highest)

zip -r myfile.zip mydirectory

$ zipgrep

Searches inside Zip files for specified text string

zipgrep "search phrase" myfile.zip




Beginning SUSE Linux from Novice to Professional
Beginning SUSE Linux: From Novice to Professional
ISBN: 1590594584
EAN: 2147483647
Year: 2005
Pages: 293
Authors: Keir Thomas

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net