Linux command

Linux Command

==============================================================
netstat -ntupl
-n Show numerical addresses instead of trying to determine symbolic host, port or user names.
-t tcp
-u udp
-p –program Show the PID and name of the program to which each socket belongs.
-l Show only listening sockets
-a Show both listening and non-listening sockets

==============================================================
ssh -CfNg -D 127.0.0.1:8000 jfo@pickbox.cc
建立本地ssh代理,浏览器中可以设置socks5代理为127.0.0.1:8000
-N Do not execute a remote command. This is useful for just forwarding ports (protocol version 2 only).
-f Requests ssh to go to background just before command execution
-C Requests compression of all data
-g Allows remote hosts to connect to local forwarded ports
-D [bind_address:]port
Specifies a local dynamic application-level port forwarding. This works by allo\
cating a socket to listen to port on the local side, optionally bound to the speci\
fied bind_address. Whenever a connection is made to this port, the connection is
forwarded over the secure channel, and the application protocol is then used to
determine where to connect to from the remote machine. Currently the SOCKS4 and
SOCKS5 protocols are supported, and ssh will act as a SOCKS server. Only root can
forward privileged ports. Dynamic port forwardings can also be specified in the
configuration file.

==============================================================
rsync -c -avz –delete –exclude=”.git” –exclude=”wp-content/uploads” –progress -e ssh . user@example.com:/opt/www
rsync -avz –delete –exclude=”.git” –progress -e ssh user@example.com:/opt/www/ .
-c: skip based on checksum, not mod-time & size

==============================================================
可以取消原来设置的默认参数,如:
ls -l :不会有默认的–color参数了
ls -p : add back slash after directory

==============================================================
Print only the process IDs of syslogd:
ps -C syslogd -o pid=

Print only the name of PID 42:
ps -p 42 -o comm=

pidofbash

==============================================================
objdumppe_dump.exe -x : Display the contents of all headers
objdump pe_dump.exe -s -j .idata : Display the full contents of “.idata” section
objdump pe_dump.exe -s -j .idata –start-address=0x431200 –stop-address=0x431800 : Display the full contents of “.idata” section in address [0x431200, 0x431800)
objdump pe_dump.exe -d -j .text : disassemble the contents of “.text” section
objdump pe_dump.exe -d -j .text –start-address=0x4187b0 : disassemble the contents of “.text” section starting from address 0x4187b0

objdump -j .text -Sl objtest | more
-S 尽可能反汇编出源代码,尤其当编译的时候指定了-g这种调试参数时,
效果比较明显。隐含了-d参数。
-l 用文件名和行号标注相应的目标代码 ( l是小写L )
-j name 仅仅显示指定section的信息

==============================================================
objcopy
–weaken
Change all global symbols in the file to be weak. This can be use-
ful when building an object which will be linked against other
objects using the -R option to the linker. This option is only
effective when using an object file format which supports weak sym-
bols.

eg:
objcopy –only-keep-debug foo foo.dbg
objcopy –strip-debug foo
objcopy –add-gnu-debuglink=foo.dbg foo
======等价=====>
strip –strip-debug foo
objcopy –add-gnu-debuglink=foo.full foo
(the file pointed to by the –add-gnu-debuglink can be the full
executable. It does not have to be a file created by the
–only-keep-debug switch.)

==============================================================
strip
strip - Discard symbols from object files.

==============================================================
nm
-u
–undefined-only
Display only undefined symbols (those external to each object
file).

==============================================================
cat /proc/pid_num/maps :
显示运行进程的内存分布,包括动态库加载的位置

pmapPID

cat
-b, –number-nonblank
number nonblank output lines
-n, –number
number all output lines

==============================================================
Graphviz dot脚本参数
nodesep=0.3;
ranksep=2;
rankdir=LR;

==============================================================
od -Ax -t x1 file
-A, –address-radix=RADIX
decide how file offsets are printed
-t, –format=TYPE
select output format or formats
-x same as -t x2, select hexadecimal shorts
x[SIZE] : hexadecimal, SIZE bytes per integer

==============================================================
tac- concatenate and print files in reverse

==============================================================
rev- reverse chars in each line of a file

