KLog

June 28, 2008

Useful Linux command

Filed under: Misc tips — hwkang @ 3:15 pm

lshw: list hardware information snapshot

———————-

cat /proc/version: show the Linux version

———————-

rm`ls -1 | grep -v ‘precious$’ | xargs` -rf

: remove all files/folders in current directory except ‘precious’; ls -1 list all in a column; -rf removes without confirmation

———————-

rm -i `ls -1 | grep -v ‘\.abc$’ | grep -v ‘\.xyz$’ | xargs`

: remove all files in current directory except files with extension ‘.abc’ or ‘.xyz’; -i prompts for confirmation for each deletion

———————-

rm `find | grep .ext | xargs`

: remove all files with extension’.ext’, in current folder and all subfolders.

———————-

useful gcc debug options:

`-print-search-dirs’
: Print the name of the configured installation directory and a list of program and library directories gcc will search–and don’t do anything else.

———————-

mount remote directory

sudo apt-get install sshfs

sudo modprobe fuse

sudo adduser username fuse

sudo chown root:fuse /dev/fuse

sudo chmod +x /dev/fuse(rmout?)

logout and login again

mkdir ~/remoteserv

sshfs username@ipaddress:/remotepath ~/remoteserv

———————-

show size of folders
du –max-depth=1 “somedir” | sort -n -r
du -h –max-depth=1 “somedir”
———————-
count the number of files in a certain folder:
ls “somedir” | wc -l
———————-
ldd “some_binary”
: list the dependency for “some_binary” file. It’s very useful to correct some mis-linked libraries.
———————-
remove a long list of files.
rm is the most frequently used command to remove a bunch of files, however, sometimes we would see this message “rm: Argument list too long”. What I would guess is the way ‘rm’ is implemented is that it first creates a list of file names with string and then iterates through the list to delete each file. Therefore, it’s reasonable to set an upper-bound.
A good workaround, I found from google is : find <some dir> -name “<some pattern>” -print | xargs rm
Before you use this command, run this first to check if they are actually the files you are looking for: find “some dir” -name “some pattern” | more
———————-

Add user access to afs directories(could be used for cvs project sharing)

fs sa <directory> <username> <permission>

fs la: to list access information

to remove someone’s access and recursively:

find . -type d -print | xargs fs setacl -acl <username> none -dir

———————-

Shell for statement

e.g.

for ((i=1; i<1000; i++))

do

qdel $i

done
———————-
# rename every *.htm file *.html
for f in *htm ; do mv $f `basename $f htm`html; done”
———————-

List only directories:

ls -d */

———————-

Redirecting stdout and stderr to file:

1) stderr to file:

e.g. foo 2> file.out

2) stdout to file:

e.g. foo > file.out

3) stdout and stderr to file:

e.g. foo &> file.out

———————-

A link to some handy commands(will update to my list when tried each):
http://www.daniweb.com/forums/thread1743.html

June 20, 2008

Getting raw char array from a string

Filed under: Misc tips — hwkang @ 5:56 pm

string str=”I am a string”;

char chr[256]=”" ;

strcpy(chr, str.c_str());

mkdir, cp, mv in C/C++

Filed under: Misc tips — hwkang @ 5:55 pm

#include <sys/stat.h>

#include<sys/types.h>

int mkdir(const char *pathname, mode_t mode);

note 1. definition of mode:

sequence: owner, group, others

4=read, 2=write, 1=execute -> 3=wx, 5=r-x, 6=rw, 7=rwx

e.g. 0700, grants the owner read, write, execute privilege while exclude group and other users.

note 2.

The final mode of the folder depend on a variable called “umask” , and

final_mode = input_mode & ~umask

e.g.

normally umask = 0022 , which exclude group and other users from writing the folder(file)

therefore: putting 0666, actually with result in 0666 & ~0022 = 0644

<< Update on Oct 30, 2008>>

I just found there’s still problem in there.  I set all the permission like the following:

mkdir(somedir, 777);

The actually permission was set to: r—-x–x

Instead, I found I have to do this:

#define MY_MASK 0777

int temp;

printf(“Default mask: %o\n”, MY_MASK & ~022 & MY_MASK);

temp = umask(0);

printf(“Previous umask = %o\n”, temp);

mkdir(sub_match_dir, MY_MASK);

June 19, 2008

Change the DPI in Fedora Core 5

Filed under: Misc tips — hwkang @ 9:03 pm

1. Check screen dimension:

xdpyinfo | grep dimension

2. Check DPI(resolution):

xdpyinfo | grep resolution

3. Understand the relationship between display_size(mm), screen_pixel_dimension(pixel) and DPI(pixel/inch)

DPI = (screen_pixel_dimension/display_size)*mm/inch=(pixel dimension/display_size)*25.4

i.e.

display_size = screen_pixel_dimension/DPI*25.4

e.g. I have a screen with 1920×1200 pixel dimension. I want a DPI of 110 pixel per inch. My display size would be:

Horizontal: 1920/110*25.4~443

Vertical: 1200/110*25.4~277

4. Change DPI by manually setting display size in /etc/X11/xorg.conf

e.g.

su

vi /etc/X11/xorg.conf

Add/Modify the following:

Section “Monitor”
Identifier “Monitor0″
ModelName “LCD Panel 1920×1200″
HorizSync 31.5 – 90.0
VertRefresh 59.9 – 60.1
Option “dpms”
DisplaySize 443 277 # 1920×1200 110dpi
EndSection

Restart X by: Ctrl+Alt+Backspace

Getting Firefox to display Chinese in Fedora Core 5

Filed under: Misc tips — hwkang @ 8:16 pm

1. Get Chinese font file: fonts-chinese-3.02-4.1.noarch.rpm

2. install new font file: rpm -vih fonts-chinese-3.02-4.1.noarch.rpm

3. restart firefox

How to add a Desktop Access (Show Desktop) Button in Fedora Core 5

Filed under: Misc tips — hwkang @ 5:52 pm

1. Right click on the task bar;Add Applet to Panel

2. Select ‘Show Desktop’ from the pop list

Powered by WordPress