1
score
|
Insert lines from one text file to another one$ sed -re ':a;Rfile1' -e 'x;s/^/./;/.{10}/!{x;ba};s/.*//;x' file2 |
1
score
|
Send a file by email as attachment$ uuencode /var/log/messages messages.txt | mailx -s "/var/log/messages on $HOST" me@example.com |
1
score
|
Get only the latest version of a file from across mutiple directories.$ find . -name 'filename' | xargs -r ls -tc | head -n1 |
1
score
|
Sort and remove duplicate lines from two (or more files). Display only uniq lines from files.$ sort file1 file2 | uniq -u |
1
score
|
Get load average in a more parse-able format$ python -c 'import os; print os.getloadavg()[0]' |
1
score
|
Function to extract columns from an input stream$ col() { awk '{print $('$(echo $* | sed -e s/-/NF-/g -e 's/ /),$(/g')')}'; } |
1
score
|
Define an own watch(1)-like function$ watch () { interrupted=false; trap "interrupted=true" INT; while ! $interrupted; do $*; sleep 1 || interrupted=true; done; } |
1
score
|
Remove offending key from known_hosts file with one swift move$ vi +18d +wq ~/.ssh/known_hosts |
1
score
|
Replace the header of all files found.$ find . -type f -name '*.html' -exec sed -i -e '1r common_header' -e '1,/STRING/d' {} \; |
1
score
|
Redirect stdout to a file you don't have write permission on$ echo hello | sudo tee -a /path/to/file |
1
score
|
`tail -f` a file until text is seen$ tail -f /path/to/file.log | sed '/^Finished: SUCCESS$/ q' |
1
score
|
Recording SSH sessions$ ssh -l USER HOST | tee -a /path/to/file |
1
score
|
Record audio from microphone or sound input from the console$ sox -t ossdsp -w -s -r 44100 -c 2 /dev/dsp -t raw - | lame -x -m s - File.mp3 |
1
score
|
Use vim to pretty-print code with syntax highlighting$ vim +'hardcopy > output.ps' +q style.css |
1
score
|
Log and verify files received via FTP$ for i in $(cat /var/log/vsftpd.log | grep $DATE_TIME | grep UPLOAD | grep OK); do ls /FTP/HOME/$i >> /dev/null 2> \&1; if \[ $? = 0 \]; then echo "$i" >> $FILES_OK_UPLOADS.log; else echo "$DATE ERROR: File $i not found" >> $FTP_FILES_NOTOK_$DATE_TIME.log; fi; done |
1
score
|
Edit the Gimp launcher file to disable the splash screen$ printf '%s\n' ',s/^Exec=[^ ]*/& -s/' w q | ed /usr/share/applications/gimp.desktop |
1
score
|
Faster disk imaging with dd$ dd if=/dev/sda bs=$(hdparm -i /dev/sda | grep BuffSize | cut -d ' ' -f 3 | tr [:lower:] [:upper:] | tr -d BUFFSIZE=,) conv=noerror | dd of=image.dd conv=noerror |
1
score
|
Convert a decimal number to octal, hexadecimal, binary, or anything$ bc <<< 'obase=2;1234' |
1
score
|
Remove carriage return '\r' character in many files, without looping and intermediary files$ vi +'bufdo set ff=unix' +'bufdo %s/^M$//' +q file1 file2 file3 |
1
score
|
Sort and remove duplicate lines in a file in one step without intermediary files$ vi +'%!sort | uniq' +wq file.txt |
1
score
|
Show files containing "foo" and "bar" and "baz"$ grep -l 'baz' $(grep -l 'bar' $(grep -lr 'foo' *) ) |
1
score
|
Find in files, recursively$ grep -rn 'nameserver' /etc 2>/dev/null |
1
score
|
Calculate the total disk space used by a list of files or directories$ du -cshx ./a ./b |
1
score
|
Create a compressed tar file that rsync will transfer efficiently$ GZIP='--rsyncable' tar cvzf bobsbackup.tar.gz /home/bob |
1
score
|
Cut select pages from a pdf file and create a new file from those pages.$ ps2pdf -dFirstPage=3 -dLastPage=10 input.pdf output.pdf |