Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Wednesday, December 8, 2010

Linux: how to remove ^M at each line end

I got an acsii file from a Window's user. If it is a regular windows text file, then I can use a command 'dos2unix' to convert it in unix format. However, it doesn't work. I use 'less' to have a look at it, it looks like:

line1^M line2^M

. If I use emacs to view it, it looks okay like a regular file. In order to convert it to unix format, I use 'gedit' to do the conversion. A user will be reminded that you save as which format...

Saturday, October 30, 2010

linux: screen

screen is a useful command when you do not have other better choice like vnc, specially for background job running. One thing that bothered me is I cannot page up and down simply even specified by

screen -h 2000

So I have to enter copy/paste mode by: ctrl+a, esc, page down/up

Wednesday, August 25, 2010

linux: renice

from : http://linux.about.com/library/cmd/blcmdl8_renice.htm

Users other than the super-user may only alter the priority of processes they own, and can only monotonically increase their ``nice value'' within the range 0 to PRIO_MAX (20). (This prevents overriding administrative fiats.) The super-user may alter the priority of any process and set the priority to any value in the range PRIO_MIN (-20) to PRIO_MAX Useful priorities are: 20 (the affected processes will run only when nothing else in the system wants to), 0 (the ``base'' scheduling priority), anything negative (to make things go very fast).


Sunday, April 11, 2010

Linux:bash:about "delete key"

When I use "delete key" in some bash terminal, the key sends a tilde "~" instead of deleting the char that is supposed to be deleted.

Find a solution:
1. In your $HOME directory, create or edit your keyboard-mapping file, $HOME/.inputrc
2. Add one mapping line:

"\M-[3~": delete-char

3. restart your terminal

Monday, March 29, 2010

Linux: how to reduce eps file size?

I have couples of eps files which have a large size (>10 MB). Thus when using them in Latex, the output files (either pdf or ps) become very large and very slow to view. So it is necessary to reduce them first. Here provided is an approch working in Linux.

  1. Create a new open office drawing file, past your large eps file to the canvas.
  2. Add your canvas hence it has no too much extra-space (magine)
  3. Export your drawing file to a PDF file. Here you can use low compress factors etc.
  4. Use "pdftops -eps YourFile.pdf" to get your small-size eps file
Note: You can use open office drawing to export your file to an eps file directly, however, the eps file is even larger than your original one, so this exporting is not useful.

Friday, January 29, 2010

Linux: overwrite

http://www.cyberciti.biz/tips/howto-keep-file-safe-from-overwriting.html

set -o noclobber
(no overwrite)

set +o
noclobber
(overwrite)

Saturday, October 24, 2009

Linux: vnc via ssh

remind myself:
1. start 'vncserver -name X' on server computer (that you try to connect by ssh)
Note: X is a session name which is defined in the file: ~/vnc/xstartup
2. ssh -L 5902:localhost:5901 YourAccountName@YourServerID(or hostname) in one local terminal
3. vncviewer localhost:5902 in your another local terminal

Friday, August 14, 2009

linux: how to insert an img to pdf files

If you want to insert an image (like your picture, signature etc.) to an existing pdf file and you don't have acrobat professional version (that allows you to edit a pdf file within the software). Then you may be able to use the following steps with combination of different tools that are available in linux:

  1. You have an image file (say, one lovely picture) and one pdf file (Orig.pdf) to which you want to insert your picture
  2. Use "gimp" to open them. For the pdf file, you have to select which page that you want to insert your picture to, and then open the page (NOTE: in order to have good quality and same size as the original page, you may have to set "resolution" as 320. I tried 300 and 400, and realized that 320 is the proper value)
  3. In "gimp", copy your picture on the pdf page. You can use the menu "Layer -> Scale Layer ..." to scale your picture to fit your requirement.
  4. Save your modified pdf page as one "eps" file.
  5. In terminal, convert the eps file to a pdf file by "epstopdf MyPage.eps" to get MyPage.pdf
  6. Then, still in your terminal, use the tool "pdftk" to merge the 2 pdf files (Orig.pdf and MyPage.pdf):
pdftk A=Orig.pdf B=MyPage.pdf cat A1-4 B1 A6-11 output Combined.pdf
where we assume MyPage.pdf will be inserted as Page 5 while totoal pages in Orig.pdf are 11 pages.

Merge pdf files:

pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

Thursday, August 13, 2009

linux:command:pdf: a useful tool

In linux, there is a very useful PDF tool called pdftk

http://www.accesspdf.com/pdftk/

Wednesday, July 1, 2009

Linux:Shell:Bash: how to search slash or backslash by sed

It is tricky to search (or replace) signs slash '\' or backslash '/' by sed. By searching internet, I found 2 approaches:

1. Put the command line of sed to a file called my.sed:

/D\\O/p

