User:Alvations/unix cheatsheet

Just a collection of one-liners that is nifty in unix/ubuntu

Extracting line(s) from a textfile
$ sed '2,4!d' somefile.txt

Grep with line number
$ grep -in "whatever" myfile.txt

Count number of lines in textfile
$ wc -l my_text.txt

Split textfiles by number of lines
$ split -l 2000 filename.txt

Check number of files in directory
$ ls -1 targetdir | wc -l

Remove empty lines from file
$ sed '/^$/d' input.txt > output.txt $ grep -v '^$' input.txt > output.txt

Using "\n" with echo
$ echo -e "foo bar\nhello world"

Check Ubuntu's version
$ lsb_release -a or $ cat /etc/issue

Monitor memory usage (Ubuntu)
$ watch -n 5 free -m

Free cache/memory
$ sudo sysctl -w vm.drop_caches=3 $ sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

Create sudo users in terminal
The first command creates a user, the second command adds the new user to the sudo group $ sudo adduser  $ sudo adduser  sudo

Change user password
$ sudo passwd

Check free space
$ df -h

Check CPU usage
$ top

Monitor all
$ glances # see http://askubuntu.com/questions/293426/system-monitoring-tools-for-ubuntu

No. of files in directory
$ ls -1 thisdirectory | wc -l

Install OpenSSH on Ubuntu
$ sudo apt-get install openssh-server openssh-client $ ssh localhost

Install easy_install and/or pip
$ sudo apt-get install python-setuptools $ sudo easy_install pip

Install scipy, nltk, gensim stack
$ sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose $ sudo pip install -U pyyaml nltk $ sudo easy_install -U gensim $ sudo easy_install gensim[distributed] $ sudo easy_install Pyro4

tar
$ tar -zxvf filename.tar.gz $ tar -zxvf filename.tgz $ tar -jxvf filename.tar.bz2

gzip
$ gunzip file.gz $ gzip -d file.gz

Adjust brightness
$ xrandr --output LVDS1 --brightness 0.8

Volume controls
$ amixer -c 0 set Master playback 0% mute $ amixer -c 0 set Master playback 50% unmute $ amixer set Master 0 $ amixer set Master 100 $ pactl set-sink-mute 0 0 $ pactl set-sink-mute 1 0

Finding Serial Number
$ dmidecode -s system-serial-number

Using nohup with pipe
$ nohup sh -c "command1 | command2"

Set deluge as default magnet handler
$ sudo apt-get install deluge $ gvfs-mime --set x-scheme-handler/magnet deluge.desktop

Installation list when things screw up (from fresh Ubuntu 14.04)
http://howtoubuntu.org/things-to-do-after-installing-ubuntu-14-04-trusty-tahr

http://ubuntuhandbook.org/index.php/2014/06/install-latest-eclipse-ubuntu-14-04/

http://ksearch.wordpress.com/2014/05/15/disable-unity-animations/

http://openjdk.java.net/install/

http://bendemott.blogspot.de/2013/11/installing-pylucene-4-451.html

https://fixubuntu.com/

NLP libraries
http://scikit-learn.org/stable/install.html

http://www.nltk.org/install.html

http://www.sussex.ac.uk/Users/davidw/courses/nle/SussexNLTK-API/

https://scikit-learn-laboratory.readthedocs.org/en/latest/index.html

http://alias-i.com/lingpipe/

https://uima.apache.org/doc-uima-examples.html

My stuff
$ for i in $(find ../parallel/ -name "*.de" -type f); do x=${i:0:-2}; e=$x"en"; cat $e >>train-de_en.en; cat $i >> train-de_en.de ; done &

$ for i in $(ls corpus.org/*.fi); do cat $i | perl ~/moses/scripts/tokenizer/tokenizer.perl -l fi > corpus.tok/${i:11}; done

Remove ads from unity
$ gsettings set com.canonical.Unity.Lenses disabled-scopes "['more_suggestions-amazon.scope', 'more_suggestions-u1ms.scope', 'more_suggestions-ebay.scope', 'more_suggestions-ubuntushop.scope', 'more_suggestions-skimlinks.scope']"

Category:Ubuntu (operating system) Category:Linux Category:Cheatsheet