07-03 linux commands
TRANSCRIPT
-
8/2/2019 07-03 Linux Commands
1/14
Command Description
apropos whatisShow commandspertinent to string. Seealsothreadsafe
man-t ascii | ps2pdf - > ascii.pdfmake a pdf of a manual
page
which commandShow full path name ofcommand
time commandSee how long a commandtakes
time catStart stopwatch. Ctrl-d tostop. See alsosw
dir navigation
cd - Go to previous directory cd Go to $HOME directory
(cd dir && command) Go to dir, executecommand and return tocurrent dir
pushd .Put current dir on stack soyou can popd back to it
file searching
aliasl='ls -l --color=auto' quick dir listing
ls -lrtList files by date. Seealsonewestandfind_mm_yyyy
ls /usr/bin | pr -T9 -W$COLUMNSPrint in 9 columns to
width of terminal
find -name '*.[ch]' | xargs grep -E 'expr'Search 'expr' in this dirand below. See alsofindrepo
find -type f -print0 | xargs -r0 grep -F 'example'Search all regular files for'example' in this dir andbelow
find -maxdepth 1 -type f | xargs grep -F 'example'Search all regular files for'example' in this dir
find -maxdepth 1 -type d | whilereaddir; do echo $dir; echo cmd2;
done
Process each item withmultiple commands (inwhile loop)
find -type f ! -perm -444Find files not readable byall (useful for web site)
find -type d ! -perm -111Find dirs not accessibleby all (useful for website)
locate -r 'file[^/]*\.txt' Search cached index for
http://www.pixelbeat.org/scripts/threadsafehttp://www.pixelbeat.org/scripts/threadsafehttp://www.pixelbeat.org/scripts/threadsafehttp://www.pixelbeat.org/lkdb/less.htmlhttp://www.pixelbeat.org/lkdb/less.htmlhttp://www.pixelbeat.org/lkdb/less.htmlhttp://www.pixelbeat.org/scripts/stopwatch/http://www.pixelbeat.org/scripts/stopwatch/http://www.pixelbeat.org/scripts/stopwatch/http://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/scripts/newesthttp://www.pixelbeat.org/scripts/newesthttp://www.pixelbeat.org/scripts/newesthttp://www.pixelbeat.org/scripts/find_mm_yyyyhttp://www.pixelbeat.org/scripts/find_mm_yyyyhttp://www.pixelbeat.org/scripts/findrepohttp://www.pixelbeat.org/scripts/findrepohttp://www.pixelbeat.org/programming/readline/http://www.pixelbeat.org/programming/readline/http://www.pixelbeat.org/programming/readline/http://www.pixelbeat.org/programming/readline/http://www.pixelbeat.org/scripts/findrepohttp://www.pixelbeat.org/scripts/find_mm_yyyyhttp://www.pixelbeat.org/scripts/newesthttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/scripts/stopwatch/http://www.pixelbeat.org/lkdb/less.htmlhttp://www.pixelbeat.org/scripts/threadsafe -
8/2/2019 07-03 Linux Commands
2/14
names. This re is likeglob *file*.txt
look referenceQuickly search (sorted)dictionary for prefix
grep--colorreference /usr/share/dict/words
Highlight occurances of
regular expression indictionary
archives and compression
gpg -c file Encrypt file
gpg file.gpg Decrypt file
tar -c dir/ | bzip2 > dir.tar.bz2Make compressed archiveof dir/
bzip2 -dc dir.tar.bz2 | tar -xExtract archive (use gzipinstead of bzip2 for tar.gzfiles)
tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'Make encrypted archiveof dir/ on remote machine
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2Make archive of subset ofdir/ and below
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parents
Make copy of subset ofdir/ and below
( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p )Copy (with permissions)copy/ dir to /where/to/ dir
( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p )Copy (with permissions)contents of copy/ dir to/where/to/
( tar -c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ && tar -x -p'
Copy (with permissions)copy/ dir toremote:/where/to/ dir
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'Backup harddisk toremote machine
rsync (Network efficient file copier: Use the --dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file fileOnly get diffs. Domultiple times fortroublesome downloads
rsync --bwlimit=1000 fromfile tofileLocally copy with ratelimit. It's like nice for I/O
rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html'Mirror web site (usingcompression andencryption)
rsync -auz -e ssh remote:/dir/. && rsync -auz -e ssh . remote:/dir/Synchronize currentdirectory with remote one
ssh (Secure SHell)
ssh $USER@$HOST command Run command on $HOST
http://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrc -
8/2/2019 07-03 Linux Commands
3/14
as $USER (defaultcommand=shell)
ssh -f -Y $USER@$HOSTNAME xeyesRun GUI command on$HOSTNAME as $USER
scp -p -r $USER@$HOST: file dir/
Copy with permissions to
$USER's home directoryon $HOST
scp -c arcfour $USER@$LANHOST: bigfileUse faster crypto for localLAN. This might saturateGigE
ssh -g -L 8080:localhost:80 root@$HOSTForward connections to$HOSTNAME:8080 outto $HOST:80
ssh -R 1434:imap:143 root@$HOSTForward connectionsfrom $HOST:1434 in toimap:143
ssh-copy-id $USER@$HOSTInstall $USER's publickey on $HOST forpassword-less log in
wget (multi purpose download tool)
(cd dir/ && wget -nd -pHEKkhttp://www.pixelbeat.org/cmdline.html)
Store local browsableversion of a page to thecurrent dir
wget -c http://www.example.com/large.fileContinue downloading apartially downloaded file
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/Download a set of files to
the current directorywget ftp://remote/file[1-9].iso/
FTP supports globbingdirectly
wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' |head
Process output directly
echo 'wget url' | at 01:00Download url at 1AM tocurrent dir
wget --limit-rate=20k urlDo a low prioritydownload (limit to20KB/sin this case)
wget -nv --spider --force-html -i bookmarks.html Check links in a file
wget --mirror http://www.example.com/Efficiently update a localcopy of a site (handyfrom cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
ethtool eth0Show status of ethernetinterface eth0
ethtool --change eth0 autoneg off speed 100 duplex full Manually set ethernet
http://www.pixelbeat.org/speeds.htmlhttp://www.pixelbeat.org/speeds.htmlhttp://www.pixelbeat.org/speeds.html -
8/2/2019 07-03 Linux Commands
4/14
interface speed
iwconfig eth1Show status of wirelessinterface eth1
iwconfig eth1 rate 1Mb/s fixedManually set wirelessinterface speed
iwlist scan List wireless networks inrange
ip link show List network interfaces
ip link set dev eth0 name wanRename interface eth0 towan
ip link set dev eth0 upBring interface eth0 up(or down)
ip addr showList addresses forinterfaces
ip addr add 1.2.3.4/24 brd + dev eth0Add (or del) ip and mask(255.255.255.0)
ip route show List routing table
ip route add default via 1.2.3.254Set default gateway to1.2.3.254
host pixelbeat.orgLookup DNS ip addressfor name or vice versa
hostname -iLookup local ip address(equivalent to host`hostname`)
whois pixelbeat.orgLookup whois info forhostname or ip address
netstat -tupl List internet services on asystem
netstat -tupList active connectionsto/from system
windows networking (Note samba is the package that provides all this windows specificnetworking support)
smbtreeFind windows machines.See also findsmb
nmblookup -A 1.2.3.4Find the windows(netbios) name associatedwith ip address
smbclient -L windows_boxList shares on windowsmachine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/share Mount a windows share
echo 'message' | smbclient -M windows_boxSend popup to windowsmachine (off by default inXP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing with
-
8/2/2019 07-03 Linux Commands
5/14
the -i option)
sed 's/string1/string2/g'Replace string1 withstring2
sed 's/\(.*\)1/\12/g'Modify anystring1 toanystring2
sed '/ *#/d; /^ *$/d' Remove comments andblank lines
sed ':a; /\\$/N; s/\\\n//; ta'Concatenate lines withtrailing \
sed 's/[ \t]*$//'Remove trailing spacesfrom lines
sed 's/\([`"$\]\)/\\\1/g'Escape shellmetacharacters activewithin double quotes
seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" Right align numberssed -n '1000{p;q}' Print 1000th line
sed -n '10,20p;20q' Print lines 10 to 20
sed -n 's/.*\(.*\).*/\1/ip;T;q'Extract title from HTMLweb 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
tr -dc '[:print:]' < /dev/urandomFilter non printablecharacters
tr -s '[:blank:]' '\t'
-
8/2/2019 07-03 Linux Commands
6/14
echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bcMore complex (int) e.g.This shows max FastEpacket rate
echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | pythonPython handles scientificnotation
echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | gnuplot -persist
Plot FastE packet rate vspacket size
echo 'obase=16; ibase=10; 64206' | bcBase conversion (decimalto hexadecimal)
echo $((0x2dec))Base conversion (hex todec) ((shell arithmeticexpansion))
units -t '100m/9.58s' 'miles/hour'Unit conversion (metricto imperial)
units -t '500GB' 'GiB'Unit conversion (SI toIEC prefixes)
units -t '1 googol' Definition lookup
seq 100 | (tr '\n' +; echo 0) | bcAdd a column ofnumbers. See alsoaddandfuncpy
calendar
cal -3 Display a calendar
cal 9 1752Display a calendar for aparticular month year
date -d friWhat date is it this friday.See alsoday
[ $(date -d "tomorrow" +%d) = "01" ] || exit exit a script unless it's thelast day of the month
date --date='25 Dec' +%AWhat day does xmas fallon, this year
date --date='@2147483647'Convert seconds since theepoch (1970-01-01 UTC)to date
TZ='America/Los_Angeles' dateWhat time is it on westcoast of US (use tzselectto find TZ)
date --date='TZ="America/Los_Angeles" 09:00 next Fri'What's the local time for
9AM next Friday on westcoast US
locales
printf "%'d\n" 1234Print number withthousands groupingappropriate to locale
BLOCK_SIZE=\'1 ls -l Use locale thousands
http://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/scripts/bchttp://www.pixelbeat.org/misc/usain_bolt/http://www.pixelbeat.org/misc/usain_bolt/http://www.pixelbeat.org/misc/usain_bolt/http://www.pixelbeat.org/scripts/addhttp://www.pixelbeat.org/scripts/addhttp://www.pixelbeat.org/scripts/addhttp://www.pixelbeat.org/scripts/funcpyhttp://www.pixelbeat.org/scripts/funcpyhttp://www.pixelbeat.org/scripts/funcpyhttp://www.pixelbeat.org/scripts/dayhttp://www.pixelbeat.org/scripts/dayhttp://www.pixelbeat.org/scripts/dayhttp://www.pixelbeat.org/scripts/dayhttp://www.pixelbeat.org/scripts/funcpyhttp://www.pixelbeat.org/scripts/addhttp://www.pixelbeat.org/misc/usain_bolt/ -
8/2/2019 07-03 Linux Commands
7/14
grouping in ls. See alsol
echo "I live in `locale territory`"Extract info from localedatabase
LANG=en_IE.utf8 locale int_prefixLookup locale info forspecific country. See also
ccodes
locale | cut -d= -f1 | xargs locale -kc | lessList fields available inlocale database
recode (Obsoletes iconv, dos2unix, unix2dos)
recode -l | lessShow availableconversions (aliases oneach line)
recode windows-1252.. file_to_change.txtWindows "ansi" to localcharset (auto does CRLFconversion)
recode utf-8/CRLF.. file_to_change.txt
Windows utf8 to local
charset
recode iso-8859-15..utf8 file_to_change.txtLatin9 (western europe)to 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 euroLookuptable ofcharacters
echo -n 0x80 | recode latin-9/x1..dumpShow what a coderepresents 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 encodingCDs
gzip < /dev/cdrom > cdrom.iso.gz Save copy of data cdrom
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gzCreate cdrom image fromcontents of dir
mount -o loop cdrom.iso /mnt/dirMount the cdrom imageat /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fast Clear a CDRW
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom - Burn cdrom image (usedev=ATAPI -scanbus toconfirm dev)
cdparanoia -BRip audio tracks from CDto wav files in current dir
cdrecord -v dev=/dev/cdrom -audio -pad *.wavMake audio CD from allwavs in current dir (seealso cdrdao)
http://www.pixelbeat.org/scripts/lhttp://www.pixelbeat.org/scripts/lhttp://www.pixelbeat.org/scripts/lhttp://www.pixelbeat.org/scripts/ccodeshttp://www.pixelbeat.org/scripts/ccodeshttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/docs/utf8.htmlhttp://www.pixelbeat.org/scripts/ccodeshttp://www.pixelbeat.org/scripts/l -
8/2/2019 07-03 Linux Commands
8/14
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'Make ogg file from wavfile
disk space (See alsoFSlint)
ls -lSrShow files by size,biggest last
du -s * | sort -k1,1rn | headShow top disk users incurrent dir. See alsodutop
du -hs /home/* | sort -k1,1hSort paths by easy tointerpret disk usage
df -hShow free space onmounted filesystems
df -iShow free inodes onmounted filesystems
fdisk -lShow disks partitionssizes and types (run asroot)
rpm-q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1nList allpackagesbyinstalled size (Bytes) onrpm distros
dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1nList allpackagesbyinstalled size (KBytes) ondeb distros
dd bs=1 seek=2TB if=/dev/null of=ext3.testCreate a large test file(taking no space). Seealsotruncate
> file truncate data of file orcreate an empty filemonitoring/debugging
tail -f /var/log/messagesMonitor messagesin alog file
strace -c ls >/dev/nullSummarise/profile systemcalls made by command
strace -f -e open ls >/dev/nullList system calls made bycommand
strace -f -e trace=write -e write=1,2 ls >/dev/nullMonitor what's written tostdout and stderr
ltrace -f -e getenv ls >/dev/null List library calls made bycommand
lsof -p $$List paths that process idhas open
lsof ~List processes that havespecified path open
tcpdump not port 22 Show network traffic
http://www.pixelbeat.org/fslint/http://www.pixelbeat.org/fslint/http://www.pixelbeat.org/fslint/http://www.pixelbeat.org/scripts/dutophttp://www.pixelbeat.org/scripts/dutophttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/scripts/truncatehttp://www.pixelbeat.org/scripts/truncatehttp://www.pixelbeat.org/scripts/truncatehttp://www.pixelbeat.org/docs/web/access_log/monitoring.htmlhttp://www.pixelbeat.org/docs/web/access_log/monitoring.htmlhttp://www.pixelbeat.org/docs/web/access_log/monitoring.htmlhttp://www.pixelbeat.org/scripts/truncatehttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/docs/packaging.htmlhttp://www.pixelbeat.org/scripts/dutophttp://www.pixelbeat.org/fslint/ -
8/2/2019 07-03 Linux Commands
9/14
except ssh. See alsotcpdump_not_me
ps -e -o pid,args --forestList processes in ahierarchy
ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'List processes by % cpu
usage
ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNSList processes by mem(KB) usage. See alsops_mem.py
ps -C firefox-bin -L -o pid,tid,pcpu,stateList all threads for aparticular process
ps -p 1,$$ -o etime=List elapsed wall time forparticular process IDs
last rebootShow system reboothistory
free -mShow amount of
(remaining) RAM (-mdisplays in MB)
watch -n.1 'cat /proc/interrupts'Watch changeable datacontinuously
udevadm monitorMonitor udev events tohelp configure rules
system information (see alsosysinfo) ('#' means root access is required)
uname -aShow kernel version andsystem architecture
head -n1 /etc/issueShow name and version
of distribution cat /proc/partitions
Show all partitionsregistered on the system
grep MemTotal /proc/meminfoShow RAM total seen bythe system
grep "model name" /proc/cpuinfo Show CPU(s) info lspci -tv Show PCI info lsusb -tv Show USB info
mount | column -tList mounted filesystemson the system (and alignoutput)
grep -F capacity: /proc/acpi/battery/BAT0/infoShow state of cells inlaptop battery
# dmidecode -q | lessDisplay SMBIOS/DMIinformation
# smartctl -A /dev/sda | grep Power_On_HoursHow long has this disk(system) been poweredon in total
http://www.pixelbeat.org/scripts/tcpdump_not_mehttp://www.pixelbeat.org/scripts/tcpdump_not_mehttp://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.pixelbeat.org/scripts/sysinfohttp://www.pixelbeat.org/scripts/sysinfohttp://www.pixelbeat.org/scripts/sysinfohttp://www.pixelbeat.org/scripts/sysinfohttp://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.pixelbeat.org/scripts/tcpdump_not_me -
8/2/2019 07-03 Linux Commands
10/14
# hdparm -i /dev/sda Show info about disk sda
# hdparm -tT /dev/sdaDo a read speed test ondisk sda
# badblocks -s /dev/sdaTest for unreadableblocks on disk sda
interactive (see alsolinux keyboard shortcuts)
readlineLine editor used by bash,python, bc, gnuplot, ...
screenVirtual terminals withdetach capability, ...
mcPowerful file managerthat can browse rpm, tar,ftp, ssh, ...
gnuplotInteractive/scriptablegraphing
links Web browser
xdg-open .open a file or url with theregistered desktopapplication
Command Description
grep . /proc/sys/net/ipv4/*List the contents of flagfiles
set | grep $USERSearch currentenvironment
tr '\0' '\n' < /proc/$$/environDisplay the startupenvironment for any
process
echo $PATH | tr : '\n'Display the $PATH oneper line
kill -0 $$ && echo process exists and can accept signalsCheck for the existenceof a process (pid)
find /etc -readable | xargs less -K -p'*ntp' -j $((${LINES:-25}/2))Search paths and datawith full context. Use nto iterate
Low impact admin
#apt-get install "package" -o Acquire::http::Dl-Limit=42 \-o Acquire::Queue-mode=access
Rate limit apt-get to42KB/s
echo 'wget url' | at 01:00Download url at 1AM tocurrent dir
# apache2ctl configtest && apache2ctl gracefulRestart apache if config isOK
nice openssl speed sha1Run a low prioritycommand (opensslbenchmark)
http://www.pixelbeat.org/lkdb/http://www.pixelbeat.org/lkdb/http://www.pixelbeat.org/lkdb/http://www.pixelbeat.org/lkdb/readline.htmlhttp://www.pixelbeat.org/lkdb/readline.htmlhttp://www.pixelbeat.org/lkdb/readline.htmlhttp://www.pixelbeat.org/lkdb/screen.htmlhttp://www.pixelbeat.org/lkdb/screen.htmlhttp://www.pixelbeat.org/lkdb/screen.htmlhttp://www.pixelbeat.org/lkdb/mc.htmlhttp://www.pixelbeat.org/lkdb/mc.htmlhttp://www.pixelbeat.org/docs/web/access_log/analyzing.htmlhttp://www.pixelbeat.org/docs/web/access_log/analyzing.htmlhttp://www.pixelbeat.org/docs/web/access_log/analyzing.htmlhttp://www.pixelbeat.org/docs/env.htmlhttp://www.pixelbeat.org/docs/env.htmlhttp://www.pixelbeat.org/speeds.htmlhttp://www.pixelbeat.org/speeds.htmlhttp://www.pixelbeat.org/speeds.htmlhttp://www.pixelbeat.org/docs/env.htmlhttp://www.pixelbeat.org/docs/web/access_log/analyzing.htmlhttp://www.pixelbeat.org/lkdb/mc.htmlhttp://www.pixelbeat.org/lkdb/screen.htmlhttp://www.pixelbeat.org/lkdb/readline.htmlhttp://www.pixelbeat.org/lkdb/ -
8/2/2019 07-03 Linux Commands
11/14
renice 19 -p $$; ionice -c3 -p $$Make shell (script) lowpriority. Use for noninteractive tasks
Interactive monitoring
htop -d 5
Better top (scrollable, tree
view, lsof/straceintegration, ...)
iotop What's doing I/O# watch -d -n30 "niceps_mem.py| tail -n $((${LINES:-12}-2))" What's using RAM
# iftopWhat's using the network.See also iptraf
# mtr www.pixelbeat.orgping and traceroutecombined
Useful utilities
pv< /dev/zero > /dev/nullProgress Viewer for datacopying from files andpipes
wkhtml2pdfhttp://.../linux_commands.htmllinux_commands.pdf Make a pdf of a web page
timeout1 sleep 3run a command withbounded time. See alsotimeout
Networking
python -m SimpleHTTPServer
Serve current directorytree athttp://$HOSTNAME:8000/
openssl s_client -connect www.google.com:443 &0 |openssl x509 -dates -noout
Display the date range fora site's certs
curl -I www.pixelbeat.orgDisplay the serverheaders for a web site
# lsof -i tcp:80 What's using port 80
# httpd -SDisplay a list of apachevirtual hosts
vim scp://user@remote//path/to/fileEdit a remote file directlyin vim
curl -s http://www.pixelbeat.org/pixelbeat.asc | gpg --importImport a gpg key fromthe web
tc qdisc add dev lo root handle 1:0 netem delay 20msecAdd 20ms latency toloopback device (fortesting)
tc qdisc del dev lo rootRemove latency addedabove
Notification
echo "DISPLAY=$DISPLAY xmessage cooker" | at "NOW +30min" Popup reminder
http://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.pixelbeat.org/scripts/ps_mem.pyhttp://www.ivarch.com/programs/pv.shtmlhttp://www.ivarch.com/programs/pv.shtmlhttp://www.ivarch.com/programs/pv.shtmlhttp://code.google.com/p/wkhtmltopdf/http://code.google.com/p/wkhtmltopdf/http://code.google.com/p/wkhtmltopdf/http://www.pixelbeat.org/docs/linux_commands.pdfhttp://www.pixelbeat.org/docs/linux_commands.pdfhttp://www.pixelbeat.org/docs/linux_commands.pdfhttp://www.gnu.org/software/coreutils/manual/coreutils.html#timeout-invocationhttp://www.gnu.org/software/coreutils/manual/coreutils.html#timeout-invocationhttp://www.gnu.org/software/coreutils/manual/coreutils.html#timeout-invocationhttp://www.pixelbeat.org/scripts/timeouthttp://www.pixelbeat.org/scripts/timeouthttp://localhost:8000/http://localhost:8000/http://localhost:8000/http://localhost:8000/http://localhost:8000/http://www.pixelbeat.org/scripts/timeouthttp://www.gnu.org/software/coreutils/manual/coreutils.html#timeout-invocationhttp://www.pixelbeat.org/docs/linux_commands.pdfhttp://code.google.com/p/wkhtmltopdf/http://www.ivarch.com/programs/pv.shtmlhttp://www.pixelbeat.org/scripts/ps_mem.py -
8/2/2019 07-03 Linux Commands
12/14
notify-send "subject" "message"Display a gnome popupnotification
echo "mail -s 'go home' [email protected] < /dev/null" | at 17:30 Email reminder
uuencode file name | mail -s subject [email protected] Send a file via email
ansi2html.sh| mail -a "Content-Type: text/html" [email protected]/Generate HTML
emailBetterdefault settings(useful in your.bashrc)
# tail -s.1 -f /var/log/messagesDisplay file additionsmore responsively
seq 100 | tail -n $((${LINES:-12}-2))Display as many lines aspossible without scrolling
# tcpdump -s0Capture full networkpackets
Useful functions/aliases (useful in your.bashrc)
md () { mkdir -p "$1" && cd "$1"; }Change to a new
directory strerror() { python -c "import os; print os.strerror($1)"; }
Display the meaning ofanerrno
plot() { { echo 'plot "-"' "$@"; cat; } | gnuplot -persist; }Plot stdin. (e.g: seq1000 | sed 's/.*/s(&)/' | bc-l | plot)
alias hd='od -Ax -tx1z -v'Handy hexdump. (usagee.g.: hd/proc/self/cmdline | less)
alias realpath='readlink -f'Canonicalize path. (usagee.g.: realpath
~/../$USER)Multimedia
DISPLAY=:0.0 import -window root orig.pngTake a (remote)screenshot
convert -filter catrom -resize'600x>' orig.png 600px_wide.pngShrinkto width,computer generatedimages or screenshots
mplayer -ao pcm -vo null -vc dummy /tmp/Flash*Extract audio from flashvideo to audiodump.wav
ffmpeg -i filename.aviDisplay info aboutmultimedia file
ffmpeg -f x11grab -s xga -r 25 -i :0 -sameq demo.mpgCapture video of an Xdisplay
DVD
for i in $(seq 9); do ffmpeg -i $i.avi -target pal-dvd $i.mpg; doneConvert video to thecorrect encoding andaspect for DVD
dvdauthor -odvd -t -v "pal,4:3,720xfull" *.mpg;dvdauthor -odvd -T Build DVD file system.
http://www.pixelbeat.org/scripts/ansi2html.shhttp://www.pixelbeat.org/scripts/ansi2html.shhttp://www.pixelbeat.org/docs/power_of_the_default.htmlhttp://www.pixelbeat.org/docs/power_of_the_default.htmlhttp://www.pixelbeat.org/docs/power_of_the_default.htmlhttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/scripts/errnohttp://www.pixelbeat.org/scripts/errnohttp://www.pixelbeat.org/scripts/errnohttp://www.imagemagick.org/Usage/resize/http://www.imagemagick.org/Usage/resize/http://www.imagemagick.org/Usage/resize/http://www.pixelbeat.org/docs/image_manipulation/#resizehttp://www.pixelbeat.org/docs/image_manipulation/#resizehttp://www.pixelbeat.org/docs/image_manipulation/#resizehttp://www.imagemagick.org/Usage/resize/http://www.pixelbeat.org/scripts/errnohttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/settings/.bashrchttp://www.pixelbeat.org/docs/power_of_the_default.htmlhttp://www.pixelbeat.org/scripts/ansi2html.sh -
8/2/2019 07-03 Linux Commands
13/14
Use 16:9 for widescreeninput
growisofs -dvd-compat -Z /dev/dvd -dvd-video dvdBurn DVD file system todisc
Unicode
python -c "import unicodedata as u; print u.name(unichr(0x2028))" Lookup a unicodecharacter
uconv-f utf8 -t utf8 -x nfcNormalizecombiningcharacters
printf '\300\200' | iconv -futf8 -tutf8 >/dev/null Validate UTF-8
printf 'TF8\n' | LANG=C grep --color=always '[^ -~]\+'Highlight non printableASCII chars in UTF-8
fc-match -s "sans:lang=zh"List font match order forlanguage and style
Development
gcc -march=native -E -v -&1|sed -n 's/.*-mar/-mar/p'Show autodetected gcctuning params. See alsogcccpuopt
for i in $(seq 4); do { [ $i = 1 ] && wgethttp://url.ie/6lko-qO-||./a.out; } | tee /dev/tty | gcc -xc - 2>/dev/null; done
Compile and execute Ccode from stdin
cpp -dM /dev/nullShow all predefinedmacros
echo "#include " | cpp -dN | grep "#define __USE_"Show all glibc featuremacros
gdb -tuiDebug showing sourcecode context inseparate
windowsExtended Attributes (Note you may need to (re)mount with "acl" or "user_xattr" options)
getfacl . Show ACLs for file
setfacl -m u:nobody:r .Allow a specific user toread file
setfacl -x u:nobody .Delete a specific user'srights to file
setfacl --default -m group:users:rw- dir/Set umask for a for aspecific dir
getcap fileShow capabilities for aprogram
setcap cap_net_raw+ep your_gtk_progAllow gtk program rawaccess to network
stat -c%C .Show SELinux contextfor file
chcon ... fileSet SELinux context forfile (see also restorecon)
getfattr -m- -d . Show all extended
http://manpages.ubuntu.com/manpages/dapper/en/man1/uconv.1.htmlhttp://manpages.ubuntu.com/manpages/dapper/en/man1/uconv.1.htmlhttp://manpages.ubuntu.com/manpages/dapper/en/man1/uconv.1.htmlhttp://www.pixelbeat.org/docs/unicode_utils/#normalizehttp://www.pixelbeat.org/docs/unicode_utils/#normalizehttp://www.pixelbeat.org/scripts/gcccpuopthttp://www.pixelbeat.org/scripts/gcccpuopthttp://www0.us.ioccc.org/2000/dhyang.chttp://www0.us.ioccc.org/2000/dhyang.chttp://www0.us.ioccc.org/2000/dhyang.chttp://www.pixelbeat.org/programming/debugger/#tuihttp://www.pixelbeat.org/programming/debugger/#tuihttp://www.pixelbeat.org/programming/debugger/#tuihttp://www.pixelbeat.org/programming/debugger/#tuihttp://www.pixelbeat.org/programming/debugger/#tuihttp://www.pixelbeat.org/programming/debugger/#tuihttp://www0.us.ioccc.org/2000/dhyang.chttp://www.pixelbeat.org/scripts/gcccpuopthttp://www.pixelbeat.org/docs/unicode_utils/#normalizehttp://manpages.ubuntu.com/manpages/dapper/en/man1/uconv.1.html -
8/2/2019 07-03 Linux Commands
14/14
attributes (includesselinux,acls,...)
setfattr -n "user.foo" -v "bar" .Set arbitrary userattributes
BASH specific
echo 123 | tee >(tr 1 a) | tr 1 bSplit data to 2 commands(using processsubstitution)
meldlocal_file