(this will print a line containing 'D\O')

2. Another way is to use single quote instead of double one in your shell command line:

sed -n '/D\\O/ p' myfile.txt

(-n is prevent from printing)

Monday, April 20, 2009

Linux: how to change background color of xdvi

If you want to change background color or whatever other settings of one application under X windows, for example, xdvi, you could set it in your file: ~/.Xdefaults by

xdvi*background: white
xdvi*foreground: black

.

Note: your changes will be starting after you log out and in.

Thursday, April 9, 2009

Linux:shell:BASH: How to delete one line by sed

If you want to delete one line containing one word "ThisWord" by sed, then you can do in the way:

sed -i "/ThisWord/d" YourTextFile.txt

Note, here '-i' is to delete it from the original file. Without it, sed only prints the file on screen. So before using '-i', make sure you are doing correct things.

Thursday, December 18, 2008

Linux:shell:Bash: How to change color of your shell printout


You could use 'echo -e' to change your printout text and background color by some color variables. One of the easiest ways to use them is to define shell variable, for example, define those variables in your shell script:

red='\e[0;31m'
RED='\e[1;31m'

blue='\e[0;34m'

BLUE='\e[1;34m'

cyan='\e[0;36m'

CYAN='\e[1;36m'
NC='\e[0m' # No Color


. '\e[0;36m': 0's place is the color of background (0, no effect, 1, bold, 4, underline) and 36 is the text color. You also can change background colors due to color values in the color table. For example, '\e[41;34m' changes background color to red and text color to blue.

How to print?

echo -e "$red These texts are in red$NC" #you must use '-e' to enable interpretation of the backslash-escaped characters, see echo's help.

or if you want to use it in 'printf':

printf "%s\n" "`echo -e $red`These texts are in red`echo -e $NC`"

There is a table of color values attached (this table is from the link). You can find color values what you want.

Sunday, November 23, 2008

linux:shell: /bin/tar: Argument list too long

When you create a tar archive and have an error: /bin/tar: Argument list too long, then you could try an argument of tar:

-T or --files-from=F

(which allows you to get names to extract or create from file F).

Wednesday, November 12, 2008

linux:shell: broken 'while' loop

When I do a while loop in which there is a command 'ssh', the while loop just goes only one iteration and quits. The problem is from 'ssh' read stdin so that 'while' cannot read anymore and stop afterwards, for example,

while read CompName
do
ssh $CompName 'ls'
echo "Done"
done <>

In the example, only one iteration is conducted (including the echo line). The solutions are provided by google searching. One is general one, I think. 1) Redirect ssh stdin by

< /dev/null ssh $CompName 'ls'

2) ssh-specified trick: use '-n':

ssh -n $CompName 'ls'

Saturday, November 8, 2008

linux:shell:bash:grep: multi-grep

If I want to search multi words by grep, I could do in the way:

egrep "a|b|c|d" my_input_file.txt

then egrep will help you to search OR of a, b, c and d. If searching for AND of multi-words, you can do by pipe:

grep a my_input_file.txt |grep b |grep c |grep d

. However, sometimes, it is not so easy to use pipe in one line for the above usage. You can always build string of the command first and evaluate it. For example,

cmd="grep $var1 my_input_file.txt|grep $var2"
...
cmd="$cmd |grep $var3"
...
eval $cmd

Linux:shell: awk: multiple separators

'awk' is a very useful shell command (also a program language) in linux (unix). You split one text line by it. For example, for the line

line="aa, b c , d , f "

what you can do in shell command (bash) is

echo $line|awk -F "," '{print $1 $2 $3 $4}' # to get different columns separated by ","

However, if you wanna split one line with multi-separators, then you could do in the way, for example,

$ line="aa, bb_ ccd: ee"
$ echo $line |awk -F ",|_|:" '{print $1$2$3}'

Note here "|" will do logic "OR" of all separators. This is similar 'egrep'. If you want to grep multi key words, then you could do in the same way (which has been addressed in my other blog, just search grep ).

Tuesday, October 14, 2008

Linux:command: du and quota

My disk quota is full on my account at Fermilab (.../home/zhiyil/desktop/...). So I have to clean to get more rooms to store files to SAM. Use the command:

du -s * .[a-zA-Z]* | sort -n

get an idea of which file is the largest one so that you could deal with them.

Thursday, October 9, 2008

Linux:command:shell: diff

One of layouts of printout of the command 'diff' is called: --side-by-side or -y which is also useful. Change the column width, just use

-W columns

--width=columns
. An example:

diff --side-by-side -W 130 file1.txt file2.txt

Tuesday, October 7, 2008

Linux:command: seq

When printing a sequence of numbers, use 'seq'. One of arguments is '-w' or '--equal-width' which will equalize width by padding with leading zeros.

Locations of visitors to this page