Actions

Linux

From ACL@NCU

Revision as of 09:43, 3 April 2014 by Aclexp (talk | contribs)

Useful tcsh and python commands

tcsh

  • Find files

with defined stem pattern under multiple different folder

find */*/*anat+tlrc.*
  • find files with a suffix recursively under subdirectories
find . -name \*.mgz -print
  • delete or copy filenames from a "pattern" search
rm `find */*/*anat+tlrc.*`
  • comment multiple lines
:<<LABEL
comment line #1
comment line #2
comment line #3
...
comment line #final
LABEL
  • Extract a substring [1]
  • Split a string[2]

The awk function split(,,sep) splits a string into an awk array using the delimiter sep.

set time = 12:34:56
set hr = `echo $time | awk '{split($0,a,":"); print a[1]}'` # = 12
set sec = `echo $time | awk '{split($0,a,":"); print a[3]}'` # = 56
  • Translation between bash and tcsh [3]


  • Install R

To obtain the latest R packages, add an entry like

  deb http://<my.favorite.cran.mirror>/bin/linux/ubuntu precise/

which for ubuntu 12.04 in Taiwan would be:

  
deb http://cran.csie.ntu.edu.tw/bin/linux/ubuntu precise/

in your /etc/apt/sources.list file, replacing <my.favorite.cran.mirror> by the actual URL of your favorite CRAN mirror. See http://cran.r-project.org/mirrors.html for the list of CRAN mirrors. To install the complete R system, use

  sudo apt-get update
  sudo apt-get install r-base
alias <name> <actual commands !:1> #take the first argument


  • list files without a string
ls -I '<pattern>.*' 

file system

  • Determine file creating and modification times [4]
stat *

Network Connection

  • Blocking a port [5]
sudo ufw deny 80
  • list all current ufw rules
sudo ufw status numbered

other ufw usage [6]

  • Scanning available ports
nmap -PS <IP address>
  • Scanning all available IPs in subnet
nmap -sP 192.168.1.0/24
  • restart network GUI (allow the top-left icon of network to show up)
sudo service network-manager restart

Install new packages

sudo apt-get install python-pip python-dev build-essential 
sudo pip install --upgrade pip 
sudo pip install --upgrade virtualenv 
  • apt-cache: search for the name of library package with keyword
apt-cache search libpcre
  • add software sources to sources.list (in /etc/apt/sources.list)
#using octave as an example
deb http://ppa.launchpad.net/octave/stable/ubuntu precise main 
deb-src http://ppa.launchpad.net/octave/stable/ubuntu precise main 

System Configuration

env
  • set environmental varialbes in .tcshrc (or the like)
setenv VARNAME values
  • reset root password
sudo passwd root
  • hardware information
hwinfo
  • tell current user
id
  • tell the current shell
echo $SHELL
edit the /etc/environments file

First, boot into ubuntu with usb or cd images; then install boot-repair as instructed below:

sudo add-apt-repository ppa:yannubuntu/boot-repair && sudo apt-get update
sudo apt-get install -y boot-repair && (boot-repair &)
  • afni & R problem: Fail to load R_io.so

under where the directory where R is installed, start R and type:

dyn.load("R_io.so")

See what error message is spit out. For example:

> dyn.load("R_io.so")
Error in dyn.load("R_io.so") : 
  unable to load shared object '/usr/local/abin/R_io.so':
  libjpeg.so.62: cannot open shared object file: No such file or directory

This is a problem of not finding libjpeg.so.62, which can be resolved by:

sudo apt-get install libjpeg62
sudo apt-get install libjpeg62:i386
  • Setup the default folder for sftp login:
sudo usermod -d [desired default path] username
  • Change number of workspace
gconftool-2 -s /apps/metacity/general/num_workspaces --type int <n>

File I/O

sed -i 's/original/new/g' file.txt
  • read out contents from multiple files and remove certain strings
find . -name "blur_est.*.1D" | xargs tail -n 1 | grep -v == | tr -s '\n'
  • extract the first 3 column(s) from a text file
cut -f 1,2,3 -d ' '

VirtualBox

Frequent Problems

Situation: I can't seem to open my desktop anymore. After powering on my 64 bit ubuntu asus laptop I see the login screen and I can reach a desktop as guest (no password). However, using my normal user name and password brings me back to that same login page I just entered my password in.

Solution:

sudo chown user.usergroup ~/.Xauthority

example
sudo chown fred.fred ~/.Xauthority