您的位置:首页 > 运维架构 > Linux

Linux日常及文件管理命令

2017-02-22 07:22 295 查看
文件属性等:chmod
 
chgrp : 改变文件所属群(change group)
chown :改变文件所属人
chmod :改变文件的属性、 SUID 、等等的特性
-------------------------------------------------------------
chmod:
         -rwxrwxrwx: r-4, w-2, x-1;
         -rwx rwx --- 7 7 0 (owner, group, others);
E:
chmod 755 test.sh (rwx r-x r-x);
 
u, g, o, a  (user, group, others, all)(用户,组,其他人,全部【以上】)
 
权限修改:
         +, -, = (加, 减,等于)
 
得出:
         chmod u=rwx,og=rx myfile (rwxr-xr-x)
         chmod a+w myfile (都加写操作)
         chmod a-x myfile (都减去执行操作)
        
 
-------------------------------------------------------------
 
目录说明:
/bin  存放命令(ls, mv, rm, mkdir, rmdir, gzip, tar, telnet, 及 ftp 等等常用的执行档的地方)
/boot        linux核心与开机相关档案
/dev 装置有关档案
/etc  开机过程需要读取的档案 (如 Lilo 的参数、人员的账号与密码、系统的主要设定、http 架站的参数内容、你所要开启的服务项目等等)
--------------------------------------------------------------------------------
 
文件与目录管理
.                当前目录
..           上层目录
~               自己家目录
~user        到 user 这个人的家目录
 
 
cd:            变换目录
pwd:         显示当前目录         pwd
mkdir:       建立目录         mkdir -p test1/test2/test3      mkdir -m 711 test 建立权限为 711 目录
rmdir:       删除目录         rmdir -p test1/test2/test3
 
---------------------------------------------------------------------------------
 
环境变量path
         echo $PATH
         (/bin 在 PATH 的设定之中,所以自然就可以找的到 ls )
 
         PATH="$PATH":/root (root 加入path)
 
------------------------------------------------------------------
 
        
ls:     显示文件名称
cp:          复制文件、目录
rm:   删除文件、目录
mv:  移动文件、目录
 
ls:     ls [-ailS]
         -a      全部的档案     -i       印inode值
         -l       显示大小等     -S      大小排序
ls -al;                  ls -al | more;             ll
 
cp:    [-drsu] [来源档] [目的档]
         -d                        -r      可以进行目录的copy
         -s      做成连结档,不是copy,与ln 相同
         -u      如果来源文件比较新,或没有目的档,才copy ;
 
         cp test test2             将 test复制 成 test2
         cp -r /bin /tmp/bin   copy整个目录
         cp -s file file2    是建立 file2 快捷文件吗?
         cp -u /home/file file 先检查/home/file是否与 file 不同,不同话就copy一分 相同不做处理
 
rm:   [-fir] filename (f强力杀掉,i提供使用者确认,r循环)
         rm -rf /
 
mv:  [-u] [来源档] [目的档]
         -u 为 update 的简写,当来源档比目的档还新的时后才会动作
         mv myfile file
         mv myfile myfile.old
         mv myfile myfile2 /tmp 将 myfile myfile2移动到/tmp目录
 
basename: [目录]
         basename /usr/local/etc  结果:etc (将一个目录或档案的最后一个咚咚秀出来)
 
dirname [目录]
         dirname /usr/local/etc   结果:/usr/local 与 basename相反
 
////////////////////////////////////////////////////////////////////////////////////
 
二。观看文件内容:cat, tac, more, less, head, tail, nl,
 
         cat   第一行开始显示
         tac   最后一行开始显示
         more         一页一页显示
         less  与more类似,却更好,可以往前翻页
         head         只看前面几行
         tail   只看尾巴几行
         nl      显示行号
         od     以二进制读取
 
cat: [-nAE]        (n行号,A列出<TAB> 与换行符, E列出换行符)
         cat myfile -n
         cat -A myfile
 
tac: [文件名]
         tac myfile
 
more:       [文件名]
         more myfile
         ls -al | more 一页一页显示ls的内容
 
