Monday, December 26, 2005

unix tip: find - limit the depth

by default find will search all subdirectories under the parent directory. but you can limit the depth by using maxdepth option.
eg:

- to limit it only to the current directory and not search through any subdirectories, use the -maxdepth 1 option.
$ find . -maxdepth 1 -name test
./test

- to search one level below of the directory use the -maxdepth 2 option.
$ find . -maxdepth 2 -name test
./scripts/test
./test
./tmp/test

- if not using -maxdepth option.
$ find . -name test
./scripts/test
./test
./tmp/test
./.snapshot/hourly.2/test
./.snapshot/hourly.2/tmp/test
./.snapshot/hourly.1/test
./.snapshot/hourly.1/tmp/test
./.snapshot/hourly.0/test
./.snapshot/hourly.0/tmp/test


Wednesday, December 21, 2005

unix tip: one-liner find files with different regex

instead of we type find a few times, we can use -o option.
eg:

$ find . -name "*ksh" -o -name "*txt"
./.mozilla/default/nxdv20h2.slt/cookies.txt
./scripts/sham.ksh
./scripts/java.txt
./scripts/ii.ksh
./scripts/aa.ksh
./scripts/input.txt
./scripts/output.txt
./scripts/test.ksh
./scripts/tiktok.ksh
./scripts/file.txt
./download/firefox-installer/license.txt
./sample.txt

Tuesday, November 29, 2005

unix tip: one-liner find & replace string

normally people use sed to find & replace string.
eg:

$ cat test
abc def xyz 123 456 789
$ sed 's/abc/123/g' test
123 def xyz 123 456 789

but the output is sent to stdout (the screen) not to the file unless you redirect it to new file.
you can use perl to do that.
eg:

$ cat test
abc def xyz 123 456 789
$ perl -pi -e 's|abc|123|g' test
$ cat test
123 def xyz 123 456 789

to backup the original file use -pi.bak option & your original file will be saved as .bak

Wednesday, November 16, 2005

unix tip: ps - full listing of the processes name

to get full listing of the processes name when using ps
for linux, you can use -w option.
eg:

$ ps -auxww

for aix, you can use -l option.
$ ps -elf

but for solaris, the processes name get truncated when you use -l option, so it is sufficient to use ps -ef only.


Wednesday, November 02, 2005

unix tip: return to previous directory

for linux if u want to return to previous directory u can type.
eg:

$ cd -

this also works for solaris & hpux. ooopss also works for aix, but if not working u can try this.
$ cd ~-

i suspect it's depend on your shell... hmmm no idea...

Friday, October 28, 2005

unix tip: when ssh root@hostname is not allowed

i guess most of the unix servers are configured not to allow root to ssh directly, at least sys admin will configured such way for security purpose. but in case of emergency or whatever reasons, you can try.
eg:

$ ssh -t root@hostname "su -"
- provide the root password & you are in as root.

this trick becomes handy when your password is expired or your account is locked, so that u can reset your password or unlock your account, but of cos u have to know the root password ;)
it works for solaris, unfortunately not with linux.

credit goes to my buddy - LC

Wednesday, October 26, 2005

no time to cp

i have no time to cp the tips to here unless it can be done automatically by script or something, so i guess it will there until further notice ;)

Saturday, October 22, 2005

cp -a http://komnas.com/~ashamril/tips/* http://ashterix.blogspot.com/

i like to collect linux tips & put it in one place for my reference. now i'm moving all the tips from http://komnas.com/~ashamril/tips/ to here.