Recent Notes
Displaying keyword search results 1 - 10
Created by magnum on October 22, 2012 20:03:05
Last update: October 22, 2012 20:03:05
First, the test command that sleeps random number of seconds ( sleeper.sh ):
#!/bin/bash
stime=$[$RANDOM % 20]
sleep $sti...
As comparison, synchronous pipe code:
#include <sys/wait.h>
#include <stdio.h>
#in...
Asynchronous pipe code:
#include <sys/wait.h>
#include <stdio.h>
#in...
Created by voodoo on May 22, 2012 12:26:41
Last update: September 12, 2012 19:09:22
My program core dumped but there was no core file. The problem was that the core file size was 0:
$ ulimit -a
core file size (blocks, -c...
Use ulimit to enable it:
$ sudo bash
# ulimit -c unlimited
Actually, you can update the limit for yourself without root. You can put the ulimit command in .bashrc .
Created by magnum on September 11, 2012 11:59:43
Last update: September 11, 2012 11:59:43
Exerpt from bash documentation. HISTORY EXPANSION The bash shell supports a history expansion feature that is similar to the history expansion in csh. This feature is enabled by default for interactive shells, and can be disabled using the +H option to the set builtin command. Non-interactive shells do not perform history expansion by default. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly. History expansion is performed immediately after a complete line is read, before the shell breaks it into words. It takes place in two parts. The first is to determine which line from the history...
Created by Dr. Xi on February 07, 2012 15:40:11
Last update: February 07, 2012 15:40:11
An alias defined in .profile does not work when you open a bash window from the desktop. Simply put, alias should be put in .bashrc ; PATH should be put in .profile . These are the facts: .profile is executed by the login shell, i.e., when you login. .bashrc is executed whenever a bash shell is opened - login or non-login. When you open a new bash window from the desktop, a non-login shell is created, it will execute .bashrc , not .profile . When you ssh to a remote system interactively, a login shell is created. When you ssh to a remote system and run a command directly, a non-login shell is created. PATH modifications should be put in .profile since it is usually...
Created by voodoo on December 08, 2011 08:52:40
Last update: December 08, 2011 08:52:40
I don't know if there's a fool proof way to find out which Linux distro you are running on, but here are some ways you can try:
cat /proc/version
cat /etc/issue
cat /etc/*release
lsb_release -a
Results on Ubuntu 11.10 oneiric:
$ cat /proc/version
Linux version 3.0.0-13-gene...
Results on Red Hat Enterprise Server:
$ cat /proc/version
Linux version 2.6.18-128.1....
Created by woolf on September 08, 2011 11:19:52
Last update: September 08, 2011 11:19:52
To check a command exists on PATH:
Use the return code of which :
which some_command &>/dev/null
[ $? -eq 0 ] || ...
For bash, use type -P :
type -P some_command &>/dev/null && echo "ome_comm...
or
check_path() {
if ! type -P $1 &> /dev/...
Created by magnum on June 23, 2011 13:01:49
Last update: June 23, 2011 13:01:49
Job control refers to the ability to selectively stop (suspend) the execution of processes and continue (resume) their execution at a later point. A user typically employs this facility via an interactive interface supplied jointly by the operating system kernel's terminal driver and bash. If the operating system on which bash is running supports job control, bash contains facilities to use it. Typing the suspend character (typically ^Z , Control-Z) while a process is running causes that process to be stopped and returns control to bash. A ^Z takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded. Typing the delayed suspend character (typically ^Y , Control-Y) causes the process to be stopped when it attempts to...
Created by woolf on June 18, 2011 21:21:56
Last update: June 18, 2011 21:34:56
I haven't test these. They are collected for reference only. With mencoder, from HOWTO: Convert and write AVCHD (.mts) to DVD with Linux
mencoder -oac copy -ovc lavc -of mpeg -mpegopts fo... With HandBrake (GUI): Transcoding AVHD (Cannon HF100 .mts) into a usable open format (MKV w/ FFMPEG) With ffmpeg & WinFF (GUI and command line): How to convert Canon .mts video files to other formats in Ubuntu With mencoder, from Transcoding AVCHD (.mts or .m2ts) files using mencoder on Linux (no deinterlacing): # 1 pass mencoder $file -o ./$file.avi -oac cop... With ffmpeg, from Stuttering playback of canon MTS files #!/bin/bash for i in "$i"*.MTS; do name="${i%.*... #!/bin/bash for i in "$i"*.MTS; do name="${i%.*... With mencoder, from [MEncoder-users] problems with AVCHD (.mts) + Deinterlace...
Created by magnum on May 06, 2011 12:26:14
Last update: May 06, 2011 12:26:14
The bash environment variable PROMPT_COMMAND contains a regular bash command that is executed just before the command prompt is displayed.
For example:
$ export PROMPT_COMMAND=a
bash: a: command not ...
The command a is not valid so you get the error message every time you hit enter.
Echo something before $PS1 :
$ export PROMPT_COMMAND='echo -n Hi!'
Hi!$
...
PROMPT_COMMAND is regularly used to change the xterm window title. You may find this in /etc/bashrc :
case $TERM in
xterm*)
if [ -...
Created by voodoo on July 30, 2010 14:53:33
Last update: July 30, 2010 14:54:52
The -d switch for cURL sends HTTP POST with data from the command line. To verify the data being posted, this is a CGI script that echos the data back:
#!C:/perl/bin/perl.exe ## ## echo -- echos ... Examples: POST data from command line: C:\>curl -d input1=value1^&input1=value2 http://lo... POST data from stdin (with @ before the - symbol): C:\>curl -d @- http://localhost/cgi-bin/echo.pl ... POST data from a file (with @ before the - symbol and input redirect): C:\tmp>cat data.txt abcd 1234 xyz ... For some reason, @ with file name didn't work as expected: C:\tmp>curl -d @data.txt http://localhost/cgi-bin/... One thing to notice is that cURL removes the new line characters when posting (thus the echo back is only one line instead of three). This can...