Revision as of 10:08, 27 November 2018 by Aclexp (talk | contribs) (→‎Setting Chinese Dayi Input Method)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Useful tcsh and python commands


  • 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
comment line #1
comment line #2
comment line #3
comment line #final
  • 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]
  • selectively filter contents of stdout

  • selectively exclude contents of stdout
grep -v PATTERN

  • 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 precise/

in your /etc/apt/sources.list file, replacing <my.favorite.cran.mirror> by the actual URL of your favorite CRAN mirror. See 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>.*' 

  • set variables
set varname=<string>
#note that there shouldn't be a space between the equal sign and the string value
#otherwise tcsh would complain "variable name should start with a letter"
set a = `expr 2 + 3`

file system

  • Determine file creating and modification times [4]
stat *
  • tell the total size of selected folders/files
du -sh --total <folder regex>

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
  • restart network GUI (allow the top-left icon of network to show up)
sudo service network-manager restart

To configure your system to use a static IP address assignment, add the static method to the inet address family statement for the appropriate interface in the file /etc/network/interfaces. The example below assumes you are configuring your first Ethernet interface identified as eth0. Change the address, netmask, and gateway values to meet the requirements of your network.

auto eth0
iface eth0 inet static

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 precise main 
deb-src precise main 

  • install python lxml on ubuntu (quite tricky if attempted from building source)
apt-get build-dep python-lxml
pip install lxml

System Configuration

  • set environmental varialbes in .tcshrc (or the like)
setenv VARNAME values
  • reset root password
sudo passwd root
  • hardware information
  • tell current user
  • 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

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


See what error message is spit out. For example:

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

This is a problem of not finding, 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>

Setting up the Desktop

for resolving an issue in X11 forwarding via SSH

I am trying to run an OpenGL+GLUT program over SSH with X forwarding. 
The program provides the following errors, then seg faults.

Xlib: extension "NV-GLX" missing on display "localhost:10.0".

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 ' '


  • How to add a virtual disk (vdi file) to an existing guest Linux system?
1. Create the vdi image
2. Add it to the guest system via the storage option. 
3. In the guest system, use gparted or fdisk to add partition to it
4. either it is automatically mounted, or use mount command to mount it. 

This link covers more options than enabling the guest to access the internet, including:
1. Connection from the laptop to the Virtual Boxes.
2. Simulating a private network between Virtual Boxes.
3. From Virtual Box to internet.

System Maintenance

  • shutdown system after a certain amount of time
nohup sudo shutdown -h +<m> &
  • view all processes
ps aux | less
#Change the Ubuntu code name from Raring Ringtail to Trusty Tahr
sudo sed -i 's/raring/trusty/g' /etc/apt/sources.list

# Disable third party PPAs (optional, see note)
cd /etc/apt/sources.list.d
sudo rename 's/(.*)/$1.bak/' *
sudo find . -type f -name "*" -print | xargs sed -i 's/raring/trusty/g'

# Update the repositories and upgrade
sudo apt-get update && sudo apt-get dist-upgrade

#Update grub and initramfs
sudo update-grub && sudo update-initramfs -u


  1. Remember to change the mode of the images folder to 557 in order for the extension to work.
  2. Problem with upload wizard file extension
Since I upgraded to MW 1.21 I have a problem with UW (UploadWizard) regarding file extensions. For instance, I try to upload a .ogg file, UW says that files with file extension .ogg is not allowed. When I try it on the normal upload, the file uploads. This UW problem happens with all allowed file extensions.

[solution]I had the same issue. For me, it was caused by $wgFileExtensions being under the require_once("$IP/extensions/UploadWizard/UploadWizard.php'); in my LocalSettings.php. I moved it above the UploadWizard and it fixed the problem. If anyone can confirm that this is necessary, it should be added to the instructions/requirements. --MikeDarling (talk) 19:34, 19 January 2015 (UTC)

Reordering the wgFileExtensions before the require_once fixed this issue for us too. --Mathieu.planche (talk) 16:06, 28 January 2015 (UTC)

Setting Chinese Dayi Input Method

  1. install gcin (sudo apt-get install gcin)
  2. Download
  3. replace /usr/share/gcin/table/gtab.list with the gtab.list in
  4. remove ~/.gcin/gtab.list, logout, and login
  5. make sure that gcin-anthy is installed (sudo apt-get install gcin-anthy)

Frequently Encountered Problems (FEPs)

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.


sudo chown user.usergroup ~/.Xauthority

sudo chown fred.fred ~/.Xauthority

#showing available modes (the active one with *)

#setting the desired mode
xrandr --output default --mode 1680x1050

The mode lines can be generated with the following syntax

cvt <h-resolution> <v-resolution> [refresh]

sudo apt-get install dkms
sudo apt-get install gnome-system-tools