Cut & Paste More Linux Commands: Command Description
Cut & Paste More Linux Commands: Command Description
Examples marked with • are valid/safe to paste without modification into a terminal, so
you may want to keep a terminal window open while reading this so you can cut & paste.
All these commands have been tested both on Fedora and Ubuntu.
See also more linux commands.
Command Description
Show commands pertinent
• apropos whatis to string. See
also threadsafe
make a pdf of a manual
• man -t ascii | ps2pdf - > ascii.pdf
page
Show full path name of
which command
command
See how long a command
time command
takes
Start stopwatch. Ctrl-d to
• time cat
stop. See also sw
dir navigation
• cd - Go to previous directory
• cd Go to $HOME directory
Go to dir, execute
(cd dir && command) command and return to
current dir
Put current dir on stack so
• pushd .
you can popd back to it
file searching
• alias l='ls -l --color=auto' quick dir listing
List files by date. See
• ls -lrt also newest and find_mm_
yyyy
Print in 9 columns to width
• ls /usr/bin | pr -T9 -W$COLUMNS
of terminal
Search 'expr' in this dir and
find -name '*.[ch]' | xargs grep -E 'expr'
below. See also findrepo
Search all regular files for
find -type f -print0 | xargs -r0 grep -F 'example' 'example' in this dir and
below
Search all regular files for
find -maxdepth 1 -type f | xargs grep -F 'example'
'example' in this dir
Process each item with
find -maxdepth 1 -type d | while read dir; do echo $dir; echo
multiple commands (in
cmd2; done
while loop)
Find files not readable by
• find -type f ! -perm -444
all (useful for web site)
• find -type d ! -perm -111 Find dirs not accessible by
all (useful for web site)
Search cached index for
• locate -r 'file[^/]*\.txt' names. This re is like glob
*file*.txt
Quickly search (sorted)
• look reference
dictionary for prefix
Highlight occurances of
• grep --color reference /usr/share/dict/words regular expression in
dictionary
archives and compression
gpg -c file Encrypt file
gpg file.gpg Decrypt file
Make compressed archive
tar -c dir/ | bzip2 > dir.tar.bz2
of dir/
Extract archive (use gzip
bzip2 -dc dir.tar.bz2 | tar -x instead of bzip2 for tar.gz
files)
Make encrypted archive of
tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'
dir/ on remote machine
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > Make archive of subset of
dir_txt.tar.bz2 dir/ and below
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ Make copy of subset of dir/
--parents and below
Copy (with permissions)
( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p )
copy/ dir to /where/to/ dir
Copy (with permissions)
( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p ) contents of copy/ dir to
/where/to/
Copy (with permissions)
( tar -c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ &&
copy/ dir to
tar -x -p'
remote:/where/to/ dir
Backup harddisk to remote
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'
machine
rsync (Network efficient file copier: Use the --dry-run option for testing)
Only get diffs. Do multiple
rsync -P rsync://rsync.server.com/path/to/file file times for troublesome
downloads
Locally copy with rate
rsync --bwlimit=1000 fromfile tofile
limit. It's like nice for I/O
Mirror web site (using
rsync -az -e ssh --delete ~/public_html/
compression and
remote.com:'~/public_html'
encryption)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e Synchronize current
ssh . remote:/dir/ directory with remote one
ssh (Secure SHell)
Run command on $HOST
ssh $USER@$HOST command as $USER (default
command=shell)
Run GUI command on
• ssh -f -Y $USER@$HOSTNAME xeyes
$HOSTNAME as $USER
Copy with permissions to
scp -p -r $USER@$HOST: file dir/ $USER's home directory
on $HOST
Use faster crypto for local
scp -c arcfour $USER@$LANHOST: bigfile LAN. This might saturate
GigE
Forward connections to
ssh -g -L 8080:localhost:80 root@$HOST $HOSTNAME:8080 out to
$HOST:80
Forward connections from
ssh -R 1434:imap:143 root@$HOST $HOST:1434 in to
imap:143
Install public key for
ssh-copy-id $USER@$HOST $USER@$HOST for
password-less log in
wget (multi purpose download tool)
Store local browsable
(cd dir/ && wget -nd -pHEKk
• version of a page to the
http://www.pixelbeat.org/cmdline.html)
current dir
Continue downloading a
wget -c http://www.example.com/large.file
partially downloaded file
Download a set of files to
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/
the current directory
FTP supports globbing
wget ftp://remote/file[1-9].iso/
directly
wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a
• Process output directly
href' | head
Download url at 1AM to
echo 'wget url' | at 01:00
current dir
Do a low priority download
wget --limit-rate=20k url (limit to 20KB/s in this
case)
wget -nv --spider --force-html -i bookmarks.html Check links in a file
Efficiently update a local
wget --mirror http://www.example.com/ copy of a site (handy from
cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
Show status of ethernet
ethtool eth0
interface eth0
Manually set ethernet
ethtool --change eth0 autoneg off speed 100 duplex full
interface speed
Show status of wireless
iwconfig eth1
interface eth1
Manually set wireless
iwconfig eth1 rate 1Mb/s fixed
interface speed
List wireless networks in
• iwlist scan
range
• ip link show List network interfaces
Rename interface eth0 to
ip link set dev eth0 name wan
wan
Bring interface eth0 up (or
ip link set dev eth0 up
down)
• ip addr show List addresses for interfaces
Add (or del) ip and mask
ip addr add 1.2.3.4/24 brd + dev eth0
(255.255.255.0)
• ip route show List routing table
Set default gateway to
ip route add default via 1.2.3.254
1.2.3.254
Lookup DNS ip address for
• host pixelbeat.org
name or vice versa
Lookup local ip address
• hostname -i (equivalent to host
`hostname`)
Lookup whois info for
• whois pixelbeat.org
hostname or ip address
List internet services on a
• netstat -tupl
system
List active connections
• netstat -tup
to/from system
windows networking (Note samba is the package that provides all this windows specific
networking support)
Find windows machines.
• smbtree
See also findsmb
Find the windows (netbios)
nmblookup -A 1.2.3.4 name associated with ip
address
List shares on windows
smbclient -L windows_box
machine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share
Mount a windows share
/mnt/share
Send popup to windows
echo 'message' | smbclient -M windows_box machine (off by default in
XP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing
with the -i option)
sed 's/string1/string2/g' Replace string1 with
string2
Modify anystring1 to
sed 's/\(.*\)1/\12/g'
anystring2
Remove comments and
sed '/ *#/d; /^ *$/d'
blank lines
Concatenate lines with
sed ':a; /\\$/N; s/\\\n//; ta'
trailing \
Remove trailing spaces
sed 's/[ \t]*$//'
from lines
Escape shell
sed 's/\([`"$\]\)/\\\1/g' metacharacters active
within double quotes
• seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" Right align numbers
sed -n '1000{p;q}' Print 1000th line
sed -n '10,20p;20q' Print lines 10 to 20
Extract title from HTML
sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q'
web page
sed -i 42d ~/.ssh/known_hosts Delete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses
• echo 'Test' | tr '[:lower:]' '[:upper:]' Case conversion
Filter non printable
• tr -dc '[:print:]' < /dev/urandom
characters
cut fields separated by
• tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4
blanks
• history | wc -l Count lines
set operations (Note you can export LANG=C for speed. Also these assume no duplicate
lines within a file)
sort file1 file2 | uniq Union of unsorted files
Intersection of unsorted
sort file1 file2 | uniq -d
files
sort file1 file1 file2 | uniq -u Difference of unsorted files
Symmetric Difference of
sort file1 file2 | uniq -u
unsorted files
join -t'\0' -a1 -a2 file1 file2 Union of sorted files
join -t'\0' file1 file2 Intersection of sorted files
join -t'\0' -v2 file1 file2 Difference of sorted files
Symmetric Difference of
join -t'\0' -v1 -v2 file1 file2
sorted files
math
Quick math (Calculate φ).
• echo '(1 + sqrt(5))/2' | bc -l
See also bc
• seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -l Calculate π the unix way
• echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bc More complex (int) e.g.
This shows max FastE
packet rate
Python handles scientific
• echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | python
notation
echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | Plot FastE packet rate vs
•
gnuplot -persist packet size
Base conversion (decimal
• echo 'obase=16; ibase=10; 64206' | bc
to hexadecimal)
Base conversion (hex to
• echo $((0x2dec)) dec) ((shell arithmetic
expansion))
Unit conversion (metric to
• units -t '100m/9.58s' 'miles/hour'
imperial)
Unit conversion
• units -t '500GB' 'GiB'
(SI to IEC prefixes)
• units -t '1 googol' Definition lookup
Add a column of numbers.
• seq 100 | (tr '\n' +; echo 0) | bc
See also add and funcpy
calendar
• cal -3 Display a calendar
Display a calendar for a
• cal 9 1752
particular month year
What date is it this friday.
• date -d fri
See also day
exit a script unless it's the
• [ $(date -d "tomorrow" +%d) = "01" ] || exit
last day of the month
What day does xmas fall
• date --date='25 Dec' +%A
on, this year
Convert seconds since the
• date --date='@2147483647' epoch (1970-01-01 UTC)
to date
What time is it on west
• TZ='America/Los_Angeles' date coast of US (use tzselect to
find TZ)
What's the local time for
• date --date='TZ="America/Los_Angeles" 09:00 next Fri' 9AM next Friday on west
coast US
locales
Print number with
• printf "%'d\n" 1234 thousands grouping
appropriate to locale
Use locale thousands
• BLOCK_SIZE=\'1 ls -l
grouping in ls. See also l
Extract info from locale
• echo "I live in `locale territory`"
database
• LANG=en_IE.utf8 locale int_prefix Lookup locale info for
specific country. See
also ccodes
List fields available in
• locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | less
locale database
recode (Obsoletes iconv, dos2unix, unix2dos)
Show available conversions
• recode -l | less
(aliases on each line)
Windows "ansi" to local
recode windows-1252.. file_to_change.txt charset (auto does CRLF
conversion)
Windows utf8 to local
recode utf-8/CRLF.. file_to_change.txt
charset
Latin9 (western europe) to
recode iso-8859-15..utf8 file_to_change.txt
utf8
recode ../b64 < file.txt > file.b64 Base64 encode
recode /qp.. < file.qp > file.txt Quoted printable decode
recode ..HTML < file.txt > file.html Text to HTML
• recode -lf windows-1252 | grep euro Lookup table of characters
Show what a code
• echo -n 0x80 | recode latin-9/x1..dump represents in latin-9
charmap
• echo -n 0x20AC | recode ucs-2/x2..latin-9/x Show latin-9 encoding
• echo -n 0x20AC | recode ucs-2/x2..utf-8/x Show utf-8 encoding
CDs
gzip < /dev/cdrom > cdrom.iso.gz Save copy of data cdrom
Create cdrom image from
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gz
contents of dir
Mount the cdrom image
mount -o loop cdrom.iso /mnt/dir
at /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fast Clear a CDRW
Burn cdrom image (use
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom - dev=ATAPI -scanbus to
confirm dev)
Rip audio tracks from CD
cdparanoia -B
to wav files in current dir
Make audio CD from all
cdrecord -v dev=/dev/cdrom -audio -pad *.wav wavs in current dir (see
also cdrdao)
Make ogg file from wav
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'
file
disk space (See also FSlint)
Show files by size, biggest
• ls -lSr
last
• du -s * | sort -k1,1rn | head Show top disk users in
current dir. See also dutop
Sort paths by easy to
• du -hs /home/* | sort -k1,1h
interpret disk usage
Show free space on
• df -h
mounted filesystems
Show free inodes on
• df -i
mounted filesystems
Show disks partitions sizes
• fdisk -l
and types (run as root)
List all packages by
• rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1n installed size (Bytes) on
rpm distros
List all packages by
dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort
• installed size (KBytes) on
-k1,1n
deb distros
Create a large test file
• dd bs=1 seek=2TB if=/dev/null of=ext3.test (taking no space). See
also truncate
truncate data of file or
• > file
create an empty file
monitoring/debugging
Monitor messages in a log
• tail -f /var/log/messages
file
Summarise/profile system
• strace -c ls >/dev/null
calls made by command
List system calls made by
• strace -f -e open ls >/dev/null
command
Monitor what's written to
• strace -f -e trace=write -e write=1,2 ls >/dev/null
stdout and stderr
List library calls made by
• ltrace -f -e getenv ls >/dev/null
command
List paths that process id
• lsof -p $$
has open
List processes that have
• lsof ~
specified path open
Show network traffic
• tcpdump not port 22 except ssh. See
also tcpdump_not_me
List processes in a
• ps -e -o pid,args --forest
hierarchy
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 List processes by % cpu
•
/d' usage
List processes by mem
• ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS (KB) usage. See
also ps_mem.py
List all threads for a
• ps -C firefox-bin -L -o pid,tid,pcpu,state
particular process
List elapsed wall time for
• ps -p 1,$$ -o etime=
particular process IDs
• last reboot Show system reboot history
Show amount of
• free -m (remaining) RAM (-m
displays in MB)
Watch changeable data
• watch -n.1 'cat /proc/interrupts'
continuously
Monitor udev events to
• udevadm monitor
help configure rules
system information (see also sysinfo) ('#' means root access is required)
Show kernel version and
• uname -a
system architecture
Show name and version of
• head -n1 /etc/issue
distribution
Show all partitions
• cat /proc/partitions
registered on the system
Show RAM total seen by
• grep MemTotal /proc/meminfo
the system
• grep "model name" /proc/cpuinfo Show CPU(s) info
• lspci -tv Show PCI info
• lsusb -tv Show USB info
List mounted filesystems
• mount | column -t on the system (and align
output)
Show state of cells in
• grep -F capacity: /proc/acpi/battery/BAT0/info
laptop battery
Display SMBIOS/DMI
# dmidecode -q | less
information
How long has this disk
# smartctl -A /dev/sda | grep Power_On_Hours (system) been powered on
in total
# hdparm -i /dev/sda Show info about disk sda
Do a read speed test on
# hdparm -tT /dev/sda
disk sda
Test for unreadable blocks
# badblocks -s /dev/sda
on disk sda
interactive (see also linux keyboard shortcuts)
Line editor used by bash,
• readline
python, bc, gnuplot, ...
Virtual terminals with
• screen
detach capability, ...
• mc Powerful file manager that
can browse rpm, tar, ftp,
ssh, ...
Interactive/scriptable
• gnuplot
graphing
• links Web browser
open a file or url with the
• xdg-open . registered desktop
application
Command Description
List the contents of flag
• grep . /proc/sys/net/ipv4/*
files
• set | grep $USER Search current environment
Display
• tr '\0' '\n' < /proc/$$/environ the startup environment for
any process
Display the $PATH one per
• echo $PATH | tr : '\n'
line
Check for the existence of
• kill -0 $$ && echo process exists and can accept signals
a process (pid)
Search paths and data with
find /etc -readable | xargs less -K -p'*ntp' -j $((${LINES:-
• full context. Use n to
25}/2))
iterate
Low impact admin
apt-get install "package" -o Acquire::http::Dl-Limit=42 \ Rate limit apt-get to
#
-o Acquire::Queue-mode=access 42KB/s
Download url at 1AM to
echo 'wget url' | at 01:00
current dir
Restart apache if config is
# apache2ctl configtest && apache2ctl graceful
OK
Run a low priority
• nice openssl speed sha1 command (openssl
benchmark)
Make shell (script) low
• renice 19 -p $$; ionice -c3 -p $$ priority. Use for non
interactive tasks
Interactive monitoring
• watch -t -n1 uptime Clock with system load
Better top (scrollable, tree
• htop -d 5 view, lsof/strace
integration, ...)
• iotop What's doing I/O
# watch -d -n30 "nice ps_mem.py | tail -n $((${LINES:-12}-2))" What's using RAM
What's using the network.
# iftop
See also iptraf
# mtr www.pixelbeat.org ping and traceroute
combined
Useful utilities
Progress Viewer for data
• pv < /dev/zero > /dev/null copying from files and
pipes
wkhtml2pdf http://.../linux_commands.html linux_commands.p
• Make a pdf of a web page
df
run a command with
• timeout 1 sleep 3 bounded time. See
also timeout
Networking
Serve current directory tree
• python -m SimpleHTTPServer at http://$HOSTNAME:80
00/
openssl s_client -connect www.google.com:443 </dev/null
Display the date range for a
• 2>&0 |
site's certs
openssl x509 -dates -noout
Display the server headers
• curl -I www.pixelbeat.org
for a web site
# lsof -i tcp:80 What's using port 80
Display a list of apache
# httpd -S
virtual hosts
Edit remote file using local
• vim scp://user@remote//path/to/file vim. Good for high latency
links
Import a gpg key from the
• curl -s http://www.pixelbeat.org/pixelbeat.asc | gpg --import
web
Add 20ms latency to
• tc qdisc add dev lo root handle 1:0 netem delay 20msec loopback device (for
testing)
Remove latency added
• tc qdisc del dev lo root
above
Notification
echo "DISPLAY=$DISPLAY xmessage cooker" | at "NOW
• Popup reminder
+30min"
Display a gnome popup
• notify-send "subject" "message"
notification
echo "mail -s 'go home' [email protected] < /dev/null" | at
Email reminder
17:30
uuencode file name | mail -s subject [email protected] Send a file via email
ansi2html.sh | mail -a "Content-Type: text/html" Send/Generate HTML
[email protected] email
Better default settings (useful in your .bashrc)
Display file additions more
# tail -s.1 -f /var/log/messages
responsively
Display as many lines as
• seq 100 | tail -n $((${LINES:-12}-2))
possible without scrolling
Capture full network
# tcpdump -s0
packets
Useful functions/aliases (useful in your .bashrc)
• md () { mkdir -p "$1" && cd "$1"; } Change to a new directory
Display the meaning of
• strerror() { python -c "import os; print os.strerror($1)"; }
an errno
Plot stdin. (e.g: • seq 1000 |
• plot() { { echo 'plot "-"' "$@"; cat; } | gnuplot -persist; }
sed 's/.*/s(&)/' | bc -l | plot)
highlight occurences of
• hili() { e="$1"; shift; grep --col=always -Eih "$e|$" "$@"; } expr. (e.g: • env | hili
$USER)
Hexdump. (usage e.g.: •
• alias hd='od -Ax -tx1z -v'
hd /proc/self/cmdline | less)
Canonicalize path. (usage
• alias realpath='readlink -f'
e.g.: • realpath ~/../$USER)
Multimedia
• DISPLAY=:0.0 import -window root orig.png Take a (remote) screenshot
Shrink to width, computer
• convert -filter catrom -resize '600x>' orig.png 600px_wide.png
gen images or screenshots
Extract audio from flash
mplayer -ao pcm -vo null -vc dummy /tmp/Flash*
video to audiodump.wav
Display info about
ffmpeg -i filename.avi
multimedia file
Capture video of an X
• ffmpeg -f x11grab -s xga -r 25 -i :0 -sameq demo.mpg
display
DVD
Convert video to the
for i in $(seq 9); do ffmpeg -i $i.avi -target pal-dvd $i.mpg;
correct encoding and aspect
done
for DVD
Build DVD file system.
dvdauthor -odvd -t -v "pal,4:3,720xfull" *.mpg;dvdauthor
Use 16:9 for widescreen
-odvd -T
input
Burn DVD file system to
growisofs -dvd-compat -Z /dev/dvd -dvd-video dvd
disc
Unicode
python -c "import unicodedata as u; print
• Lookup a unicode character
u.name(unichr(0x2028))"
Normalize combining
• uconv -f utf8 -t utf8 -x nfc
characters
• printf '\300\200' | iconv -futf8 -tutf8 >/dev/null Validate UTF-8
Highlight non printable
• printf 'ŨTF8\n' | LANG=C grep --color=always '[^ -~]\+'
ASCII chars in UTF-8
• fc-match -s "sans:lang=zh" List font match order for
language and style
Development
Show autodetected gcc
gcc -march=native -E -v -</dev/null 2>&1|sed -n 's/.*-mar/-
• tuning params. See
mar/p'
also gcccpuopt
for i in $(seq 4); do { [ $i = 1 ] && wget http://url.ie/6lko -qO-|| Compile and execute C
•
./a.out; } | tee /dev/tty | gcc -xc - 2>/dev/null; done code from stdin
Show all predefined
• cpp -dM /dev/null
macros
echo "#include <features.h>" | cpp -dN | grep "#define Show all glibc feature
•
__USE_" macros
Debug showing source
gdb -tui code context in separate
windows
Extended Attributes (Note you may need to (re)mount with "acl" or "user_xattr" options)
• getfacl . Show ACLs for file
Allow a specific user to
• setfacl -m u:nobody:r .
read file
Delete a specific user's
• setfacl -x u:nobody .
rights to file
Set umask for a for a
setfacl --default -m group:users:rw- dir/
specific dir
Show capabilities for a
getcap file
program
Allow gtk program raw
setcap cap_net_raw+ep your_gtk_prog
access to network
Show SELinux context for
• stat -c%C .
file
Set SELinux context for
chcon ... file
file (see also restorecon)
Show all extended
• getfattr -m- -d . attributes (includes
selinux,acls,...)
• setfattr -n "user.foo" -v "bar" . Set arbitrary user attributes
BASH specific
Split data to 2 commands
• echo 123 | tee >(tr 1 a) | tr 1 b
(using process substitution)
Compare a local and
meld local_file <(ssh host cat remote_file) remote file (using process
substitution)
Multicore
Restrict a command to
• taskset -c 0 nproc
certain processors
Process files in parallel
• find -type f -print0 | xargs -r0 -P$(nproc) -n10 md5sum
over available processors
Sort separate data files over
sort -m <(sort data1) <(sort data2) >data.sorted
2 processors
Commands marked • are bash built-ins, these are available under all shells.
The tail utility displays the end of a file. The -15 tells tail to display the last fifteen lines
of each specified file.
Who owns the data dictionary?
The SYS user owns the data dictionary. The SYS and SYSTEM users are created when
the database is created.
You routinely compress old log files. You now need to examine a log from two
months ago. In order to view its contents without first having to decompress it,
use the _________ utility.
zcat
The zcat utility allows you to examine the contents of a compressed file much the same
way that cat displays a file.
You suspect that you have two commands with the same name as the command
is not producing the expected results. What command can you use to determine
the location of the command being run?
which
The which command searches your path until it finds a command that matches the
command you are looking for and displays its full path.
You locate a command in the /bin directory but do not know what it does. What
command can you use to determine its purpose.
whatis
The whatis command displays a summary line from the man page for the specified
command.
You wish to create a link to the /data directory in bob's home directory so you
issue the command ln /data /home/bob/datalink but the command fails. What
option should you use in this command line to be successful.
Use the -F option
When you issue the command ls -l, the first character of the resulting display
represents the file's ___________.
type
The first character of the permission block designates the type of file that is being
displayed.
The top utility shows a listing of all running processes that is dynamically updated.
You wish to restore the file memo.ben which was backed up in the tarfile
MyBackup.tar. What command should you type?
tar xf MyBackup.tar memo.ben
This command uses the x switch to extract a file. Here the file memo.ben will be
restored from the tarfile MyBackup.tar.
You need to view the contents of the tarfile called MyBackup.tar. What
command would you use?
tar tf MyBackup.tar
The t switch tells tar to display the contents and the f modifier specifies which file to
examine.
You want to create a compressed backup of the users' home directories. What
utility should you use?
tar
You can use the z modifier with tar to compress your archive at the same time as
creating it.
The syslogd daemon is responsible for tracking system information and saving it to
specified log files.
You have a file called phonenos that is almost 4,000 lines long. What text filter
can you use to split it into four pieces each 1,000 lines long?
split
The split text filter will divide files into equally sized pieces. The default length of each
piece is 1,000 lines.
You would like to temporarily change your command line editor to be vi. What
command should you type to change it?
set -o vi
The set command is used to assign environment variables. In this case, you are
instructing your shell to assign vi as your command line editor. However, once you log
off and log back in you will return to the previously defined command line editor.
Whenever you install Linux, only one user account is created. This is the superuser
account also known as root.
What command should you use to check the number of files and disk space
used and each user's defined quotas?
repquota
The repquota command is used to get a report on the status of the quotas you have set
including the amount of allocated space and amount of used space.
In order to run fsck on the root partition, the root partition must be mounted
as
readonly
The pwconv command creates the file /etc/shadow and changes all passwords to 'x' in
the /etc/passwd file.
Bob Armstrong, who has a username of boba, calls to tell you he forgot his
password. What command should you use to reset his command?
passwd boba
The passwd command is used to change your password. If you do not specify a
username, your password will be changed.
The top utility can be used to change the priority of a running process? Another
utility that can also be used to change priority is ___________?
nice
Both the top and nice utilities provide the capability to change the priority of a running
process.
What command should you type to see all the files with an extension of 'mem'
listed in reverse alphabetical order in the /home/ben/memos directory.
ls -r /home/ben/memos/*.mem
The -c option used with ls results in the files being listed in chronological order. You
can use wildcards with the ls command to specify a pattern of filenames.
What file defines the levels of messages written to system log files?
kernel.h
To determine the various levels of messages that are defined on your system, examine
the kernel.h file.
The gpasswd command is used to change the password assigned to a group. Use the -r
option to remove the password from the group.
What command would you type to use the cpio to create a backup called
backup.cpio of all the users' home directories?
find /home | cpio -o > backup.cpio
The find command is used to create a list of the files and directories contained in home.
This list is then piped to the cpio utility as a list of files to include and the output is
saved to a file called backup.cpio.
What can you type at a command line to determine which shell you are using?
echo $SHELL
The name and path to the shell you are using is saved to the SHELL environment
variable. You can then use the echo command to print out the value of any variable by
preceding the variable's name with $. Therefore, typing echo $SHELL will display the
name of your shell.
What type of local file server can you use to provide the distribution installation
materials to the new machine during a network installation?
A) Inetd
B) FSSTND
C) DNS
D) NNTP
E) NFS
E - You can use an NFS server to provide the distribution installation materials to the
machine on which you are performing the installation. Answers a, b, c, and d are all
valid items but none of them are file servers. Inetd is the superdaemon which controls
all intermittently used network services. The FSSTND is the Linux File System
Standard. DNS provides domain name resolution, and NNTP is the transfer protocol for
usenet news.
If you type the command cat dog & > cat what would you see on your
display? Choose one:
a. Any error messages only.
b. The contents of the file dog.
c. The contents of the file dog and any error messages.
d. Nothing as all output is saved to the file cat.
d
When you use & > for redirection, it redirects both the standard output and standard
error. The output would be saved to the file cat.
You are covering for another system administrator and one of the users asks
you to restore a file for him. You locate the correct tarfile by checking the
backup log but do not know how the directory structure was stored. What
command can you use to determine this?
Choose one:
a. tar fx tarfile dirname
b. tar tvf tarfile filename
c. tar ctf tarfile
d. tar tvf tarfile
d
The t switch will list the files contained in the tarfile. Using the v modifier will display
the stored directory structure.
You have the /var directory on its own partition. You have run out of space.
What should you do? Choose one:
a. Reconfigure your system to not write to the log files.
b. Use fips to enlarge the partition.
c. Delete all the log files.
d. Delete the partition and recreate it with a larger size.
d
The only way to enlarge a partition is to delete it and recreate it. You will then have to
restore the necessary files from backup.
You have a new application on a CD-ROM that you wish to install. What should
your first step be?
Choose one:
a. Read the installation instructions on the CD-ROM.
b. Use the mount command to mount your CD-ROM as read-write.
c. Use the umount command to access your CD-ROM.
d. Use the mount command to mount your CD-ROM as read-only.
d
Before you can read any of the files contained on the CD-ROM, you must first mount
the CD-ROM.
When you create a new partition, you need to designate its size by defining the
starting and ending _____________.
cylinders
When creating a new partition you must first specify its starting cylinder. You can then
either specify its size or the ending cylinder.
What key combination can you press to suspend a running job and place it in
the background?
ctrl-z
The easiest most basic form of backing up a file is to make a copy of that file to another
location such as a floppy disk.
C - You can use a DHCP server to assign IP addresses to individual machines during
the installation process. Answers a, b, d, and e list legitimate Linux servers, but these
servers do not provide IP addresses. The SMB, or Samba, tool is used for file and print
sharing across multi-OS networks. An NFS server is for file sharing across Linux net-
works. FTP is a file storage server that allows people to browse and retrieve information
by logging in to it, and HTTP is for the Web.
Which password package should you install to ensure that the central password
file couldn't be stolen easily?
A) PAM
B) tcp_wrappers
C) shadow
D) securepass
E) ssh
C - The shadow password package moves the central password file to a more secure
location. Answers a, b, and e all point to valid packages, but none of these places the
password file in a more secure location. Answer d points to an invalid package.
When using useradd to create a new user account, which of the following tasks
is not done automatically.
Choose one:
a. Assign a UID.
b. Assign a default shell.
c. Create the user's home directory.
d. Define the user's home directory.
c
The useradd command will use the system default for the user's home directory. The
home directory is not created, however, unless you use the -m option.
You want to enter a series of commands from the command-line. What would
be the quickest way to do this?
Choose One
a. Press enter after entering each command and its arguments
b. Put them in a script and execute the script
c. Separate each command with a semi-colon (;) and press enter after the last
command
d. Separate each command with a / and press enter after the last command
c
The semi-colon may be used to tell the shell that you are entering multiple commands
that should be executed serially. If these were commands that you would frequently
want to run, then a script might be more efficient. However, to run these commands
only once, enter the commands directly at the command line.
c
The password field must not be blank before converting to shadow passwords.
c
The default location for application documentation is in a directory named for the
application in the /usr/doc directory.
What file would you edit in your home directory to change which window
manager you want to use?
A) Xinit
B) .xinitrc
C) XF86Setup
D) xstart
E) xf86init
Answer: B - The ~/.xinitrc file allows you to set which window man-ager you want to
use when logging in to X from that account.
Answers a, d, and e are all invalid files. Answer c is the main X server configuration file.
What command allows you to set a processor-intensive job to use less CPU
time?
A) ps
B) nice
C) chps
D) less
E) more
Answer: B - The nice command is used to change a job's priority level, so that it runs
slower or faster. Answers a, d, and e are valid commands but are not used to change
process information. Answer c is an invalid command.
While logged on as a regular user, your boss calls up and wants you to create a
new user account immediately. How can you do this without first having to
close your work, log off and logon as root?
Choose one:
a. Issue the command rootlog.
b. Issue the command su and type exit when finished.
c. Issue the command su and type logoff when finished.
d. Issue the command logon root and type exit when finished.
Answer: b
You can use the su command to imitate any user including root. You will be prompted
for the password for the root account. Once you have provided it you are logged in as
root and can do any administrative duties.
There are seven fields in the /etc/passwd file. Which of the following lists all
the fields in the correct order?
Choose one:
a. username, UID, GID, home directory, command, comment
b. username, UID, GID, comment, home directory, command
c. UID, username, GID, home directory, comment, command
d. username, UID, group name, GID, home directory, comment
Answer: b
The seven fields required for each line in the /etc/passwd file are username, UID, GID,
comment, home directory, command. Each of these fields must be separated by a colon
even if they are empty.
Which of the following commands will show a list of the files in your home
directory including hidden files and the contents of all subdirectories?
Choose one:
a. ls -c home
b. ls -aR /home/username
c. ls -aF /home/username
d. ls -l /home/username
Answer: b
The ls command is used to display a listing of files. The -a option will cause hidden files
to be displayed as well. The -R option causes ls to recurse down the directory tree. All
of this starts at your home directory.
In order to prevent a user from logging in, you can add a(n) ________at the
beginning of the password field.
Answer: asterick
If you add an asterick at the beginning of the password field in the /etc/passwd file,
that user will not be able to log in.
Answer: a
When using the mv command to move a directory, if a directory of the same name
exists then a subdirectory is created for the files to be moved.
Which of the following tasks is not necessary when creating a new user by
editing the /etc/passwd file?
Choose one:
a. Create a link from the user's home directory to the shell the user will use.
b. Create the user's home directory
c. Use the passwd command to assign a password to the account.
d. Add the user to the specified group.
Answer: a
There is no need to link the user's home directory to the shell command. Rather, the
specified shell must be present on your system.
You issue the following command useradd -m bobm But the user cannot logon.
What is the problem?
Choose one:
a. You need to assign a password to bobm's account using the passwd command.
b. You need to create bobm's home directory and set the appropriate permissions.
c. You need to edit the /etc/passwd file and assign a shell for bobm's account.
d. The username must be at least five characters long.
Answer: a
The useradd command does not assign a password to newly created accounts. You will
still need to use the passwd command to assign a password.
You wish to print the file vacations with 60 lines to a page. Which of the
following commands will accomplish this? Choose one:
a. pr -l60 vacations | lpr
b. pr -f vacations | lpr
c. pr -m vacations | lpr
d. pr -l vacations | lpr
Answer: a
The default page length when using pr is 66 lines. The -l option is used to specify a
different length.
Answer: a
The /etc/passwd file contains all the information on users who may log into your
system. If a user account is not contained in this file, then the user cannot log in.
Answer(s): B - The fdisk partitioning tool is available in all Linux distributions. Answers
a, c, and e all handle partitioning, but do not come with all distributions. Disk Druid is
made by Red Hat and used in its distribution along with some derivatives. Partition
Magic and System Commander are tools made by third-party companies. Answer d is
not a tool, but a file system type. Specifically, FAT32 is the file system type used in
Windows 98.
Which partitions might you create on the mail server's hard drive(s) other than
the root, swap, and boot partitions?
[Choose all correct answers]
A) /var/spool
B) /tmp
C) /proc
D) /bin
E) /home
Answer(s): A, B, E - Separating /var/spool onto its own partition helps to ensure that if
something goes wrong with the mail server or spool, the output cannot overrun the file
system. Putting /tmp on its own partition prevents either software or user items in
the /tmp directory from overrunning the file system. Placing /home off on its own is
mostly useful for system re-installs or upgrades, allowing you to not have to wipe
the /home hierarchy along with other areas. Answers c and d are not possible, as
the /proc portion of the file system is virtual-held in RAM-not placed on the hard
drives, and the /bin hierarchy is necessary for basic system functionality and,
therefore, not one that you can place on a different partition.
When planning your backup strategy you need to consider how often you will
perform a backup, how much time the backup takes and what media you will
use. What other factor must you consider when planning your backup
strategy? _________
what to backup
Choosing which files to backup is the first step in planning your backup strategy.
In order to display the last five commands you have entered using the history
command, you would type ___________ .
Answer: history 5
The history command displays the commands you have previously entered. By passing
it an argument of 5, only the last five commands will be displayed.