Commands Flashcards
pwd
print the working directory
echo STRING
display text from stdin
time COMMAND
times how long COMMAND takes to execute
Three times are displayed: totalexecution time (aka real time); user CPU time; and system CPU time
set
displays a wide variety of options relating to bash shell operation
These options are formatted much like environment variables; but they aren’t the same things. You can pass various options to set to have it affect a wide range of shell operations.
exit
terminates any shell
Login shells are shell programs that are launched automatically when you initiate a text-mode login as opposed to those that run in xterm windows or other terminal emulators
logout
terminates only login shells
Login shells are shell programs that are launched automatically when you initiate a text-mode login as opposed to those that run in xterm windows or other terminal emulators
type COMMAND
tells you how a command you enter will be interpreted—as a built-in command; an external command; an alias; and so on
history
displays all of the commands in the history
typically the latest 500 commands
!!
display and execute the last command in your shell history
!NUMBER
execute command NUMBER from the history
$PATH
a directory list to search when you’re entering command or program names
env
display environment variables
unset VARNAME
unset an environment variable
$PS1
the shell prompt
man COMMAND
display the manual for COMMAND
info COMMAND
hypertext formatted manual
help COMMAND
a built in manual for built in commands
>
Creates a new file containing standard output. If the specified file exists; it’s overwritten. No file descriptor necessary.
> >
Appends standard output to the existing file. If the specified file doesn’t exist; it’s created. No file descriptor necessary.
2>
Creates a new file containing standard error. If the specified file exists; it’s overwritten. File descriptor necessary.
2»
Appends standard error to the existing file. If the specified file doesn’t exist; it’s created. File descriptor necessary.
&>
Creates a new file containing both standard output and standard error. If the specified file exists; it’s overwritten. No file descriptors necessary.
Sends the contents of the specified file to be used as standard input. No file descriptor necessary.
<
Accepts text on the following lines as standard input. No file descriptor necessary.
<>
Causes the specified file to be used for both standard input and standard output. No file descriptor necessary.
COMMAND1 | COMMAND2
link stdout from COMMAND1 to stdin of COMMAND2
tee
display stdin on stdout and save it to the specified files
xargs [ options ] [ command [ initial-arguments ]]
run command once for every word passed to it on standard input
find / -user Christine | xargs -d “” \ n”” rm
COMMAND
a separate command whose results are substituted on the command line
rm ` find . / -user Christine `
$(COMMAND)
a separate command whose results are substituted on the command line
rm $(find ./ -user Christine)
cat
concatenate files and print on the standard output
tac
concatenate files and print on the standard output in reverse line order
join
For each pair of input lines with identical join fields; write a line to standard output. The default join field is the first; delimited by blanks.
Fields are typically space-separated entries on a line
paste
Write lines consisting of the sequentially corresponding lines from each FILE; separated by TABs; to standard output
expand
Convert tabs in each FILE to spaces; writing to standard output.
assumes a tab stop every eight characters
od
dump files in octal and other formats
sort
sort lines of text files
split
Output pieces of FILE to PREFIXaa; PREFIXab; …; default size is 1000 lines; and default PREFIX is ‘x’.
split -l 2 listing1.1.txt numbers
tr [ options ] SET1 [ SET2 ]
Translate; squeeze; and/or delete characters from standard input; writing to standard output tr BCJ bc < listing1.1.txt B is replaced with b C is replaced with c J is replaced with c
unexpand
unexpand - convert spaces to tabs
defaults to 8
uniq
report or omit repeated lines
fmt
Reformat each paragraph in the FILE(s); writing to standard output.
(default of 75 columns)
nl
number lines of files (non empty)
the similar to ““cat -b”” by default
pr
Paginate or columnate FILE(s) for printing
defaults to 80 columns
head
Print the first 10 lines of each FILE to standard output. With more than one FILE; precede each with a header giving the file name.
tail
Print the last 10 lines of each FILE to standard output. With more than one FILE; precede each with a header giving the file name.
less
Less is a program similar to more (1); but it has many more features.
cut
Print selected parts of lines from each FILE to standard output.
wc
Print newline; word; and byte counts for each FILE; and a total line if more than one FILE is specified. A word is a non-zero-length sequence of characters delimited by white space.
grep
searches for PATTERN in each FILE
sed
stream editor for filtering and transforming text
sed [ options ] -f script-file [ input-file ]
sed [ options ] script-text [ input-file ]
rpm
RPM Package Manager
rpm2cpio
converts the .rpm file specified as a single argument to a cpio archive on standard out. If a ‘-‘ argument is given; an rpm stream is read from standard in.
cpio
copy files to and from archives
find ./my-work | cpio -o > /media/usb/my-work.cpio
cpio -i < /media/usb/my-work.cpio
yum
a repository based rpm manage
used by: Red Hat; CentOS; Fedora; and some other RPM-based distributions
not usd by: SUSE and Mandriva;
yumdownloader
yumdownloader is a program for downloading RPMs from Yum repositories
kyum
a gui frontend for yum
also yumex
yumex
a gui frontend for yum
also kyum
dpkg
debian’s equivelant of rpm
dselect
a high-level interactive package browser. Using it; you can select packages to install on your system from the APT archives defined in /etc/apt/sources.list ; review the packages that are already installed on your system; uninstall packages; and upgrade packages.
apt-get
debian’s equivelant of yum
apt-cache
apt-cache performs a variety of operations on APT’s package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata. The metadata is acquired and updated via the ‘update’ command of e.g. apt-get; so that it can be outdated if the last update is too long ago; but in exchange apt-cache works independently of the availability of the configured sources (e.g. offline).
aptitude
a text based debian package manager with an optional interactive mode that is similar to dselect
synaptic
a X gui program similar to dselect or aptitude
dpkg-reconfigure
reconfigures packages after they have already been installed. Pass it the names of a package or packages to reconfigure. It will ask configuration questions; much like when the package was first installed.
alien
converts between Red Hat rpm; Debian deb; Stampede slp; Slackware tgz; Solaris pkg; and tarballs
requires that you have appropriate package manager software installed—for instance; both RPM and Debian—to convert between these formats
When converting from a tarball; alien copies the files directly as they had been in the tarball; so alien works only if the original tarball has files that should be installed off the root ( / ) directory of the system
$LD_LIBRARY_PATH
This environment variable specifies additional directories the system is to search for libraries
Does not require ldconfig for changes to take effect
ldd
prints the shared objects (shared libraries) required by each program or shared object specified on the command line.
ldconfig
usually called without any options
updates caches and links used by the system for locating libraries—that is; it reads /etc/ld.so.conf and implements any changes in that file or in the directories to which it refers
uname
Print certain system information. With no OPTION; same as -s
node(host) name; kernel name; kernel version; kernel release; machine; processor; hardware platform; os name
ps
ps displays information about a selection of the active processes.
top
provides a dynamic real-time view of a running system
free
displays the total amount of free and used physical and swap memory in the system; as well as the buffers and caches used by the kernel. The information is gathered by parsing /proc/meminfo. T
uptime
gives a one line display of the following information. The current time; how long the system has been running; how many users are currently logged on; and the system load averages for the past 1; 5; and 15 minutes
the same information displayed in the header of w
jobs
displays minimal information about the processes associated with the current session
pgrep
looks through the currently running processes and lists the process IDs which match the selection criteria to stdout.
pgrep -u root cron
bg
move the specified job to the background, or start the first background process if it is stopped
fg
bring the specified job to the foreground
nice
Run COMMAND with an adjusted niceness (defaults to 10); which affects process scheduling. With no COMMAND; print the current niceness.
renice
renice alters the scheduling priority of one or more running processes.
renice 7 16580 -u pdavison tbaker
kill
send a signal to a process
The default signal for kill is TERM.
used to stop programs
nohup
Run COMMAND; ignoring hangup signals
killall
kill processes by name
killall vi
pkill
allows you to kill one or more processes based on usernames; user IDs; group IDs; and other features as well as using a matching regular expression
setpci
a utility for querying and configuring PCI devices.
lspci
utility for displaying information about PCI buses in the system and devices connected to them
lsmod
a trivial program which nicely formats the contents of the /proc/modules (kernel modules)
insmod
a trivial program to insert a module into the kernel. Most users will want to use modprobe(8) instead; which is more clever and can handle module dependencies. e.g. insmod /lib/modules/3.16.6/kernel/drivers/bluetooth/bluetooth.ko
modprobe
intelligently adds or removes a module from the Linux kernel e.g. modprobe bluetooth
rmmod
a trivial program to remove a module (when module unloading support is provided) from the kernel. Most users will want to use modprobe(8) with the -r option instead.
lsusb
a utility for displaying information about USB buses in the system and the devices connected to them
pvcreate
initialize a disk or partition for use by LVM
vgcreate
create a volume group (for LVM)
lvcreate
create a logical volume in an existing volume group (for LVM)
lvscan
scan (all disks) for Logical Volumes (for LVM)
fdisk
a dialog-driven program for creation and manipulation of partition tables. It understands GPT; MBR; Sun; SGI and BSD partition tables.
the book says this tool can’t do GPT even though it can
e.g. fdisk /dev/hda
gdisk
GPT fdisk (aka gdisk) is a text-mode menu-driven program for creation and manipulation of partition tables
mkfs
build a Linux filesystem
deprecated in favour of filesystem specific mkfs. utils
mkfs -t ext3 /dev/sda6
mkswap
sets up a Linux swap area on a device or in a file
mkswap /dev/sda7
swapon
used to specify devices on which paging and swapping are to take place
/dev/sda7
dumpe2fs
dump ext2/ext3/ext4 filesystem information
prints the super block and blocks group information for the filesystem present on device
xfs_info
like dumpe2fs but for xfs; displays filesystem info
xfs_metadump
copies the filesystem’s metadata (filenames; file sizes; and so on) to a file
tune2fs
enables you to change many of the filesystem parameters that are reported by dumpe2fs
adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems
fsck
check and repair a Linux filesystem
xfs_admin
xfs equivelant to tune2fs
xfs_admin -L av_data /dev/sda7
blkid
display the label and UUID of any partition’s filesystem
debugfs
provides the abilities of dumpe2fs ; tune2fs ; and many of Linux’s normal file-manipulation tools all rolled into one
an interactive file system debugger. It can be used to examine and change the state of an ext2; ext3; or ext4 file system
e.g. debugfs /dev/sda11
xfs_db
xfs equivelant to debugfs; only for experts
df
report file system disk space usage
du
estimate file space usage
mount
mount a filesystem
mount /dev/sdb7 /mnt/shared
umount
unmount file systems
ls
list directory contents
cp
make a copy
mv
move (rename) files
rm
remove files or directories
touch
Update the access and modification times of each FILE to the current time
tar
an archiving utility
gzip
compress or expand files; oldest least compression
bzip2
a block-sorting file compressor; improved over gzip
xz
Compress or decompress .xz and .lzma files newest and best compression compared to gzip and bzip2
dd
Copy a file; converting and formatting according to the operands.
very low level
ln
make links between files
ln [options] source link
you can’t make hard links to directories
mkdir
make directories