Difference between revisions of "Linux"
From ACL@NCU
(26 intermediate revisions by the same user not shown) | |||
Line 40: | Line 40: | ||
* Translation between bash and tcsh [http://joelinoff.com/blog/?page_id=235] | * Translation between bash and tcsh [http://joelinoff.com/blog/?page_id=235] | ||
* selectively filter contents of stdout | |||
<pre> | |||
grep PATTERN | |||
</pre> | |||
* selectively exclude contents of stdout | |||
<pre> | |||
grep -v PATTERN | |||
</pre> | |||
Line 67: | Line 78: | ||
<pre> | <pre> | ||
ls -I '<pattern>.*' | ls -I '<pattern>.*' | ||
</pre> | |||
*set variables | |||
<pre> | |||
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" | |||
</pre> | |||
*[http://www.twbsd.org/cht/book/ch24.htm performing algebra] | |||
<pre> | |||
set a = `expr 2 + 3` | |||
</pre> | </pre> | ||
Line 74: | Line 98: | ||
<pre> | <pre> | ||
stat * | stat * | ||
</pre> | |||
*tell the total size of selected folders/files | |||
<pre> | |||
du -sh --total <folder regex> | |||
</pre> | </pre> | ||
Line 112: | Line 141: | ||
gateway 10.0.0.1 | gateway 10.0.0.1 | ||
</pre> | </pre> | ||
*[http://tnrc.ncku.edu.tw/course/93/fedora_core2/page15/p15.htm setting up rsync server#1] | |||
*[https://help.ubuntu.com/community/rsync setting up rsync server#2] | |||
= Install new packages = | = Install new packages = | ||
Line 216: | Line 248: | ||
*[http://dragli.blogspot.tw/2008/01/sftpreceived-message-too-long-xxxxxx.html sftp login message too long problem] | *[http://dragli.blogspot.tw/2008/01/sftpreceived-message-too-long-xxxxxx.html sftp login message too long problem] | ||
==Setting up the Desktop== | |||
*[http://blog.lifebloodnetworks.com/?p=1253 switch from gnome to mate desktop] | |||
*[https://wiki.ubuntu.com/LightDM LightDm display manager ] | |||
*[http://www.webupd8.org/2014/04/how-to-install-and-tweak-gnome.html install Gnome flashback on Ubuntu 14.04] | |||
==for resolving an issue in X11 forwarding via SSH== | |||
*[http://stackoverflow.com/questions/23260349/opengl-glut-over-ssh-seg-faulting SSH X forwarding error] | |||
<pre> | |||
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". | |||
</pre> | |||
*[http://dri.freedesktop.org/wiki/Building/ Building the DRI with X.org and Mesa] | |||
=File I/O= | =File I/O= | ||
Line 234: | Line 282: | ||
=VirtualBox= | =VirtualBox= | ||
*[http://askubuntu.com/questions/140081/virtualbox-doesnt-recognize- | *[http://askubuntu.com/questions/140081/virtualbox-doesnt-recognize-usb Virtualbox cannot find any usb devices (check on solution 18 to change vboxuser's privilege in accessing usb devices )] | ||
*[http://wiredrevolution.com/virtualbox/setup-ssh-access-between-virtualbox-host-and-guest-vms Setup SSH access between VirtualBox Host and Guest VMs] | |||
*[http://stackoverflow.com/questions/5906441/how-to-ssh-to-a-virtualbox-guest-externally-through-a-host How to SSH to a VirtualBox guest externally through a host?] | |||
*[https://nsrc.org/workshops/2014/btnog/raw-attachment/wiki/Track2Agenda/ex-virtualbox-portforward-ssh.htm Port forwarding] | |||
*How to add a virtual disk (vdi file) to an existing guest Linux system? | |||
<pre> | |||
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. | |||
</pre> | |||
*[https://technology.amis.nl/2014/01/27/a-short-guide-to-networking-in-virtual-box-with-oracle-linux-inside/ Connect VirtualBox Guest to Internet] | |||
<pre> | |||
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. | |||
</pre> | |||
=System Maintenance= | =System Maintenance= | ||
Line 264: | Line 335: | ||
</pre> | </pre> | ||
==Mediawiki== | |||
#Remember to change the mode of the images folder to 557 in order for the extension to work. | |||
#Problem with upload wizard file extension | |||
{| class="wikitable" width="40%" | |||
|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= | |||
# install gcin (sudo apt-get install gcin) | |||
# Download [[:File:dragonfly.zip|dragonfly.zip]] | |||
# replace /usr/share/gcin/table/gtab.list with the gtab.list in dragonfly.zip | |||
# remove ~/.gcin/gtab.list, logout, and login | |||
# make sure that gcin-anthy is installed (sudo apt-get install gcin-anthy) | |||
=Frequently Encountered Problems (FEPs)= | =Frequently Encountered Problems (FEPs)= | ||
Line 291: | Line 382: | ||
<pre> | <pre> | ||
cvt <h-resolution> <v-resolution> [refresh] | cvt <h-resolution> <v-resolution> [refresh] | ||
</pre> | |||
*[https://wiki.archlinux.org/index.php/xrandr more on xrandr] | |||
*[http://askubuntu.com/questions/365850/virtualbox-not-seeing-any-usb-devices-in-the-usb-filters-settings Virtualbox not seeing any USB] | |||
<pre> | |||
sudo apt-get install dkms | |||
sudo apt-get install gnome-system-tools | |||
</pre> | </pre> |
Latest revision as of 09:08, 27 November 2018
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]
- selectively filter contents of stdout
grep PATTERN
- 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 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 *
- 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 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
- pip [7]
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
- 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
Mediawiki
- Remember to change the mode of the images folder to 557 in order for the extension to work.
- 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)
|
Setting Chinese Dayi Input Method
- install gcin (sudo apt-get install gcin)
- Download dragonfly.zip
- replace /usr/share/gcin/table/gtab.list with the gtab.list in dragonfly.zip
- remove ~/.gcin/gtab.list, logout, and login
- 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.
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