【tar命令】
[xqzhang@PEKdev032 ~]$ tar --help
Usage: tar [OPTION...] [FILE]...
GNU `tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
Main operation mode:
-A, --catenate, --concatenate append tar files to an archive
-c, --create create a new archive
-d, --diff, --compare find differences between archive and file system
--delete delete from the archive (not on mag tapes!)
-r, --append append files to the end of an archive
-t, --list list the contents of an archive
--test-label test the archive volume label and exit
-u, --update only append files newer than copy in archive
-x, --extract, --get extract files from an archive
Usage: tar [OPTION...] [FILE]...
GNU `tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.
Examples:
tar -cf archive.tar foo bar # Create archive.tar from files foo and bar.
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xf archive.tar # Extract all files from archive.tar.
Main operation mode:
-A, --catenate, --concatenate append tar files to an archive
-c, --create create a new archive
-d, --diff, --compare find differences between archive and file system
--delete delete from the archive (not on mag tapes!)
-r, --append append files to the end of an archive
-t, --list list the contents of an archive
--test-label test the archive volume label and exit
-u, --update only append files newer than copy in archive
-x, --extract, --get extract files from an archive
Compression options:
-j, --bzip2 filter the archive through bzip2
-z, --gzip, --gunzip, --ungzip filter the archive through gzip
Device selection and switching:
-f, --file=ARCHIVE use archive file or device ARCHIVE
--force-local archive file is local even if it has a colon
-f, --file=ARCHIVE use archive file or device ARCHIVE
--force-local archive file is local even if it has a colon
Informative output:
-v, --verbose verbosely list files processed
--warning=KEYWORD warning control
--warning=KEYWORD warning control
tar -zxvf aerospike-server-community-3.5.9.tar.gz && cd aerospike-server
$ tar -xvf /archives/got-it-off-the-net.tar.gz
$ tar xf foo.tar '*.c'
Ch7 【Linux文件与目录管理】
ch7.1【目录与路径】
【绝对路径用途】在写程序(shell scripts)来管理系统的条件下, 务必使用绝对路径的写法。
【命令】
cd:切换工作目录,是Change Directory的缩写。
pwd:显示当前目录,是Print Working Directory的缩写。
-P取得正确的完整路径名,而不是以连接文件的路径显示。
mkdir:新建一个目录。-p递归创建
rmdir:删除一个目录。
-p递归删除(rm -r也可以)
【特殊的目录,记下来】
. 代表此层目录
.. 代表上一层目录
- 代表 前一个工作目录
~ 代表 当前用户的 主文件夹
~account 代表account这个用户的主文件夹
【执行文件路径的变量:$PATH】
命令:echo $PATH root用户输出:... :/sbin:/bin: ...
普通用户查看网络配置:/sbin/ifconfig eth0,普通用户$PATH没有设置/sbin
变量赋值:$PATH="$PATH":/root
为安全起见,不建议将“.”加入PATH的查询目录中。
Ch7.2【文件与目录管理】
查看文件与目录:ls
。默认以文件名排名。常用选项——
-a:全部文件,包括隐藏文件;
-d:仅列出目录本身,不列文件内数据;
-h:文件大小以人类 易读方式列出(GB,KB等)
-l : 列出长数据串,包括文件的属性与权限等。
【复制、删除与移动:cp、rm、mv】
复制文件:cp(copy) 源文件 目标文件
-a:相当于-pdr的意思;
-p:连通文件属性 一起复制;
-d:源文件为连接文件 则复制连接文件的属性;(link file软件连接)
-r :递归持续复制,用于目录的复制;
-i :目标文件已存在,询问是否覆盖;
-l :创建硬连接文件,而非复制文件本身。
删除文件或目录:rm(remove)
-r:递归删除。
移动文件与目录,或更名:mv(move)
eg:mv bashrc1 bashrc2 mvtest2 // 最后一个一定是目录。
Ch7.3【文件内容查阅】
cat:全部内容 一次显示。(Concatenate连续)
more:逐页显示,空格下一页。
less:逐页显示,但可以往前翻页,[PageDown]、[PageUp]
od:二进制方式 显示。
修改文件时间或创建新文件:touch
eg:touch testtouch; ls -l testtoush
新建一个文件,分号代表连续命令的执行,文件没有则新建,时间更新为当前时间。
Ch7.4【文件与目录的默认权限 与隐藏权限】
【文件默认权限:umask】
user mask:用户屏蔽码,屏蔽的权限。
$umask 显示屏蔽码,后三位为rwx,第一位为特殊权限;
$umask 002 设置屏蔽码;
$umask -S 以符号形式(Symbolic)显示权限。
【文件隐藏属性:chattr,lsattr】
设置文件的隐藏属性:charttr [+-=] [ai] 文件或目录名称
+:增加,-删除,=仅有后面的,即赋值;
a:只能增加数据(eg:log文件),i:只能读数据(eg:共享文件)。只有root能设置。
【实例:】chattr +ai attrtest; lsattr attrtest
【实例:】chown 4666 testsuid 使文件具有设置权限(4),
执行时将进程的有效用户ID 设置为文件所有者。
【显示文件 所使用的磁盘空间总量】du [OPTION]... [FILE]...
DU(1) User Commands
Summarize disk usage of each FILE, recursively for directories.
-s, --summarize
display only a total for each argument