Linux Command(cont.)
Part 1 Linux Command
退出shell,但不退出该shell启动的后台程序:
nohup ./sh &
==============================================================
pdftk
把文件 1.pdf、2.pdf 和 3.pdf 合并成一个名为 123.pdf 的新文件,参数的有效格式只能是单个的大写字母,比如 A、B、C 等。
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
pdftk A=1.pdf B=2.pdf C=3.pdf cat A B C output 123.pdf
pdftk *.pdf cat output combined.pdf
将文件 one.pdf 中的 1~7 页、two.pdf 中 1~5 页和 one.pdf 中的第 8 页分割出来, 依次合并为一个名为 combined.pdf 的新文件。
pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf
对文件 mydoc.pdf 进行修改时需要输入的密码“mypass1”(自行设定)。同时,
该命令将 mydoc.pdf 文件重新命名为了 mydoc.new.pdf。
pdftk mydoc.pdf output mydoc.new.pdf owner_pw mypass1
打开文件 mydoc.pdf 时需要输入密码“mypass2”
pdftk mydoc.pdf output mydoc.new.pdf user_pw mypass2
取消原先设定的密码
pdftk mydoc.new.pdf input_pw mypass2 output mydoc.pdf
解码 PDF 的文件流,解码后的文件可以用文本编辑器进行编辑
pdftk mydoc.pdf output mydoc.clear.pdf uncompress
==============================================================
chattr/lsattr
The letters `acdijsuADST’ select the new attributes for the files:
append only (a), compressed (c), no dump (d), immutable (i), data jour-
nalling (j), secure deletion (s), no tail-merging (t), undeletable (u),
no atime updates (A), synchronous directory updates (D), synchronous
updates (S), and top of directory hierarchy (T).
chattr +i /etc/fstab 防止文件被修改或删除
==============================================================
vmstat - Report virtual memory statistics
==============================================================
pstree display a tree of processes
-a Show command line arguments. If the command line of a process is
swapped out, that process is shown in parentheses.
-h Highlight the current process and its ancestors.
-H Like -h, but highlight the specified process instead.
-l Display long lines. By default, lines are truncated to the dis-
play width or 132 if output is sent to a non-tty or if the dis-
play width is unknown.
-p Show PIDs.
==============================================================
stty
-a, –all
print all current settings in human-readable form
-g, –save
print all current settings in a stty-readable form
eg: 设置读取单字符
stty -icanon min 1 time 0
关闭回显
stty -echo
启动回显
stty echo
==============================================================
popularity-contest - list the most popular Debian packages
The popularity-contest command gathers information about Debian pack-
ages installed on the system, and prints the name of the most recently
used executable program in that package as well as its last-accessed
time (atime) and last-attribute-changed time (ctime) to stdout.
popcon-largest-unused - List size of unused packages
Based on the list of unused packages reported by popularity-contest, this program extract the package size from the APT cache, and list the unused
packages sorted by size.
==============================================================
lsof - list open files
==============================================================
flock [-sxon] [-w timeout] lockfile [-c] command…
flock [-sxun] [-w timeout] fd
The first form wraps the lock around the executing a command, in a manner similar to su(1) or newgrp(1). It locks a specified file, which is cre-
ated (assuming appropriate permissions), if it does not already exist.
The second form is convenient inside shell scripts, and is usually used the following manner:
(
flock -s 200
… commands executed under lock …
) 200>/var/lock/mylockfile
The mode used to open the file doesn’t matter to flock; using > or >> allows the lockfile to be created if it does not already exist, however,
write permission is required; using < requires that the file already exists but only read permission is required.
By default, if the lock cannot be immediately acquired, flock waits until the lock is available.
==============================================================
checkinstall - 方便创建 deb、rpm、slackware 二进制包
–install Toggle installation of the created package.
–fstrans Enable/disable filesystem translation. Filesystem translation
enabled causes the install to proceed in a temporary direc-
tory, thus not actually touching your system.
eg:
./configure
make
sudo checkinstall -D –install=no # 仅仅生成deb包
==============================================================
tune2fs - adjust tunable filesystem parameters on ext2/ext3 filesystems
-c max-mount-counts
Adjust the number of mounts after which the filesystem will be checked
-C mount-count
Set the number of times the filesystem has been mounted.
-l List the contents of the filesystem superblock.
eg:
tune2fs -l /dev/sda5
如果想系統下一次開機略過 fsck,可以建立 /fastboot 文件
$sudo touch /fastboot
但這個 /fastboot 檔案會在開機後自動刪除,所以只可以略過一次 fsch 檢查
==============================================================
genisoimage - 制作ISO文件
eg: genisoimage cd.iso ./dir
==============================================================
sysctl - configure kernel parameters at runtime
-a Display all values currently available.
-A Display all values currently available in table form.
==============================================================
getconf - get configuration values
-a Display all configuration values.
eg:ARG_MAX, CHAR_BIT, PAGESIZE
==============================================================
lspci
-nn Show PCI vendor and device codes as both numbers and names.
==============================================================
lsof
lsof abc.txt 显示开启文件abc.txt的进程
lsof -i :22 知道22端口现在运行什么程序
lsof -c abc 显示abc进程现在打开的文件
lsof -u uid 显示用户uid的进程情况
lsof +d /usr/local/ 显示目录下被进程开启的文件
lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长
lsof -d 4 显示使用fd为4的进程
lsof -s 列出打开文件的大小,如果没有大小,则留下空白
lsof -i 用以显示符合条件的进程情况
语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]
46 –> IPv4 or IPv6
protocol –> TCP or UDP
hostname –> Internet host name
hostaddr –> IPv4位置
service –> /etc/service中的 service name (可以不只一个)
port –> 端口号 (可以不只一个)
例子: TCP:25 - TCP and port 25
@1.2.3.4 - Internet IPv4 host address 1.2.3.4
tcp@ohaha.ks.edu.tw:ftp - TCP protocol hosthaha.ks.edu.tw service name:ftp
lsof -n 不将IP转换为hostname,缺省是不加上-n参数
例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -n
lsof -p 12 看进程号为12的进程打开了哪些文件
lsof +|-r [t] 控制lsof不断重复执行,缺省是15s刷新
-r,lsof会永远不断的执行,直到收到中断信号
+r,lsof会一直执行,直到没有档案被显示
例子:不断查看目前ftp连接的情况:lsof -i tcp@ohaha.ks.edu.tw:ftp -r
==============================================================
watch - execute a program periodically, showing output fullscreen
-d, –differences highlight the differences between successive updates.
==============================================================
smbclient -L 192.168.1.1
Domain=[SERVER] OS=[Windows Server 2008 R2 Enterprise 7600] Server=[Windows Server 2008 R2 Enterprise 6.1]
Sharename Type Comment
ADMIN$ Disk 远程管理
C$ Disk 默认共享
D$ Disk 默认共享
DRIVER Disk
F$ Disk 默认共享
PICTURE Disk
print$ Disk 打印机驱动程序
SOFTWARE Disk
mount -t smbfs -o iocharset=utf8 -o username=user,password=passwd //192.168.1.1/SOFTWARE /mnt
==============================================================
continue