Вы находитесь на странице: 1из 13

Linux [...

http://www.f-notes.info:9102/linux:linux_command

Linux


arch
uname -m

uname -r

dmidecode -q

- (SMBIOS / DMI)

hdparm -i /dev/hda

hdparm -tT /dev/sda

cat /proc/cpuinfo

cat /proc/interrupts

cat /proc/meminfo

cat /proc/swaps

()

cat /proc/version

cat /proc/net/dev

cat /proc/mounts

lspci -tv

PCI

lsusb -tv

USB

date

cal 2007

- 2007-

date 041217002007.00

(.)

clock -w

BIOS


shutdown -h now
init 0

telinit 0
shutdown -h hours:minutes &

shutdown -c

shutdown -r now
reboot
logout


cd /home

'/home'

cd ..

cd ../..

cd

cd ~user

user

. 1 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

cd -

pwd

ls

ls -F

ls -l

ls -a

ls *[0-9]*

tree
lstree

, (/)

mkdir dir1

'dir1'

mkdir dir1 dir2

mkdir -p /tmp/dir1/dir2

rm -f file1

'file1'

rmdir dir1

'dir1'

rm -rf dir1

'dir1'

rm -rf dir1 dir2

mv dir1 new_dir

cp file1 file2

file1 file2

cp dir/* .

dir

cp -a /tmp/dir1 .

dir1

cp -a dir1 dir2

dir1 dir2

ln -s file1 lnk1

ln file1 lnk1

"" ()

touch -t 0712250000 fileditest

, ,
(YYMMDDhhmm)


find / -name file1

file1. (/)

find / -user user1

user1.
(/)

find /home/user1 -name "*.bin"

, '. bin'.
'/ home/user1'

find /usr/bin -type f -atime +100

'/usr/bin',
100

find /usr/bin -type f -mtime -10

'/usr/bin',
10

find / -name *.rpm -exec chmod 755 , '.rpm',


'{}' \;

find / -xdev -name "*.rpm"

, '.rpm',
, cdrom, floppy ..

locate "*.ps"

,
'updatedb'

. 2 13

'.ps'.

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

whereis halt


, 'halt'

which halt

'halt'


mount /dev/hda2 /mnt/hda2

'hda2' '/mnt/hda2'.
- '/mnt/hda2'

umount /dev/hda2

'hda2'. , '/mnt/hda2'

fuser -km /mnt/hda2

. ,
-

umount -n /mnt/hda2

/etc/mtab.
" "

mount /dev/fd0 /mnt/floppy

mount /dev/cdrom /mnt/cdrom

CD DVD

mount /dev/hdc /mnt/cdrecorder

CD-R/CD-RW DVD-R/DVD-RW(+-)

mount -o loop file.iso /mnt/cdrom

ISO-

mount -t vfat /dev/hda5 /mnt/hda5

Windows FAT32

mount
-t
smbfs
username=user,password=pass
//winclient/share /mnt/share
mount
-o
/var/ftp/user

bind

-o
Windows (SMB/CIFS)

"" (binding).
/home/user/prg 2.4.0.
,
,

ftp ftp-
"" (chroot), .


df -h


, (..
-h *nix )

ls -lSr |more

du -sh dir1

,
(.. -h *nix )

du -sk * | sort -rn

'dir1'

rpm
-q
-a
--qf '%10{SIZE}t% ,
{NAME}n' | sort -k1,1n
rpm-, (fedora, redhat ..)
dpkg-query
-W
-f='${Installed- ,
Size;10}t${Package}n' | sort -k1,1n
deb-, (ubuntu, debian ..)

groupadd group_name

group_name

groupdel group_name

group_name

groupmod
-n
old_group_name

new_group_name

old_group_name new_group_name

user1,
useradd -c "Nome Cognome" -g admin
/home/user1, shell' /bin/bash,
-d /home/user1 -s /bin/bash user1
admin Nome Cognome

. 3 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

useradd user1

user1

userdel -r user1

user1

usermod -c "User FTP" -g system -d



/ftp/user1 -s /bin/nologin user1
passwd

passwd user1

user1 ( root)

chage -E 2005-12-31 user1

user1

pwck

/etc/passwd /etc/shadow

grpck

/etc/group

newgrp [-] group_name

. "-",
,
. ,
/etc/passwd

/
ls -lh

ls /tmp | pr -T5 -W$COLUMNS

/tmp

chmod ugo+rwx directory1

directory1 ugo(User Group


Other)+rwx(Read Write eXecute) - .
"chmod 777 directory1"

chmod go-rwx directory1


directory1.

chown user1 file1

file1 user1

chown -R user1 directory1

directory1
user1

chgrp group1 file1

- file1 group1

chown user1:group1 file1

file1

find / -perm -u+s

, , SUID

chmod u+s /bin/binary_file

SUID- /bin/binary_file.

.

chmod u-s /bin/binary_file

SUID- /bin/binary_file.

chmod g+s /home/public

SGID- /home/public.

chmod g-s /home/public

SGID- /home/public.

chmod o+t /home/public

STIKY- /home/public.

chmod o-t /home/public

STIKY- /home/public


chattr +a file1

chattr +c file1

/ .

chattr +d file1

dump
backup'

. 4 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

chattr +i file1

:
, , .

chattr +s file1

, ..
s , , ,
,
.

chattr +S file1

, , ,
, sync

chattr +u file1

lsattr


bunzip2 file1.bz2
gunzip file1.gz
gzip file1
bzip2 file1

'file1.gz'

'file1'

gzip -9 file1

file1

rar a file1.rar test_file

rar- 'file1.rar' test_file

rar a file1.rar file1 file2 dir1

rar- 'file1.rar' file1, file2 dir1

unrar x file1.rar

rar-

tar -cvf archive.tar file1

tar- archive.tar, file1

tar -cvf archive.tar file1 file2 dir1

tar- archive.tar, file1, file2 dir1

tar -tf archive.tar

tar -xvf archive.tar

tar -xvf archive.tar -C /tmp

/tmp

tar -cvfj archive.tar.bz2 dir1

bzip2(.. -j
*nix )

tar -xvfj archive.tar.bz2

(.. -j
*nix )

tar -cvfz archive.tar.gz dir1

gzip

tar -xvfz archive.tar.gz

zip file1.zip file1

zip-

zip -r file1.zip file1 file2 dir1

zip-
/

unzip file1.zip

zip-

RPM (Fedora, Red Hat )


rpm -ivh package.rpm

rpm -ivh --nodeps package.rpm

rpm -U package.rpm

,
,

rpm -F package.rpm

rpm -e package_name.rpm

. 5 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

rpm -qa

rpm -qa | grep httpd

, ,
"httpd"

rpm -qi package_name

rpm
-qg
Environment/Daemons"

"System

rpm -ql package_name

rpm -qc package_name

rpm -q package_name -- whatrequires

rpm -q package_name -- whatprovides show capability provided by a rpm package


rpm -q package_name -- scripts

, /

rpm -q package_name -- changelog

rpm -qf /etc/httpd/conf/httpd.conf

.
.

rpm -qp package.rpm -l

, ,

rpm
--import /media/cdrom

/RPM-GPG-KEY
rpm --checksig package.rpm

rpm -qa gpg-pubkey

rpm -V package_name

, , , , , MD5-

rpm -Va

rpm -Vp package.rpm

rpm2cpio package.rpm | cpio -- extract


bin
--make-directories *bin*
rpm -ivh /usr/src/redhat/RPMS/`arch`
,
/package.rpm
rpmbuild
package_name.src.rpm

--rebuild

YUM - (Fedora, RedHat )


yum install package_name

yum update

yum update package_name

yum remove package_name

yum list

yum search package_name

yum clean packages

rpm-,

yum clean headers

yum clean all

rpm-,

DEB (Debian, Ubuntu )

. 6 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

dpkg -i package.deb

dpkg -r package_name

dpkg -l

dpkg -l | grep httpd

, ,
"httpd"

dpkg -s package_name

dpkg -L package_name

, ,

dpkg --contents package.deb

dpkg -S /bin/ping

, .

APT - (Debian, Ubuntu )


apt-get install package_name

apt-cdrom install package_name

/ cdrom'

apt-get update

apt-get upgrade

apt-get remove package_name

apt-get purge package_name

apt-get check

apt-get clean

apt-get autoclean


cat file1

file1

tac file1

file1
( ..)

more file1

file1

less file1

file1
, (-),
..

head -2 file1

file1
. -

tail -2 file1

file1
. -

tail -f /var/log/messages

/var/log/messages
.


cat file | grep -i "Criteria" > result.txt

cat file | grep -i "Criteria" result.txt


. ,

grep Aug /var/log/messages

'/var/log/messages'
, "Aug"

. 7 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

grep ^Aug /var/log/messages

'/var/log/messages'
, "Aug"

grep [0-9] /var/log/messages

'/var/log/messages'
,

grep Aug -R /var/log/*

,
"Aug", , /var/log

sed 's/stringa1/stringa2/g' example.txt

example.txt "string1" "string2",


.

sed '/^$/d' example.txt

example.txt

sed '/ *#/d; /^$/ d' example.txt

example.txt

echo 'test' | tr '[:lower:]' '[:upper:]'

sed -e '1d' result.txt

example.txt

sed -n '/string1/p'

"string1"

sed -e 's/ *$// ' example.txt

sed -e 's/string1// g' example.txt

"string1"

sed -n '1,8p;5q' example.txt

sed -n '5p;5q' example.txt

sed -e 's/0*/0/g' example.txt

cat -n file1

cat example.txt | awk 'NR%2==1'

echo a b c | awk '{print $1}'

.
,
-,
/ /

echo a b c | awk '{print $1,$3}'

. , -,
/ /

paste file1 file2

file1 file2 : 1 file1 =


1 1-n, 1 file2 = 1 n+1-m

paste -d '+' file1 file2

file1 file2 "+"

sort file1 file2

sort file1 file2 | uniq

sort file1 file2 | uniq -u

,
(, ,
)

sort file1 file2 | uniq -d

comm -1 file1 file2

,
'file1'

comm -2 file1 file2

,
'file2'

comm -3 file1 file2


dos2unix filedos.txt fileunix.txt

. 8 13

MSDOS UNIX (
)

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

unix2dos fileunix.txt filedos.txt

UNIX MSDOS (
)

recode ..HTML < page.txt > page.html

page.html

recode -l | more

page.txt

html-


badblocks -v /dev/hda1

hda1 bad-

fsck /dev/hda1

/ linux-
hda1

fsck.ext2 /dev/hda1

/ ext2
hda1

e2fsck /dev/hda1
e2fsck -j /dev/hda1

/ ext3
hda1 ,

fsck.ext3 /dev/hda1

/ ext3
hda1

fsck.vfat /dev/hda1
fsck.msdos /dev/hda1

/ fat hda1

dosfsck /dev/hda1

mkfs /dev/hda1

linux- hda1

mke2fs /dev/hda1

ext2 hda1

mke2fs -j /dev/hda1

ext3 hda1

mkfs -t vfat 32 -F /dev/hda1

FAT32 hda1

fdformat -n /dev/fd0

mkswap /dev/hda3

swap- hda3

swap-
mkswap /dev/hda3

swap- hda3

swapon /dev/hda3

swap-, hda3

swapon /dev/hda2 /dev/hdb3

swap-, hda2
hdb3

(backup)
dump -0aj -f /tmp/home0.bak /home


/tmp/home0.bak

/home

dump -1aj -f /tmp/home0.bak /home

/home
/tmp/home0.bak

restore -if /tmp/home0.bak

/tmp/home0.bak

rsync -rogpav -- delete /home /tmp

/tmp /home

rsync -rogpav -e ssh -- delete /home


SSH-
ip_address:/tmp
rsync
-az
-e
ssh
--delete
ssh-
ip_addr:/home/public /home/local

rsync -az -e ssh -- delete /home/local


ssh-
ip_addr:/home/public

. 9 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

dd bs=1M if=/dev/hda | gzip | ssh ""


ssh-
user@ip_addr 'dd of=hda.gz'
'/home/user'
backup.tar

tar -Puf backup.tar /home/user

( cd /tmp/local/ && tar c . ) | ssh -C


/tmp/local
user@ip_addr 'cd /home/share/ && tar
ssh- /home/share/
x -p'
( tar c /home ) | ssh -C user@ip_addr /home
ssh- /home/backup-home
'cd /home/backup-home && tar x -p'
tar cf - . | (cd /tmp/backup ; tar xf - )

find /home/user1 -name '*.txt' | \


/home/user1 , '.txt',
xargs cp -av -- target-directory=/home

/backup/ --parents
find /var/log -name '*.log' | tar cv /var/log , '.log',
--files-from=- | bzip2 > log.tar.bz2
bzip-
dd if=/dev/hda of=/dev/fd0 bs=512
MBR (Master Boot Record) /dev/hda -
count=1
dd if=/dev/fd0 of=/dev/hda bs=512
MBR - /dev/hda
count=1
CDROM
cdrecord -v gracetime=2 dev=/dev
clean a rewritable cdrom
/cdrom -eject blank=fast -force
mkisofs /dev/cdrom > cd.iso

create an iso image of cdrom on disk

mkisofs /dev/cdrom | gzip > cd_iso.gz

create a compressed iso image of cdrom on disk

mkisofs -J -allow-leading-dots -R -V
"Label CD" -iso-level 4 -o ./cd.iso create an iso image of a directory
data_cd
cdrecord -v dev=/dev/cdrom cd.iso

burn an ISO image

gzip -dc cd_iso.gz | cdrecord dev=/dev


burn a compressed ISO image
/cdrom mount -o loop cd.iso /mnt/iso

mount an ISO image

cd-paranoia -B

rip audio tracks from a CD to wav files

cd-paranoia -- "-3"

rip first three audio tracks from a CD to wav files

cdrecord --scanbus

scan bus to identify the channel scsi

(LAN WiFi)
ifconfig eth0

eth0

ifup eth0

() eth0

ifdown eth0

() eth0

ifconfig eth0
255.255.255.0

192.168.1.1

netmask

eth0 ip-

ifconfig eth0 promisc

eth0 promiscuous- ""


(sniffing)

ifconfig eth0 -promisc

promiscuous- eth0

dhclient eth0

eth0 dhcp-.

. 10 13

12.04.2012 13:05

Linux [...

route -n

http://www.f-notes.info:9102/linux:linux_command

netstat -rn
route add -net 0/0 gw IP_Gateway

ip- (default gateway)

route add -net 192.168.0.0 netmask 192.168.0.0/16


255.255.0.0 gw 192.168.1.1
ip- 192.168.1.1
route del 0/0 gw IP_gateway

ip- (default gateway)

echo
"1"
/ip_forward

(forwarding)

>

/proc/sys/net/ipv4

hostname

host www .yandex . ru

www . yandex . ru ip-

host 93.158.134.3
ip link show

mii-tool eth0

eth0

ethtool eth0

eth0 ,

netstat -tupn

TCP
UDP ip- PID' ,

netstat -tupln

TCP UDP
ip- PID' ,

tcpdump tcp port 80

TCP- 80 ( - HTTP)

iwlist scan

iwconfig eth1

eth1

Microsoft Windows networks(SAMBA)


netbios- nbtscan
-,
,

.
nmblookup samba.

nbtscan ip_addr
nmblookup -A ip_addr
smbclient -L ip_addr/hostname

smbget -Rr smb: // ip_addr/ share

wget
smb-

mount
-t
smbfs
username=user,password=pass
//winclient/share /mnt/share

-o

windows-

smb-,

windows-

windows-,

IPTABLES (firewall)
iptables -t filter -nL
iptables -nL
iptables -t nat -L
iptables -t filter -F
iptables -F


NAT-
filter-

iptables -t nat -F

NAT-

iptables -t filter -X

filter-

. 11 13

12.04.2012 13:05

Linux [...

iptables -t filter -A INPUT


--dport telnet -j ACCEPT

-p

tcp

http://www.f-notes.info:9102/linux:linux_command

telnet'

iptables -t filter -A OUTPUT -p tcp


HTTP-
--dport http -j DROP
iptables -t filter -A FORWARD -p tcp
"" (forward) POP3-
--dport pop3 -j ACCEPT
iptables -t filter -A INPUT -j LOG -- log- ,
INPUT, "DROP INPUT"
prefix "DROP INPUT"
NAT (Network Address Translate)
iptables -t nat -A POSTROUTING -o eth0
eth0.
-j MASQUERADE
ip-.
iptables -t nat -A PREROUTING -d
192.168.0.1 -p tcp -m tcp -- dport 22 \ , ,
-j DNAT --to-destination 10.0.0.2:22

top

,
( )

ps -eafw

,
()

ps -e -o pid,args -- forest

PID'

pstree

kill -9 98989
kill -KILL 98989

"" PID 98989 " " (


)

kill -TERM 98989

PID 98989

kill -1 98989
kill -HUP 98989

PID 98989

lsof -p 98989

, PID 98989

lsof /home/user1

/home/user1

strace -c ls > /dev/null

,
ls

strace -f -e open ls > /dev/null

watch -n1 'cat /proc/interrupts'

last reboot

last user1

user1

lsmod

free -m

smartctl -A /dev/hda

/dev/hda SMART

smartctl -i /dev/hda

SMART /dev/hda

tail /var/log/dmesg

tail /var/log/messages

. 12 13

12.04.2012 13:05

Linux [...

http://www.f-notes.info:9102/linux:linux_command

apropos keyword

,
. , ,

man ping

, , - ping

whatis keyword

mkbootdisk --device /dev/fd0 `uname


-
-r`
gpg -c file1

file1 GNU Privacy Guard

gpg file1.gpg

file1 GNU Privacy Guard

wget -r www .example . com

www . example . com

wget -c www .example . com/file . iso

www . example . com/file . iso


echo
'wget
www .example . com/files. iso'
09:00

-c
at

ldd /usr/bin/ssh

, ssh

alias hh='history'

hh history

. 13 13

12.04.2012 13:05

Вам также может понравиться