
Command Description Show commands • apropos whatis pertinent 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 • pushd. so you can popd back to it file searching • alias l='ls -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 'expr' in this dir find -name '*.[ch]' | xargs grep -E 'expr' and below. See also findrepo Search all regular files find -type 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 echo $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 Extractarchive 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 'dd 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 cp -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 nice 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' | head Process output directly Download url at 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 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 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 sed 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>\(.*\)<\/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 Difference of unsorted sort file1 file1 file2 | uniq -u files Symmetric Difference of sort file1 file2 | uniq -u unsorted files join -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 | paste -sd-+ | bc -l Calculate π the unix way More 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) • units -t '1 googol' Definition lookup Add a column of • seq 100 | (tr '\n' +; echo 0) | bc numbers. 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 • [ $(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 • printf "%'d\n" 1234 thousands grouping appropriate to locale Use locale thousands • BLOCK_SIZE=\'1 ls -l grouping in ls.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages8 Page
-
File Size-