Command Description Show commands • whatis pertinent to string. See also threadsafe a pdf of a manual • man -t ascii | ps2pdf - > ascii.pdf page Show full path name of which command See how long a command command takes Start stopwatch. Ctrl-d to • time stop. See also sw dir navigation • - 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 • pushd. so you can popd back to it searching • l=' -l --color=auto' quick dir listing List files by date. See also • ls -lrt newest and find_mm_yyyy Print in 9 columns to • ls /usr/bin | pr -T9 -W$COLUMNS width of terminal Search '' in this dir -name '*.[ch]' | -E 'expr' and below. See also findrepo Search all regular files find - f -print0 | xargs -r0 grep -F 'example' for 'example' in this dir and below Search all regular files find -maxdepth 1 -typef | xargs grep -F 'example' for 'example' in this dir Process each item with find -maxdepth 1 -type d | while read dir; do $dir; echo cmd2; done multiple commands (in while loop) Find files not readable by • find -type f ! -perm -444 all (useful for web site) Find dirs not accessible • find -type d ! -perm -111 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 tar -cdir/ | bzip2 >dir.tar.bz2 archiveExtract archive of dir/ (use gzip bzip2 -dc dir.tar.bz2 | tar -x instead of bzip2 for tar.gz files) Make encrypted archive tar -cdir/ | gzip | gpg -c | ssh user@remote ' of=dir.tar.gz.gpg' of dir/ on remote machine Make archive of subset of find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2 dir/ and below Make copy of subset of find dir/ -name '*.txt' | xargs -a --target-directory=dir_txt/ --parents dir/ 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/ && tar -x -p' copy/ dir to remote:/where/to/ dir Backup harddisk to dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz' remote machine rsync (Network efficient file copier: Use the --dry-run option for testing) Only get diffs. Do rsync -P rsync://rsync.server.com/path/to/file file multiple times for troublesome downloads Locally copy with rate rsync --bwlimit=1000 fromfile tofile limit. It's like for I/O Mirror web site (using rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html' compression and encryption) Synchronize current rsync -auz -e ssh remote:/dir/. && rsync -auz -e 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 ssh -R 1434:imap:143 root@$HOST from $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 http://www.pixelbeat.org/cmdline.html) version of a page to the 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 wget ftp://remote/file[1-9].iso/ FTP supports globbing directly • wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | Process output directly Download url 1AM to echo 'wget url' | at 01:00 current dir Do a low priority wget --limit-rate=20k url download (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 ) 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 ip link set dev eth0 up (or down) List addresses for • ip addr show 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 • host pixelbeat.org for 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) name nmblookup -A 1.2.3.4 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 /mnt/share Mount a windows share Send popup to windows echo 'message' | smbclient -M windows_box machine (off by default in XP sp2) text manipulation (Note uses stdin and stdout. Newer versions support inplace editing with the - i option) Replace string1 with sed 's/string1/string2/g' 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>.*/\1/ip;T;q' web page sed -i 42d ~/.ssh/known_hosts Delete a particular line <a href="/tags/Sort_(Unix)/" rel="tag">sort</a> -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses • echo '<a href="/tags/Test_(Unix)/" rel="tag">Test</a>' | <a href="/tags/Tr_(Unix)/" rel="tag">tr</a> '[: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 | <a href="/tags/Wc_(Unix)/" rel="tag">wc</a> -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 | <a href="/tags/Uniq/" rel="tag">uniq</a> Union of unsorted files Intersection of unsorted sort file1 file2 | uniq -d files Difference of unsorted sort file1 file1 file2 | uniq -u files Symmetric Difference of sort file1 file2 | uniq -u unsorted files <a href="/tags/Join_(Unix)/" rel="tag">join</a> -t'\0' -a1 -a2 file1 file2 Union of sorted files Intersection of sorted join -t'\0' file1 file2 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 | <a href="/tags/Paste_(Unix)/" rel="tag">paste</a> -sd-+ | bc -l Calculate π the unix way <a href="/tags/More_(command)/" rel="tag">More</a> complex (int) e.g. • echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bc This shows max FastE packet rate Python handles scientific • echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | python notation Plot FastE packet rate vs • echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | 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 (SI to IEC • units -t '500GB' 'GiB' prefixes)</p><p>• units -t '1 googol' Definition lookup Add a column of • seq 100 | (tr '\n' +; echo 0) | bc numbers. See also add and funcpy calendar • <a href="/tags/Cal_(Unix)/" rel="tag">cal</a> -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 <a href="/tags/Exit_(command)/" rel="tag">exit</a> a script unless it's • [ $(date -d "tomorrow" +%d) = "01" ] || exit the last day of the month What day does xmas fall • date --date='25 Dec' +%A on, this year Convert seconds since • date --date='@2147483647' the 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 • <a href="/tags/Printf_(Unix)/" rel="tag">printf</a> "%'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 Lookup locale info for • LANG=en_IE.utf8 locale int_prefix specific country. See also ccodes List fields available in • locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | less locale database recode (Obsoletes <a href="/tags/Iconv/" rel="tag">iconv</a>, dos2unix, unix2dos) Show available • recode -l | less conversions (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) recode iso-8859-15..utf8 file_to_change.txt 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 Lookup table of • recode -lf windows-1252 | grep euro 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, • ls -lSr biggest last Show top disk users in • <a href="/tags/Du_(Unix)/" rel="tag">du</a> -s* | sort-k1,1rn | head current dir. See also dutop Sort paths by easy to • du -hs /home/* | sort -k1,1h interpret disk usage Show free space on • <a href="/tags/Df_(Unix)/" rel="tag">df</a> -h mounted filesystems Show free inodes on • df -i mounted filesystems Show disks partitions • fdisk -l sizes 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 -k1,1n installed size (KBytes) on 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</p><p>Monitor messages in a • <a href="/tags/Tail_(Unix)/" rel="tag">tail</a> -f /var/log/messages log file Summarise/profile • strace -c ls >/dev/null system 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=<a href="/tags/Write_(Unix)/" rel="tag">write</a> -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 • <a href="/tags/Ps_(Unix)/" rel="tag">ps</a> -e -o pid,args --forest hierarchy List processes by % cpu • ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /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 Show system reboot • last 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 • <a href="/tags/Uname/" rel="tag">uname</a> -a system architecture Show name and version • head -n1 /etc/issue of 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 # hdparm -tT /dev/sda Do a read speed test on disk sda Test for unreadable # badblocks -s /dev/sda blocks on disk sda interactive (see also <a href="/tags/Linux/" rel="tag">linux</a> keyboard shortcuts) Line editor used by bash, • readline python, bc, gnuplot, ... Virtual terminals with • screen detach capability, ... Powerful file manager • mc 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</p><p>© Jan 7 2008 [Comments] | [Add link to ...]</p><p>Ads by Google Linux Basic Linux Training Linux System Monitor Free Linux Scripts</p> </div> </article> </div> </div> </div> <script type="text/javascript" async crossorigin="anonymous" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8519364510543070"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script> var docId = 'f2b7791d3a1c1cdb3ac72f9bc307bb1a'; var endPage = 1; var totalPage = 8; var pfLoading = false; window.addEventListener('scroll', function () { if (pfLoading) return; var $now = $('.article-imgview .pf').eq(endPage - 1); if (document.documentElement.scrollTop + $(window).height() > $now.offset().top) { pfLoading = true; endPage++; if (endPage > totalPage) return; var imgEle = new Image(); var imgsrc = "//data.docslib.org/img/f2b7791d3a1c1cdb3ac72f9bc307bb1a-" + endPage + (endPage > 3 ? ".jpg" : ".webp"); imgEle.src = imgsrc; var $imgLoad = $('<div class="pf" id="pf' + endPage + '"><img src="/loading.gif"></div>'); $('.article-imgview').append($imgLoad); imgEle.addEventListener('load', function () { $imgLoad.find('img').attr('src', imgsrc); pfLoading = false }); if (endPage < 7) { adcall('pf' + endPage); } } }, { passive: true }); </script> <script> var sc_project = 11552861; var sc_invisible = 1; var sc_security = "b956b151"; </script> <script src="https://www.statcounter.com/counter/counter.js" async></script> </html><script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>