linux 杂记

1解压与压缩

1.以.a为扩展名的文件:
#tar xv file.a
2.以.z为扩展名的文件:
#uncompress file.Z
3.以.gz为扩展名的文件:
#gunzip file.gz
4.以.bz2为扩展名的文件:
#bunzip2 file.bz2
5.以.tar.Z为扩展名的文件:
#tar xvZf file.tar.Z 
或 #compress -dc file.tar.Z | tar xvf -
6.以.tar.gz/.tgz为扩展名的文件:
#tar xvzf file.tar.gz 
或 gzip -dc file.tar.gz | tar xvf -
7.以.tar.bz2为扩展名的文件:
#tar xvIf file.tar.bz2 
或 bzip2 -dc file.tar.bz2 | xvf -
8.以.cpio.gz/.cgz为扩展名的文件:
#gzip -dc file.cgz | cpio -div
9.以.cpio/cpio为扩展名的文件:
#cpio -div file.cpio 
或cpio -divc file.cpio
10.以.rpm为扩展名的文件安装:
#rpm -i file.rpm
11.以.rpm为扩展名的文件解压缩:
#rpm2cpio file.rpm | cpio -div
12.以.deb为扩展名的文件安装:
#dpkg -i file.deb
13.以.deb为扩展名的文件解压缩:
#dpkg-deb --fsys-tarfile file.deb | tar xvf - ar p 
file.deb data.tar.gz | tar xvzf -
14.以.zip为扩展名的文件:
#unzip file.zip

2.为什么要用/dev/null 2>&1 这样的写法.

这条命令的意思是将标准输出和错误输出全部重定向到/dev/null中,也就是将产生的所有信息丢弃.下面我就为大家来说一下, command > file 2>file   与command > file 2>&1 有什么不同的地方.
       首先~command > file 2>file 的意思是将命令所产生的标准输出信息,和错误的输出信息送到file 中.command   > file 2>file 这样的写法,stdoutstderr都直接送到file中, file会被打开两次,这样stdoutstderr会互相覆盖,这样写相当使用了FD1和FD2两个同时去抢占file 的管道.
       而command >file 2>&1 这条命令就将stdout直接送向file,stderr 继承了FD1管道后,再被送往file,此时,file 只被打开了一次,也只使用了一个管道FD1,它包括了stdoutstderr的内容.
       从IO效率上,前一条命令的效率要比后面一条的命令效率要低,所以在编写shell脚本的时候,较多的时候我们会用command > file 2>&1 这样的写法。

3 .名称 : crontab

使用权限 : 所有使用者
使用方式 :
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }
说明 :
crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类似使用者的时程表。-u user 是指设定指定 user 的时程表,这个前提是你必须要有其权限(比如说是 root)才能够指定他人的时程表。如果不使用 -u user 的话,就是表示设定自己的时程表。
餐数 :
-e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe)
-r : 删除目前的时程表
-l : 列出目前的时程表
时程表的格式如下 :
f1 f2 f3 f4 f5 program  
  
其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。program 表示要执行的程序。
当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,其馀类推
当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 a-b 时表示从第 a 到第 b 小时都要执行,其馀类推
当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其馀类推
当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小时要执行,其馀类推
使用者也可以将所有的设定先存放在档案 file 中,用 crontab file 的方式来设定时程表。
例子 :
每月每天每小时的第 0 分钟执行一次 /bin/ls :
0 7 * * * /bin/ls  
  
在 12 月内, 每天的早上 6 点到 12 点中,每隔 20 分钟执行一次 /usr/bin/backup :
0 6-12/3 * 12 * /usr/bin/backup  
  
周一到周五每天下午 5:00 寄一封信给 alex@domain.name :

0 17 * * 1-5 mail -s "hi" alex@domain.name  /dev/null 2>&1 即可

4. ls 常用参数

显示目录  ls -F | grep /$   或者   ls -l | grep “^d”    或者ls -p
-F  :根据文件、目录等资讯,给予附加数据结构,例如*:代表可运行档; /:代表目录; =:代表 socket 文件; |:代表 FIFO 文件
-p 在目录后面加上/符号
显示全部文件 ls -a
只显示文件而不显示目录:ls -l |grep ^-  
显示详细信息 ls -ld  (参数d表示将文件大小以人的可读方式列出)
-S  :以文件容量大小排序,而不是用档名排序
-t  :依时间排序,而不是用档名
-r  :将排序结果反向输出

5 ftp 客户端命令

  • ! - Runs the specified command on the local computer
  • ? - Displays descriptions for ftp commands
  • append - Appends a local file to a file on the remote computer
  • ascii - Sets the file transfer type to ASCII, the default
  • bell - Toggles a bell to ring after each file transfer command is completed (default = OFF)
  • binary - Sets the file transfer type to binary
  • bye - Ends the FTP session and exits ftp
  • cd - Changes the working directory on the remote computer
  • close - Ends the FTP session and returns to the command interpreter
  • debug - Toggles debugging (default = OFF)
  • delete - Deletes a single file on a remote computer
  • dir - Displays a list of a remote directory's files and subdirectories
  • disconnect - Disconnects from the remote computer, retaining the ftp prompt
  • get - Copies a single remote file to the local computer
  • glob - Toggles filename globbing (wildcard characters) (default = ON)
  • hash - Toggles hash-sign (#) printing for each data block transferred (default = OFF)
  • help - Displays descriptions for ftp commands
  • lcd - Changes the working directory on the local computer
  • literal - Sends arguments, verbatim, to the remote FTP server
  • ls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mdelete - Deletes one or more files on a remote computer
  • mdir - Displays a list of a remote directory's files and subdirectories
  • mget - Copies one or more remote files to the local computer
  • mkdir - Creates a remote directory
  • mls - Displays an abbreviated list of a remote directory's files and subdirectories
  • mput - Copies one or more local files to the remote computer
  • open - Connects to the specified FTP server
  • prompt - Toggles prompting (default = ON)
  • put - Copies a single local file to the remote computer
  • pwd - Displays the current directory on the remote computer (literally, "print working directory")
  • quit - Ends the FTP session with the remote computer and exits ftp (same as "bye")
  • quote - Sends arguments, verbatim, to the remote FTP server (same as "literal")
  • recv - Copies a remote file to the local computer
  • remotehelp - Displays help for remote commands
  • rename - Renames remote files
  • rmdir - Deletes a remote directory
  • send - Copies a local file to the remote computer (same as "put")
  • status - Displays the current status of FTP connections
  • trace - Toggles packet tracing (default = OFF)
  • type - Sets or displays the file transfer type (default = ASCII)
  • user - Specifes a user to the remote computer
  • verbose - Toggles verbose mode (default = ON)

5 挂接光盘

mount -r /dec/cdrom /mnt/cdrom 以只读方式挂接

chown -R owner:group file 改变文件夹所有者,递归

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值