Unix tips (contains duplicated)

A right terminal console when launching SSH

When run SSH, the terminal they give us may sick us due to the ugly interface. To have a proper one, as if run directly on the Unix server, is gnome-terminal.

Some helpful GUI application

Run a console and call the following commands :

  • A GUI-explorer : nautilus
  • Text editor with syntax highlight: kate
  • File manager – a very powerful & useful tool to work with your files: krusader
  • A great IDE application: eclipse

If you want to continue on your current terminal-console, you should run the application in background by adding the & at the end of the program name. E.g.:

vgnam@/home/vgnam> krusader&

“.bashrc” tips

The followings format the prompt of the terminal to the form of username@workingFolder and also colorize it.

usernameColor="\e[34;1m"
pathColor="\e[34m"
defaultColor="\e[0m"
export PS1="\[$usernameColor\]\u\[$default$pathColor\] \w $ \[$defaultColor\]"

Colorful ls command

alias ls='ls --color'

Note: The above scripts should be put in the .bashrc file in your home folder, e.g. /home/vgnam/.bashrc

Search and replace in bash command.

google:bash perl replace -> One-line shell script for find and replace

Using perl-like command:

perl -pi -e 's/find/replace/g' *.txt

Used with multiple files:

find . -name '*.txt' |xargs perl -pi -e 's/find/replace/g'

Another way using sed Use the sed command with inline option and regular-expression as :

sed -i -e 's/source/destination/g' *.html

In program //kate//, how to execute the current open file?

Simply press Ctrl-Shift-X

Install new font in Unix system?

Firts, extract and copy fonts to:

/usr/share/fonts/yourFontsFolder

Login as root user. Then, continue to use the command:

fc-cache /usr/share/fonts/yourFontsFolder

Print elapsed time from bash command ?

time1=`date +%s`
# your program that need to measure time runs here
time2=`date +%s`
elapsed=`echo $time2-$time1 | bc`
echo "Elapsed time: $elapsed seconds."

Delete recursive files, e.g. the “name.ext~” – How to?

find . -type f -name "yourPatter" -delete

How to get numbers of lines of a huge file? Call the wc command with -l option :

wc -l

How to get memory (RAM) size in Linux OS system by command line?

I need to know the memory size, RAM size, of the server which is a Linux OS. I look on the web and found this quite not easy since the input keyword must be precise.

cat /proc/meminfo

There u can see the line that says: MemFree : ### kB (or mB) is where the free memory is showed. For a brief information output let’s used :

cat /proc/meminfo | grep MemFree

This will show only the MemFree line! What a command!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: