Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, May 21, 2013

Edit history command line in Linux

Sometime I use the following command to search. When I need to search a different pattern later, I used "!find" to run the command, cancel it and modify the last command. That is not a decent method. Two solutions: type: The command line will display but will not execute, then use arrow UP and modify it. Type: then type "find" to localize the command line, and use arrow UP to edit. -- Sometimes you want to replace one parameter with another: Or you know the history number:

Wednesday, April 24, 2013

Find command in Linux

Usually I only use a couple of them, but it's good to list for looking up

Monday, February 04, 2013

touch command

The touch command is the easiest way to create new, empty files.

touch filename1 filename2

Wednesday, November 28, 2012

ubuntu problem: running on low-graphics mode

try to reinstall the desktop:

Monday, November 19, 2012

setup svn on my linux machine

1. install apache sudo apt-get install libapache2-svn apache2
2. enable SSL sudo a2enmod ssl sudo gedit /etc/apache2/ports.conf
3. generate SSL certification 4. create virtual host In svnserver
5. enable site
6. create svn repos
Choose System > Administration > Users and Groups from your Ubuntu menu.
Click the 'Manage Groups' button.
Click the 'Add' button. Name the group 'subversion'
Add yourself and www-data (the Apache user) as users to this group (Note: in order to see www-data you may need to see FixShowAllUsers)
Click 'OK', then click 'Close' twice to commit your changes and exit the app.
7. add users
8. test with

some contents are from: https://help.ubuntu.com/community/Subversion

Friday, May 20, 2011

Monday, March 08, 2010

Priority inversion, priority inheritance, and priority ceiling

Remember polycom?

Priority inversion: a high priority task is indirectly preempted by a medium priority task. (a medium priority task preempts a low priority task, the low priority task is using a shared resource on which the high priority task is pending). The process from wiki is:
  • There are 3 tasks A, B, and C, with priority from high to low. A and C share the resource
  • C successfully locks the resource
  • A attempts to acquire resource, being blocked and wait for C to release resource
  • B became runnable before C release resource
  • Now you don't know when C can release resource, and A is still blocked
  • reversion happens: B is running and A is not
Solution 1: Priority inheritance - make the low priority task inherit the priority of any high task pending on a resource they share. This priority change should take place as soon as the high priority task begins to pend. It should end when resource is released.

Solution 2: Priority ceiling - each resource is assigned a priority ceiling, which equals to the highest priority of an task which may lock the resource. Once a task finishes with the resource, its priority returns to normal.

The link is a good read for this topic.

Difference between mutex and binary semaphore

I have some notes about semaphore at former post (especially at the end of that post).
Now what is the different between mutex and binary semaphore?
  • If mutex is locked by some thread, only that thread can unlock it. The binary semaphore can be unlocked by any other threads. For instance, if thread A locks the mutex and returns before release the lock, then you are in a deadlock and cannot recover it (in C). With semaphore it is a bit different. You can still release the lock even the thread A leaves early.
  • You can use recursive mutex (although you may not want to use it). This feature is not available in semaphore.
  • Priority inversion (see last post) is possible with mutex, but not applicable in binary semaphore ( I think is similar with the 1st listed item).
When using a binary semaphore to serialize the access to resource, you have to initialize it with the value 1, which means the resource is available.

Synchronization

In common use, it means making two things happen at the same time.
It multithreading programming, it refers to relationships among threads: any number of threads, and any kind of relationship (before, after, during). Such like:
Serialization - thread A must happen before thread B.
Mutual exclusion - thread A and B must not happen at the same time.

Monday, January 25, 2010

Cut, copy, and paste block in vi

cut: dd or 4dd, then paste with p or P
copy: yy or 4yy, then past with p

if you know the start line number and end line number (Ctrl+g):
:10,25y
then p to paste. (this is copy-paste, replace y with d to cut-paste)

or set marks in both start and end lines with ma, mb
:'a,'by
then p to paste

Thursday, November 05, 2009

Use wired connection in ubuntu vmware

  1. disconnect wireless
  2. in vmware ‘network adapter’, choose ‘Bridged’
  3. in ubuntu ‘System Preferences-Netwrok connections’, Edit ‘Auto eth0’ and apply…

Wednesday, October 28, 2009

Get a short prompt in linux terminal

The default ubuntu linux prompt shows the all the directories:
user@user~desktop:~/home/user/work/project$
To make it shorter, add following two lines:


PS1="[\W]\\$ "
PS2="> "

to .bashrc file. Don't forget to 'source ~/.bashrc'

Tuesday, October 27, 2009

Search and install packages in ubuntu

aptitude search package
dpkg -l | grep package
dpkg-query --show package
apt-cache search package (this one may return lots of results)

and the easy one (GUI):
synaptic

apt-get install package

Friday, October 23, 2009

save file in vi when you forget 'sudo'

:w !sudo tee %

This issue happened to me a lot of times.
After you made some changes in vi and want to save, suddenly you find you don't have the permission~.

Others:
> file.txt
empty the file (or create a new empty file)

Alt-.
place the argument of most recent command (keep pressing for older ones)

-- from commandlinefu.com

Wednesday, October 21, 2009

Some keyboard shortcuts in linux command line

Some are the same with emacs:

ctrl-a move to beginning/end of the line
ctrl-e  
ctrl-u cut from cursor to beginning/end
ctrl-k  
ctrl-w cut from cursor to beginning/end of word
ctrl-y yank
ctrl-] n move to next/previous character ‘n’
ctrl-alt-] n  
ctrl-x ctrl u undo last change
alt-r undo current line
ctrl-n next/previous command
ctrl-p  
ctrl-L clean screen
ctrl-r incremental/non- history search
alt-p  

Friday, October 09, 2009

Basic SVN commands

svn help [ … ]
svn co http://svn.abc.org/repos/svn/trunk /home/usr
svn st
svn st –v (verbose, show details)
svn diff
svn diff abc.c
svn diff > patchfile (save output to a file)
svn diff | vi -
svn diff -r 2269:2210 main.c
vi <(svn diff)
svn up
svn ci
svn ci abc.c –m “fixed xxx bug”
svn add abc.c (then you need to check in)
svn revert
svn log
svn list (display all files)
svn cat –r 2165 abc.c > abc.c.2165 (show an old version and save it)

Wednesday, October 07, 2009

Check current Linux version

cat /etc/*release
cat /etc/*version
cat /etc/issue
cat /proc/version
uname -a
... and check memory, CPU
cat /proc/meminfo
cat /proc/cpuinfo

check how much hard disk:
df -h

Tuesday, October 06, 2009

Access folders in vmware Linux from Windows machine

In vmware Linux machine (using bridge network connection):
Install samba (ubuntu example):
sudo apt-get install samba

Then create a user name and password for the samba server:

sudo smbpasswd -a your_user_name

Share folder: right-click the folder and choose “sharing options”, give a share name like “usr_ubuntu”.
In Windows machine:

File explorer->Tools->Map Network Driver: folder is “\\10.10.1.1\usr_ubuntu”, then input your_user_name and password

[update: 2/5/2013] you don't need the step of "Share folder: right-click...."

Monday, October 05, 2009

set up tftp

I got some troubles when setting up the tftp server, here is a note:
install packages: (if in ubuntu)

sudo apt-get install xinetd tftpd tftp

create file: /etc/xinetd.d/tftp with following lines inside:

service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -p /tftpboot
per_source = 11
cps = 100 2
flags = IPv4
}

Use TAB space before every line. In the line ‘server-args = –p /tftpboot’, it works with Fedora. When using ubuntu, you have to remove ‘-p’ from my experience.

create a directory
named ‘/tftpboot’
start tftp with:

sudo /etc/init.d/xinetd restart

Test from local machine, if you have a abc.txt file in your current directory and an xxx.txt file in your /tftpboot directory:

tftp 10.10.1.1
put abc.txt
get xxx.txt

try the same test from another machine.
If tftp is still not working, try to disable "Firewall" and "SELinux" (use command 'getenforce' to check current status of SELinux).

Wednesday, September 23, 2009

search for inside all files in current directory with grep

grep -RnisI <pattern> *
-R: recurse to subdir
-n: show line number
-i: ignore case
-s: suppress “doesn’t exist” and “cannot read” message
-I: ignore binary files

another one:

find . -type f | xargs grep -RnisI <pattern>

--[update: 11/3/09]
grep --color -RnisIH 'pattern' .
-H: show file name
--color: highlight the word (or use --color=auto, --color=always)

find . -type f -name '*.c' -print0 | xargs -0 --color -RnisIH 'search_pattern'

--if we want to find all 'oldstring' and replace with 'newstring':
grep -Rl 'oldstring' . | sed -i -e 's/oldstring/newstring/'
-l: only list the file name with containing matches.
Refer former post