Linux Notes

bash for files

for f in $FILES
  echo "Processing $f file..."
  # take action on each file. $f store current file name
  cat $f

SSH Keys

ssh-keygen -t rsa
ssh-copy-id <username>@<host>
cat ~/.ssh/ | ssh user@host 'cat >> .ssh/authorized_keys'

Network Traffic Monitor

netstat -tpe

Alarm Clock

sleep 8h && audacious /path/to/mp3file.mp3

Count Files

ls -1 | wc -l

Labeling Partitions

sudo e2label /dev/sdb3 mylabel


tar -cvzf file.tgz directory
tar -xvzf file.tgz
or for better compression:
tar -cvjf file.tbz directory
tar -xvjf file.tbz

Using apt to install pacakages

sudo apt-get install <package>
sudo apt-get remove <package>  (does not rm dependent packages)
sudo apt-get autoremove (removes dependencies)
apt-cache search <package>
apt-cache show <package>

Installing tex packages

Go to to download packages move packages to directory:
/usr/local/share/texmf/tex/latex/<package name>/
update package list:
sudo mktexlsr
package sty files to get:

Compiling latex

pdflatex <file>.tex

Mounting an iso

sudo mkdir /media/iso
sudo modprobe loop
sudo mount file.iso /media/iso/ -t iso9660 -o loop

Creating an iso from a CD

sudo umount /dev/cdrom; dd if=/dev/cdrom of=file.iso bs=1024

vim find and replace

:%s/findThis/replaceWithThis/gc  (confirm each)


find <path> -name <fileName>


nohup &
tail -f nohup.out

Installing deb packages

sudo dpkg -i <package>.deb

Shutdown remotely

sudo shutdown now
or to restart:
sudo shutdown -r now


lpr -P <printer_name> <document>
list print jobs:
lpq -P <printer_name>
cancel print job:
lprm -P <printer_name> <job_id>
printers at CERN:

List all files

find . -type f -follow -print > filelist.txt

  # --- print second column 
  ls -al | awk '{print $2}'
  ls -al | pru 'split(" ")[1]'
  ls -al | scc -n 'F(1)'

  # --- count and average of all integers on second position
  ls -al | awk '{ s += $2; } END {print "average" ,int(s/NR);print "count ",int(NR)}'
  ls -al | pru 'split(" ")[1]' '"average #{mean(&:to_i)}\ncount #{size}"'
  ls -al | scc 'int c=0; WRL c+=F(1); FMT("average %s\ncount %s") %(c/NR) %NR'

  # --- count lines
  ls -al | wc -l  
  ls -al | pru -r 'size'
  ls -al | scc 'WRL;NR+1'

  # -- replace a 5 with five
  ls -al | sed 's/5/five/'
  ls -al | pru 'gsub(/5/,"five")'
  ls -al | scc -n 'RR(line,R("5"),"five")'

  # every second line
  ls -al | pru 'i % 2 == 0'
  ls -al | scc -n 'NR % 2 ? line : ""'

  # sum up df's used-space column
  df | awk '{n+=$3;};  END{print n}'
  df | pru  ?????
  df | scc 'int n=0; WRL n+=F(2); n'

-- RyanReece - 18 May 2008

Edit | Attach | Watch | Print version | History: r12 < r11 < r10 < r9 < r8 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r12 - 2015-12-30 - RyanReece
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Sandbox All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback