您现在的位置: 主页 > 嵌入式操作系统 > Linux > linux命令 > linux常用的命令
本文所属标签:
为本文创立个标签吧:

linux常用的命令

来源:网络整理 网络用户发布,如有版权联系网管删除 2018-07-03 

soso_tc_slider_img

  主要记录在日常生活中遇到的问题,进行记录:

linux中文件中存在^M 
使用shell命令tr可以实现去除,具体命令如下:
  cat-v yourfile | tr -d"^M"> targetfile

  VIM中选定某个单词
  在ESC之后,使用w或者wi或者vwi可以选择某个单词

  在控制台中快速移动光标
  1.删除
  1.1 ctrl + d 删除光标所在位置上的字符相当于VIM里x或者dl
  1.2 ctrl + h 删除光标所在位置前的字符相当于VIM里hx或者dh
  1.3 ctrl + k 删除光标后面所有字符相当于VIM里d,shift+$ 
  1.4 ctrl + u 删除光标前面所有字符相当于VIM里d,shift+^
  1.5 ctrl + w 删除光标前一个单词相当于VIM里db
  1.6 ctrl + y 恢复ctrl+u上次执行时删除的字符
  1.7 ctrl + ? 撤消前一次输入
  1.8 alt + r 撤消前一次动作
  1.9 alt + d 删除光标所在位置的后单词
  2.移动
  2.1 ctrl + a 将光标移动到命令行开头相当于VIM里shift+^
  2.2 ctrl + e 将光标移动到命令行结尾处相当于VIM里shift+$
  2.3 ctrl + f 光标向后移动一个字符相当于VIM里l
  2.4 ctrl + b 光标向前移动一个字符相当于VIM里h
  2.5 ctrl + 方向键左键 光标移动到前一个单词开头
  2.6 ctrl + 方向键右键 光标移动到后一个单词结尾
  2.7 ctrl + x 在上次光标所在字符和当前光标所在字符之间跳转
  2.8 在vim中的命令输入模式中,输入gg,可以快速跳转到文件开头
  2.9 在vim中的命令输入模式中,输入GG,可以快速跳转到文件结尾
  3.0 在vim中返回上一个的编辑的位置,在输入命令模式使用 ctrl+o
  3.1 在vim中返回下一个的编辑的位置,在输入命令模式使用 ctrl+i
  3.统计
  3.1 例如在vim中统计某个字符串的数量,可以使用命令

:%s/Name//gn 1

  防止被某个文件被删除
  1.使用一个shell命令来防止文件下的文件不能被删除

sudo chattr +a Downloads 
cd Downloads 
rm Ngix.pdf 
mv: cannot move ‘Ngix.pdf’ to ‘/home/gpx/.trash/Ngix.pdf’: Operation not permitted 
sudo rm Ngix.pdf 
rm: cannot remove ‘Ngix.pdf’: Operation not permitted

  2.使用alias命令来去除rm

alias rm='rm -i' 
or 
alias rm=trash 
trash() 

  mv"$@" trash/ 

or 
alias rm='cp $@ ~/backup; rm $@'
数据同步命令
#!/bin/sh 
date -d'now' > /mnt/hd/data/log/rsync.log  
index=1 
while : 
do 
  rsync -azvh --compress-level=0 --progress gpx@ip:/mnt/hd/data/PriceAdj_data/ /mnt/hd/data/PriceAdj_data/ >> /mnt/hd/data/log/rsync.log 
if [ $? -ne0 ];then 
  sleep5m 
else 
break 
fi 
let"index++" 
if [ $index-eq5 ];then 
  curl-d"operator=alert&phone=number&msg=rsync-dell-data-Failed""http://ip:port/sendmessage" 
echo"rsync data Failed !" >> /mnt/hd/data/log/rsync.log 
exit1 
fi 
done 
date -d'now' > /mnt/hd/data/log/log_save_dateData.log  
nohup python /mnt/hd/data/code/load_Today_Data.py >> /mnt/hd/data/log/log_save_dateData.log
linux中去除文件中的重复行
sort -n Yourfile | uniq > save_path
更新Linux系统时间
sudo ntpdate cn.pool.ntp.org

  亚洲地区的ntp服务器
  1. Bangladesh  bd.pool.ntp.org
  2. China  cn.pool.ntp.org
  3. Hong Kong  hk.pool.ntp.org
  4. India  in.pool.ntp.org
  5. Indonesia  id.pool.ntp.org
  6. Iran  ir.pool.ntp.org
  7. Israel  il.pool.ntp.org
  8. Japan  jp.pool.ntp.org
  9. Korea  kr.pool.ntp.org
  10. Malaysia  my.pool.ntp.org
  11. Philippines  ph.pool.ntp.org
  12. Singapore  sg.pool.ntp.org
  13. Taiwan  tw.pool.ntp.org
  14. Thailand  th.pool.ntp.org
  15. Turkey  tr.pool.ntp.org
  16. United Arab Emirates  ae.pool.ntp.org

在vim中进行完整单词的匹配
使用命令行输入模式 
/<这里输入你要匹配的单词> 
如果在单文件中使用进行查找和匹配 
直接使用在命令输入模式下 对某个单词使用 *
使用scp和rsync进行数据的内网数据传输和备份
rsync -azvh --delete --compress-level=0 --progress username@hostname(ip):file_path  save_path >> log_path 
参数解释: 
-v: 
--verbose               increase verbosity 
--info=FLAGS            fine-grained informational verbosity 
--debug=FLAGS           fine-grained debug verbosity 
--msgs2stderr           special output handling for debugging 
-a: 
--archive               archive mode; equals -rlptgoD (no -H,-A,-X) 
--no-OPTION             turn off an implied OPTION (e.g. --no-D) 
  -z: 
--compress              compress file data during the transfer 
--compress-level=NUM    explicitly set compression level 
--skip-compress=LIST    skip compressing files with suffix inLIST 
-h: 
--human-readable        output numbers in a human-readable format 
--progress              show progress during transfer 
--delete                delete extraneous files from dest dirs
scp mode remote_username@remote_hostname(or ip):remote_file_path dest_file_path >> run_log_path 
example: 
name@host:/mnt/hd/data/code/shell$  scp sql_rsync.sh name@host:/tmp/ 
name@host's password: 
sql_rsync.sh                                                                                                                                                100%  149     0.2KB/s   00:00 
name@host:/mnt/hd/data/code/shell$ 




              查看评论 回复



 使用 命令 光标

"linux常用的命令"的相关文章

网站地图

围观()