==============================================================
date +%a
%a locale’s abbreviated weekday name (e.g., Sun)
%F full date; same as %Y-%m-%d
%s seconds since 1970-01-01 00:00:00 UTC
%T time; same as %H:%M:%S
%u day of week (1..7); 1 is Monday
%x locale’s date representation (e.g., 12/31/99)
%X locale’s time representation (e.g., 23:13:48)

%s show timeStamp

%F full date; same a

date -d “1970-01-01 UTC 1318477895 seconds”

 

==============================================================
备份文件的方法:
tar cf - . | (cd ../dest/directory; tar xpvf -) 或者
tar cf - . | tar xpvf - -C ../dest/directory

==============================================================
cut
-c:
$ echo “August” | cut -c2
u
$ echo “August” | cut -c1-3
Aug

==============================================================
tr [OPTION]… SET1 [SET2]
-d, –delete
delete characters in SET1, do not translate
$ echo “abcd1234” | tr -d ‘cd4’
ab123
-s, –squeeze-repeats
replace each input sequence of a repeated character that is
listed in SET1 with a single occurrence of that character
删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。
$ echo “aabaacccdefee” | tr -s ‘ace’
abacdefe
$ echo “aabaacccdefee” | tr -s ‘ace’ ‘xyz’
xbxydzfz

$ echo “abcd1234” | tr ‘[:lower:]’ ‘[:upper:]’
ABCD1234

SET2 is extended to length of SET1 by repeating its last character as necessary.
Excess characters of SET2 are ignored.
$ echo “abcd1234” | tr ‘abc’ ‘jfo’
jfod1234
$ echo “abcd1234” | tr ‘abcd’ ‘jfo’
jfoo1234
$ echo “abcd1234” | tr ‘ab’ ‘jfo’
jfcd1234
$ echo “g fmnc wms bgblr rpylqjyrc gr zw fylb.” | tr a-z c-za-b
i hope you didnt translate it by hand.

==============================================================
wall
wall – send a message to everybody’s terminal.
eg: wall “This is a message!”

==============================================================
fuser file
显示file正在被那个进程使用

==============================================================
csplit [OPTION]… FILE PATTERN…
Output pieces of FILE separated by PATTERN(s) to files xx01',xx02’, …,
and output byte counts of each piece to standard output.

