Showing posts with label console. Show all posts
Showing posts with label console. Show all posts

Monday, August 11, 2008

Номер процесса по номеру порта

Know process id with a port

Как узнать имя процесса по номеру порта?
Найти и обезвредить! =)

alexey@alexey:~$ sudo lsof -iTCP:8080
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
java 635 alexey 13u IPv6 10169721 TCP *:webcache (LISTEN)

alexey@alexey:~$ sudo ps 635
PID TTY STAT TIME COMMAND
635 pts/1 Sl+ 0:20 /home/alexey/java/jdk1.5/bin/java -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog -Djava.security.auth.

alexey@alexey:~$ sudo ps -p 635 -l
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
0 S 1000 635 611 1 85 0 - 194938 383196 pts/1 00:00:20 java

alexey@alexey:~$ sudo kill -9 635

Tuesday, June 3, 2008

SVN in command line helps you

Are there conflicted?
svn st * | grep "C "

Are there unversioned?
svn st * | grep "? "

Are there modified?
svn st * | grep "M "

Are there unversioned but not mine generated?
svn st * | grep "? " | grep -v "target" | grep -v ".classpath" | grep -v ".settings" | grep -v ".project"

How to remove that files which are results of search?
| xargs rm -rf

Thursday, March 20, 2008

Console

Теперь разделены статьи консоль и консоль для интернета

Как правильно спросить в никсах исполнимый файл или нет?
ls -l file1
или
stat -c %a file1

как скопировать пермишен одного файла другому?
chmod --reference=file1 file2

Прикольная команда делает список файлов с числовым представлением пермишенов
for i in $(ls) ; do bla=$( stat -c “%a” $i);echo “$i: $bla”; done

Замена одной папку в пути на другую
pwd | sed 's/\/старая_папка\//\/новая_папка\//'

Create tar gz archive
tar -pczf name_of_archive.tar.gz /path/to/directory

Bash Guide for Beginners
http://tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html

Advanced Bash-Scripting Guide
http://tldp.org/LDP/abs/html/

Print dir with sort.
Сортировка папок по размеру
du -sb * | sort -n -t\ | more
thx Vitaliy

Print current dir
pwd | awk '{i=split($0, Name, "/") ; print ("Name[" i "]=" Name[i])}'
http://project.net.ru/web-master/unix_shell/article4/

List of directories
Список директорий
find . /* -type d -maxdepth 0
tree -dR -L 3

Make CD fs and burn it
mkisofs -r -o image.iso ivana_kupala/
sudo mkdir /mnt/iso
sudo mount -t iso9660 image.iso /mnt/iso -o loop
sudo umount /mnt/iso/
cdrecord -v -eject -dummy image.iso
cdrecord -v -eject image.iso


Make DVD
mkisofs -dvd-video -o /home/alexey/Download/karaoke.iso /home/alexey/Download/Karaoke/

isoinfo -i karaoke.iso-l

  1. Make an "ISO" filesystem image of a DVD filesystem:

    mkisofs -dvd-video dvd >dvd.iso

    dvd is the directory containing the filesystem produced by dvdauthor.

  2. Record "ISO" filesystem image to disc:

    growisofs -dvd-compat -Z /dev/dvd=dvd.iso

    The -Z option selects one-time recording or overwriting. growisofs can also record a new session (hence its name) but DVD videos must be recorded in a single session. The -dvd-compat option enables various recording features to improve compatibility.

  3. Record DVD filesystem directly to disc:

    growisofs -dvd-compat -Z /dev/dvd -dvd-video dvd
How to create ISO images from your HD CD DVD
=============================================
To make an ISO from your CD/DVD, place the media in your drive but do not mount it. If it automounts, unmount it. (ubuntu automount so you need to unmount, that's quite easy, just choose the option unmount from the shell).

dd if=/dev/dvd of=dvd.iso # for dvd
dd if=/dev/cdrom of=cd.iso # for cdrom
dd if=/dev/scd0 of=cd.iso # if cdrom is scsi

To make an ISO from files on your hard drive, create a directory which holds the files you want. Then use the mkisofs command.

mkisofs -o /tmp/cd.iso /tmp/directory/

This results in a file called cd.iso in folder /tmp which contains all the files and directories in /tmp/directory/.

=============================================


http://womble.decadent.org.uk/talks/dvd-ukuug06/dvd-talk-ukuug06-paper.html

Rename
Переименование последовательности символов в файлах
how-to-bulk-rename-files-in-linux-in-the-terminal
ex.
rename 's/(-2\.0-)/_v2_/' *


Count lines with find and wc
Как узнать количество строк во всех файлах ".java"
find . -wholename './*.java' -type f | xargs wc -l


Count directorys sizes with find and du
Как узнать обьем всех по отдельности папок в текущем каталоге
find . -maxdepth 1 -type d | xargs du -sh
du -h --max-depth 1

Thursday, March 13, 2008

dos and win console commands

http://www.ss64.com/nt/
*.bat files

Examples:
call cd applications/assembly/
rmdir /s /q ..\..\..\..\..\..\..\exo-working\exo-tomcat\
mkdir ..\..\..\..\..\..\..\exo-working\exo-tomcat\
xcopy /e /h /r ..\..\..\..\..\..\..\exo-dependencies\tomcat-5.5.17\* ..\..\..\..\..\..\..\exo-working\exo-tomcat\*
pause null

Tuesday, January 22, 2008

Console for networking and internet

Перетаскивая ноутбук дом-работа приходиться менять конфиги:
Можете использовать gedit вместо vi.

1.1. ip command to set a default router to 192.168.0.1
sudo ip route add default via 192.168.0.1

1.2. route command to set a default router to 192.168.0.1
sudo route add default gw 192.168.0.1

1.3. Save routing information to a configuration file /etc/network/interfaces
sudo vi /etc/network/interfaces
gateway 192.168.0.1

2.
Save nameserver information to a configuration file /etc/resolv.conf
sudo vi /etc/resolv.conf
nameserver 192.168.0.1

3. Restart networking
sudo /etc/init.d/networking restart

ip a change 192.168.0.12/24 dev eth0

ip r list
ip a list
cat /etc/network/interfaces
ifconfig
sudo mtr ya.ru
telnet svn.exoplatform.org 80
ping www.exoplatform.org
cat /etc/resolv.conf

Ping
ping HOST_OR_IP
ex.1:
$ ping google.ru
------------------------------
PING google.ru (72.14.221.104) 56(84) bytes of data.
64 bytes from fg-in-f104.google.com (72.14.221.104): icmp_seq=1 ttl=248 time=1106 ms
...
------------------------------
ex.2:
$ ping ya.ru
------------------------------
PING ya.ru (213.180.204.8) 56(84) bytes of data.
64 bytes from ya.ru (213.180.204.8): icmp_seq=2 ttl=56 time=99.3 ms
...
------------------------------



Nmap
sudo nmap -sS -PI -PT -O -F 192.168.0.1
sudo nmap -sS --open -p T:80,8080 192.168.0.1-255
ex.1:
alexey@wtf:~$ sudo nmap -sS --open -p T:80,8080 72.14.221.104
------------------------------
Starting Nmap 4.20 ( http://insecure.org ) at 2008-01-22 09:11 EET
Interesting ports on fg-in-f104.google.com (72.14.221.104):
Not shown: 1 filtered port
PORT STATE SERVICE
80/tcp open http

Nmap finished: 1 IP address (1 host up) scanned in 5.444 seconds
------------------------------


ex.2:
alexey@wtf:~$ sudo nmap -sS -PI -PT -O -F 72.14.221.104
------------------------------
Starting Nmap 4.20 ( http://insecure.org ) at 2008-01-22 09:12 EET
Interesting ports on fg-in-f104.google.com (72.14.221.104):
Not shown: 1252 filtered ports
PORT STATE SERVICE
80/tcp open http
113/tcp closed auth
179/tcp closed bgp
443/tcp open https
Device type: general purpose
Running (JUST GUESSING) : Microsoft Windows 95/98/ME|NT/2K/XP|3.X (85%), Linux 1.X (85%), NetBSD (85%)
Aggressive OS guesses: Microsoft Windows NT 3.51 SP5, NT 4.0 or 95/98/98SE (85%), Linux 1.3.20 (x86) (85%), NetBSD 1.6.2 (alpha) (85%), Microsoft Windows 3.1 with Trumpet Winsock 2.0 revision B (84%)
No exact OS matches for host (test conditions non-ideal).

OS detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .
Nmap finished: 1 IP address (1 host up) scanned in 97.809 seconds

------------------------------


Telnet
telnet 192.168.0.1 80
GET . HTTP/1.0
ex.1:
alexey@wtf:~$ telnet 72.14.221.104 80
------------------------------
Trying 72.14.221.104...
Connected to 72.14.221.104.
Escape character is '^]'.
------------------------------

GET http://www.google.ru HTTP/1.0
------------------------------
HTTP/1.0 200 OK
Cache-Control: private
Content-Type: text/html; charset=windows-1251
Set-Cookie: PREF=ID=940ca0c052b49a6a:NW=1:TM=1200985708:LM=1200985708:S=xE0rP3DhbLa0U2SU; expires=Thu, 21-Jan-2010 07:08:28 GMT; path=/; domain=.google.ru
Server: gws
Date: Tue, 22 Jan 2008 07:08:28 GMT
Connection: Close

...
meta equiv="content-type" content="text/html; charset=windows-1251" .. title .. Google ./title..
...
...
------------------------------


ex.2:
POST /portal/portal HTTP/1.0
Host: localhost
Content-Length: 26

fis=yes&listCollapsed=true


Wget
r - рекурсивно
c - дописать
l - глубина
ex.
wget -r -c -l 2 http://docs.oasis-open.org/wsrp/v2/
wget -r -c -l 1 -nd -P wsrpSpecFiles http://docs.oasis-open.org/wsrp/v2/
wget -r -k -с -l 0 -np http://example.com/
- выкачка сайта целиком (рекурсивно, изменяя ссылки на относительные, докачивая, с неограниченной глубиной, без вышестоящего домена)

wget - wiki
Wget - насос для Интернета

Iptables

добавьте 127.0.0.1 link.altova.com в hosts
> sudo gedit /etc/hosts

запретить всем программам TCP подключения к 443 и 2799 портам на IP адресах 84.53.166.97, 88.221.170.97, 88.221.2.97
> sudo iptables -A INPUT -p tcp --dport 443:2799 -d 84.53.166.97 -j DROP
> sudo iptables -A INPUT -p tcp --dport 443:2799 -d 88.221.170.97 -j DROP
> sudo iptables -A INPUT -p tcp --dport 443:2799 -d 88.221.2.97 -j DROP
> sudo iptables --list


Links
http://www.xml.com/pub/a/2004/12/15/telnet-REST.html
http://ipesin.linux.kiev.ua/translations/rhm/love_cl1.htm
http://ipesin.linux.kiev.ua/translations/rhm/love_cl2.htm