Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2009. 6. 11. 09:31

sort and Remove duplicate lines


>>> sort myfile.txt | uniq
Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2008. 7. 7. 10:06

grep

print out all lines contain ( 完 ):

$> grep -w '( 完 )' train.UCUP.utf8


Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2008. 5. 7. 16:24

linux command related with process

$ps
    to see currently running process
$kill 1012    #kill {PID}
    to stop any process by PID i.e. to kill process
$killall http    #killall {Process-name}
    to stop processes by name i.e. to kill process
$ps -ag
    to get information about all running process
$kill 0
    to stop all process except your shell
$ls | wc -l &    #linux-command &
    for background processing
$ps aux
    to disply the owner of the processes along with the processes
$ps ax | grep http   #ps ax | grep process-U-want-to see
    to see if a particular process is runing or not. For this purpose you have to use
    ps command in combination with the grep command
$top
    to see currently running processes and other information like memory and
    CPU usage with real time updates.
$pstree
    to display a tree of processes
   
   
Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2008. 2. 27. 13:53

iconv

iconv -f gb2312 -t utf-8 original_file_name > target_file_name

ex :
iconv -f gb2312 -t utf-8 train.CityU.gb > train.CityU.utf8
Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 12. 27. 22:02

Archiving with Tar

Archiving with Tar

Tar files place several files or the contents of a directory or directories in one file. This is a good way to create backups and archives. Usually, tar files end with the .tar extension.

To create a tar file, type:

tar -cvf filename.tar files/directories

In this example, filename.tar represents the file you are creating and files/directories represents the files or directories you want to put in the new file.

To extract the contents of a tar file, type:
tar -xvf foo.tar

This command does not remove the .tar file, but it places copies of the .tar contents in the current working directory.

The tar command does not compress files automatically. You can compress tar files with:

tar -czvf foo.tar

Compressed tar files are conventionally given the extension .tgz and are compressed with gzip.

To expand a compressed tar file type:

create:

tar -cvf mystuff.tar mystuff/
tar -czvf mystuff.tgz mystuff/

extracting:

tar -xvf mystuff.tar
tar -xzvf mystuff.tgz

testing/viewing:

tar -tvf mystuff.tar
tar -tzvf mystuff.tgz

Note that .tgz is the same thing as .tar.gz
Tar "tars up" a bunch of files into one "tar-file"
gzip is compression, but only works on one file, so the entire "tarfile" is compressed.

tar xvf **.tar.tar

Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 12. 26. 11:26

how to check folder size

$ du -hs /path/to/directory
Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 12. 11. 20:48

vi: search and replace

Vi: Search and Replace

Change to normal mode with <ESC>.

Search (Wraped around at end of file):

  Search STRING forward :   / STRING.
  Search STRING backward:   ? STRING.

  Repeat search:   n
  Repeat search in opposite direction:  N  (SHIFT-n)

Replace: Same as with sed, Replace OLD with NEW:
 
 First occurrence on current line:      :s/OLD/NEW
  
 Globally (all) on current line:        :s/OLD/NEW/g 

 Between two lines #,#:                 :#,#s/OLD/NEW/g
  
 Every occurrence in file:              :%s/OLD/NEW/g 
Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 12. 11. 09:34

[linux]check and kill all process of certain user

check all process of certain user :


$ top -u johndoe
OR
$ top -u 500
OR
$ top -U johndoe








kill all process of certain user:
kill -9 `ps -u <username> -o "pid="`

Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 11. 1. 15:58

ps & kill

Linux / Unix Command: ps / kill
Command Library

Even on Linux it sometimes happens that processes wear out their welcome and stick around longer than you would like them to. They simply ignore your request to close up and go away. Fortunately you have a powerful gun at your disposal that will clean out anything that doesn't get a hint: The Arnold Schwarzenegger equivalent among the Linux commands is the kill command.

The kill command works together with the ps command

  • With the ps command (ps stands for "process status") you find out the identity of the program you want to get rid of.
  • Then kill will finish it off.

    Here's how you do it:

The ps Command

It is used to display the currently running processes on Unix/Linux systems. If you know the 'Task-Manager" which pops up under Windows NT/2000/XP when you press CTRL+ALT+DEL then you will quickly grasp what ps does on Linux. It can show you the processes on your system in various formats. Here is a typical example:

To display all processes owned by the current user type ps ux and hit return:

$ ps ux