长选项必须用的参数在使用短选项时也是必须的。
-b, –suffix-format=FORMAT use sprintf FORMAT instead of %d
-f, –prefix=PREFIX use PREFIX instead of `xx’
-k, –keep-files do not remove output files on errors
-n, –digits=DIGITS use specified number of digits instead of 2
-s, –quiet, –silent do not print counts of output file sizes
-z, –elide-empty-files remove empty output files
–help 显示此帮助信息并离开
–version 显示版本信息并离开

Read standard input if FILE is -. Each PATTERN may be:

INTEGER copy up to but not including specified line number
/REGEXP/[OFFSET] copy up to but not including a matching line
%REGEXP%[OFFSET] skip to, but not including a matching line
{INTEGER} repeat the previous pattern specified number of times
{*} repeat the previous pattern as many times as possible

A line OFFSET is a required +' or-‘ followed by a positive integer.

==============================================================
echo “(8.96-7.7)/3.7” | bc -lq
通过bc计算结果,-l 默认设置scale为20(可保留小数点后20位)
echo “scale=6; (8.96-7.7)/3.7” | bc -q
注意:scale=6必须写在expression的前面

==============================================================
cscope -Rbkq
-b Build the cross-reference only.
-k ‘kernel Mode’, turns off the use of the default include dir
(usually /usr/include) when building the database, since kernel
source trees generally do not use it.
-q Enable fast symbol lookup via an inverted index.
-R: 在生成索引文件时,搜索子目录树中的代码
-b: 只生成索引文件,不进入cscope的界面
-k: 在生成索引文件时,不搜索/usr/include目录
-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
eg: find | grep -v “arm|powerpc|amd” | xargs cscope -b

==============================================================
alien convert formats of binary package

==============================================================
setterm -blank 0 (让显示器不休眠)
setterm -blank n (n为等待时间)

==============================================================
让用户的密码必须有一定的长度,并且符合复杂度
vi /etc/login.defs,修改PASS_MIN_LEN

==============================================================
cpio
Main operation mode:
-i, –extract Extract files from an archive (run in copy-in mode)
-o, –create Create the archive (run in copy-out mode)
-p, –pass-through Run in copy-pass mode

-t, –list Print a table of contents of the input

-d, –make-directories Create leading directories where needed
-m, –preserve-modification-time Retain previous file modification times when creating files
-s, –swap-bytes Swap the bytes of each halfword in the files
-S, –swap-halfwords Swap the halfwords of each word (4 bytes) in the files
-b, –swap Swap both halfwords of words and bytes of halfwords in the data. Equivalent to -sS
-A, –append Append to an existing archive.

–no-absolute-filenames Create all files relative to the current directory

Examples:

Copy files named in name-list to the archive

cpio -o < name-list [> archive]

Extract files from the archive

cpio -i [< archive]

Copy files named in name-list to destination-directory

cpio -p destination-directory < name-list

Copy individual files out of rpm file,

rpm2cpio RPM_file | cpio -id individual_file(s)

copy all files & dirs in one partition to another

sudo find /home/jfo -depth -print0 | sudo cpio –null –sparse –preserve-modification-time -pvd /mnt/newhome/
-depth says search all the way to the lowest level of the folder tree
-print0 is to include file names with spaces
–null expect to receive filenames containing spaces
–preserve-modification-time keeps all the ‘last modified timestamps’ intact through the copy process
pis for pass-through or ‘by-pass the archive step’ and copy direct to destination
v is verbose - list the files copied onscreen
d specifies make-directories - create the corresponding folders in the destination folder.

==============================================================
curl
URL syntax:
http://site.{one,two,three}.com
ftp://ftp.numericals.com/file[1-100].txt
ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)
ftp://ftp.letters.com/file[a-z].txt
http://any.org/archive[1996-1999]/vol[1-4]/part{a,b,c}.html

http://www.numericals.com/file[1-100:10].txt (step by 10)

Examples:

上传文件,以mutipart/form-data post

curl -F file=@/etc/passwd www.mypasswords.com

==============================================================
sudo

-K
The -K (sure kill) option is like -k except that it removes the user’s timestamp entirely. Like -k, this option does not require a password.
-S
The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.
——————————————————————————————————
Examples:
sudo -S ls <<EOF
password
EOF
==============================================================
chkconfig
安装 脚本在Linux启动时运行
copy openvpn.sh to /etc/rc.d/init.d/openvpn
shell> chkconfig –add openvpn
shell> mkdir /etc/openvpn
make .conf or .sh files in /etc/openvpn (see below)

To uninstall:
run: chkconfig –del openvpn

==============================================================
nroff-man /usr/man/man1/cscope.1 | more
man命令不在路径中时,查看非标准的man文件

==============================================================
xargs
–null, -0
Input items are terminated by a null character instead of by whitespace, and the
quotes and backslash are not special (every character is taken literally). Disables
the end of file string, which is treated like any other argument. Useful when input
items might contain white space, quote marks, or backslashes. The GNU find -print0
option produces input suitable for this mode.
–max-args=max-args, -n max-args
Use at most max-args arguments per command line. Fewer than max-args arguments will
be used if the size (see the -s option) is exceeded, unless the -x option is given,
in which case xargs will exit.
-I replace-str
-i 表示 find 传递给xargs的结果 由{}来代替,等价于 -I{}

eg:
find ./ -type f -print | xargs -i mv -f {} ./newdir
find ./ -type f -print | xargs -I aa mv -f aa ./newdir

==============================================================
tee
Copy standard input to each FILE, and also to standard output.
eg: cat file | tee out1 out2 out3

==============================================================
run-parts
run-parts runs all the executable files named within constraints
found in directory directory.
eg: run-parts /etc/ppp/ip-up.d –arg=”$1”–arg=”$2” –arg=”$3”

==============================================================
modinfo 显示模块的详细信息
modinfo snd-atiixp

==============================================================
type bash内置命令
eg: type ls
ls 已被别名为“ls –color=auto”
ls is /bin/ls

end