Linux work note

Linux高频cmd
  • rz : 上传
  • sz : 下载
  • ls -lrt : 浏览当前目录所有文件,-lrt 按照时间正序排序
  • grep : 搜索命令
  • top : 查看服务器性能指标
  • cp sourcefile targetfile :复制
  • mv sourcefiile targetfile :剪切/重命名
  • rm -rf
  • uname -a :显示系统所有属性
  • arch : 显示系统硬件架构
  • last -5 : 查看成功登录用户信息,显示前5条
  • lastb : 查看用户不成功登录信息,参数与上面的一样
  • who : 查看已登录用户
  • df :查看磁盘使用情况
  • ln :创建文件链接
  • du :查看文件占用空间
  • find :查找文件
  • locate :定位文件位置
  • tar zcvf /tmp/test.tar.gz /home/temp
  • TODO
  • head -n 5 file :显示file的前5行
  • tail -10 file :显示file的尾几行
  • wc file :统计文件的内容
  • sort :排序
  • history : 查看历史cmd
  • wc ­ print the number of newlines, words, and bytes in files
  • TODO Linux File Permissions drwxrw-r– : d 目录 rwx ower读写执行 rw- group读写不能执行 r– 其他用户只读
  • chmod – change file access permissions
  • chown – change file owner and group
  • su –  change user ID or become super­user
  • passwd – update  a user’s authentication tokens(s) 
  • who – show who is logged on
  • ps – report a snapshot of the current processes
  • kill – to kill a process(using signal mechanism) 
  • ssh – SSH client (remote login program)  Usage: ssh [options] [user]@hostname 
  • scp – secure copy (remote file copy program) Usage: scp [options] [[user]@host1:file1] [[user]@host2:file2]
  • fdisk – partition manipulator   eg. sudo fdisk ­l
  • mount – mount a file system  Usage: mount ­t type device dir  
  • umount – unmount file systems  Usage: umount [OPTIONS] dir   device…      
  • du – estimate file space usage   Usage:  du [OPTION]… [FILE]… 
  • df – report filesystem disk space usage  Usage: df [OPTION]… [FILE]…  
  • quota – display disk usage and limits   Usage: quota [OPTION]  
  • reboot – reboot the system   Usage: reboot [OPTION]    
  • poweroff – power off the system       Usage: poweroff [OPTION]
  • bg – make a foreground process to run in background   Usage: type ’ctrl+z’  and then ’bg <job id>’  
  • fg – to make background process as foreground process       Usage: fg [jobid]
  • jobs – displays the names and ids of background jobs   Usage: jobs
  • sed ­  stream editor for filtering and transforming text Usage: sed [OPTION] [input­file]… eg. sed ’s/love/hate/g’ loveletter.txt     
  • awk ­ pattern scanning and processing language   
  • find ­ search for files in a directory hierarchy     Usage: find [OPTION] [path] [pattern]        
  • locate – find or locate a file  Usage: locate [OPTION]… FILE…    
[root@www ~]# grep [-acinv] [--color=auto] '搜寻字符串' filename
选项与参数
-a  binary 文件以 text 文件的方式搜寻数据
-c 计算找到 '搜寻字符串' 的次数
-i 忽略大小写的不同所以大小写视为相同
-n 顺便输出行号
-v 反向选择亦即显示出没有 '搜寻字符串' 内容的那一行
--color=auto 可以将找到的关键词部分加上颜色的显示喔

# grep energywise *           #在当前目录搜索带'energywise'行的文件
# grep -r energywise *        #在当前目录及其子目录下搜索'energywise'行的文件
# grep -l -r energywise *     #在当前目录及其子目录下搜索'energywise'行的文件但是不显示匹配的行只显示匹配的文件

- 显示1000行到3000行
cat filename| head -n 3000 | tail -n +1000
*注意两种方法的顺序
分解
   tail -n 1000显示最后1000行
   tail -n +1000从1000行开始显示显示1000行以后的
   head -n 1000显示前面1000行

- 用sed命令
sed -n '5,10p' filename 这样你就可以只查看文件的第5行到第10行