This will show a listing of processes similar to:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jhaas 3064 0.1 3.6 18324 9088 ? S 17:55 0:00 /usr/bin/gnome-session
jhaas 3107 0.0 0.3 3128 968 ? S 17:55 0:00 /usr/bin/ssh-agent /etc/X11/xinit/Xclients
jhaas 3112 0.1 2.9 11208 7376 ? S 17:55 0:00 /usr/libexec/gconfd-2 11
jhaas 3130 0.0 0.6 3584 1696 ? S 17:55 0:00 xscreensaver -nosplash
jhaas 3133 0.8 5.3 21744 13216 ? S 17:55 0:03 gnome-panel --sm-client-id default2
jhaas 3137 0.0 2.4 16296 6172 ? S 17:55 0:00 magicdev --sm-client-id default4
jhaas 3141 0.0 2.8 16676 6936 ? S 17:55 0:00 eggcups --sm-client-id default6
jhaas 3143 0.0 1.7 11652 4308 ? S 17:55 0:00 pam-panel-icon --sm-client-id default0
jhaas 3145 0.2 5.4 24280 13564 ? S 17:55 0:01 /usr/bin/python /usr/bin/rhn-applet-gui --sm-client-id default5
jhaas 3154 0.3 4.1 23856 10172 ? S 17:55 0:01 evolution
jhaas 3157 0.0 0.9 5636 2228 ? S 17:55 0:00 oafd --ac-activate --ior-output-fd=10
jhaas 3216 0.2 3.1 12788 7844 ? S 17:56 0:00 emacs
jhaas 3218 1.3 4.0 20248 9904 ? R 17:56 0:04 gnome-terminal
jhaas 3219 0.0 0.2 1852 572 ? S 17:56 0:00 [gnome-pty-helpe]
jhaas 3220 0.0 0.5 4316 1388 pts/0 S 17:56 0:00 bash
jhaas 3268 0.0 0.2 2636 684 pts/0 R 18:01 0:00 ps ux

The kill Command

Now, if you want to terminate for example the emacs process you would look up the process identifier (PID) in the above table (3216), and say:

$ kill -9 3216

The -9 will ensure "execution".

A convenient short cut is the Alt-Ctrl-Esc key combination, which allows you to simply click on the application you want to kill.

Linux & Ubuntu/Linux tips | Posted by 알 수 없는 사용자 2007. 11. 1. 15:56

df - Linux command line tool to display disk space usage

df - Linux command line tool to display disk space usage


-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)

-H, --si
likewise, but use powers of 1000 not 1024

-i, --inodes
list inode information instead of block usage

-k like --block-size=1K

-l, --local
limit listing to local file systems

--no-sync
do not invoke sync before getting usage info (default)

-P, --portability
use the POSIX output format

--sync invoke sync before getting usage info

-t, --type=TYPE
limit listing to file systems of type TYPE

-T, --print-type
print file system type

-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE

-v (ignored)

--help display this help and exit

--version
output version information and exit

Examples

If you use df with no options it will display all the available filesystems' info

$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 151225248 16280980 127262392 12% /
tmpfs 517924 0 517924 0% /lib/init/rw
udev 10240 60 10180 1% /dev
tmpfs 517924 0 517924 0% /dev/shm
/dev/sdb1 76896316 54820876 18169240 76% /media/discob
sshfs#ggarron@alketech.com:/home/ggarron/
7999999992 0 7999999992 0% /mnt/remote

To better understand what is in the screen can be used the -h (human readable)

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 145G 16G 122G 12% /
tmpfs 506M 0 506M 0% /lib/init/rw
udev 10M 60K 10M 1% /dev
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 74G 53G 18G 76% /media/discob
sshfs#ggarron@alketech.com:/home/ggarron/
7.5T 0 7.5T 0% /mnt/remote

To display only local mounted systemfilesystems use the -l (local) options, you will see the sshfs remote filesystem is not shown anymore.

$ df -hl
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 145G 16G 122G 12% /
tmpfs 506M 0 506M 0% /lib/init/rw
udev 10M 60K 10M 1% /dev
tmpfs 506M 0 506M 0% /dev/shm
/dev/sdb1 74G 53G 18G 76% /media/discob

You can use it pointed to the device path or to the path where the filesystem is mounted

$ df -h /dev/sdb1
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 74G 53G 18G 76% /media/discob

$ df -h /media/discob/
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 74G 53G 18G 76% /media/discob