less: [文件名]
         less myfile        可【pageup,pagedown翻页】
 
         less /etc/man.config -> /word: (在man.config中搜找 word 字符串所在)
                                     q: 离开
 
head: [-n number] [文件名]
         head -n 20 myfile 显示前20行
 
tail: [-n number] [文件名]
         tail -n 20 myfile 显示最后20行
         tail -f myfile 连续显示
 
nl: [文件名]
         nl myfile
 
od: [文件名]
         od myfile
 
////////////////////////////////////////////////////////////////////////////////
查找搜索文件、目录
 
which:                查看可执行文件位置
whereis:  查看文件位置
locate:               配合数据库查看文件位置
find:          搜索硬盘查询文件名
 
which:
         which [文件名]
         which myfile/myfile.txt 可能不在path环境变量的,要指定路径?
         which passwd
 
find: [路径] [参数]
         1. 时间:
                   -atime n -> 在n*24小时内被access 存取过的文件
                   -ctime n -> 在n*24小时内被changed 改变、新增的文件,目录
                   -mtime n -> 在n*24小时内被modified 修改过的文件
                   -newer file -> 比 file 还要新的档案就列出来
        
         2.使用名称:
                   -gid n -> 查找群组id为n 的档案
                   -group name 查找群组名称为name的文件
                   -uid n 找查拥有者id为n的文件
                   -user name
                   -name file 查找文件名为:file 的文件
                   -type  type  查找文件属性为 type的档案 b, c, d, p, l, s
        
         find / -name test
         find / -name 'test*' 查找文件名包含test的文件
         find . -ctime 1 查找当前目录一天内新增的目录、文件
         find /home/test -newer .myfile 查找 test目录 下比 .myfile新的文件
         find /home -user test 查找home下 拥有者为test的文件、目录
         find /dev -type b
 
//////////////////////////////////////////////////////////////////////////////////
 
四、压缩、解压、备份
 
tar dd
 
tar: [-cxtzjvfpPN] 档案目录……
         c ->   建立压缩
         x ->   解压缩
         t ->   查看tarfile 里的档案
                   c\x\t不能同时存在
         z ->   是否有gzip的属性,是需要用gzip压缩
         j ->    是否有bzip属性。。。
         v ->   压缩、解压里显示文件名
         f ->   使用档名,tar  f 之后要立即接档名  错:-zcvfP tfile sfile,对:-zcvPf tfile sfile
         P ->  使用原文件的原来属性
         N ->  比后面接的日期(yyyy/mm/dd)要新的才打包
 
E:
         tar -cvf /tmp/etc.tar /etc 仅打包,不压缩
         tar -zcvf /tmp/etc/tar.gz /etc 打包后,以gzip压缩
         tar -jcvf /tmp/ect.tar.bz2 / etc 打包后以bzip2压缩
 
         查看 /tmp/etc/tar.gz 档案有哪些
         tar -ztvf /tmp/etc/tar.gz
 
         将/tmp/etc/tar.gz 解压 到 /usr/local/src
         cd /usr/local/src
         tar -zxvf /tmp/etc.tar.gz
 
         在/tmp底下,只将 /tmp/etc/tar.gz 内的 etc/passwd 解开
         cd /tmp
         tar -zxvf /tmp/etc.tar.gz etc/passwd
 
--------------------------------------------------------------------------------
          tar -zcvf Web.zip
          unzip Web.zip  解压
          解压到另外的目录,如cc: tar zxvf ab.tar.gz -C cc  写全路径也行 tar zxvf ab.tar.gz -C /home/cc
          常用格式:
 
         单个文件压缩打包 tar czvf my.tar file1
         多个文件压缩打包 tar czvf my.tar file1 file2,...
         单个目录压缩打包 tar czvf my.tar dir1
         多个目录压缩打包 tar czvf my.tar dir1 dir2
         解包至当前目录:tar xzvf my.tar

unzip -od /app/oa/web  WEB-INF.zip  
o覆盖自动确认
 
 
        
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: