Actions

Difference between revisions of "Linux"

From ACL@NCU

Line 75: Line 75:
#note that there shouldn't be a space between the equal sign and the string value
#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"
#otherwise tcsh would complain "variable name should start with a letter"
</pre>
*[http://www.twbsd.org/cht/book/ch24.htm performing algebra]
<pre>
set a = `expr 2 + 3`
</pre>
</pre>



Revision as of 20:41, 4 February 2015

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


  • 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 *

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

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
address 10.0.0.100
netmask 255.255.255.0
gateway 10.0.0.1

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 


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

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>

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

VirtualBox

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

Mediawiki

  1. Remember to change the mode of the images folder to 557 in order for the extension to work.

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.

Solution:

sudo chown user.usergroup ~/.Xauthority

example
sudo chown fred.fred ~/.Xauthority

#showing available modes (the active one with *)
xrandr

#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