xargs

linux中常用命令

风格不统一 提交于 2019-11-28 15:35:27
平时的积累,记录的比较散: ls -lrt ls -t按照时间顺序显示文件列表,r 最新的再最后面 more:显示文件(文本)的内容(分屏显示) less:显示文件(文本)的内容(分屏显示、可回溯) sort:对文本文件中的各行按字母进行排序 ls | sort wc: wc [选项] 文件列表 统计指定文件中的字节数(-c)、字数(-w)、行数(-l), 并将统计结果显示输出。 cat xx | wc -l echo $HOME 来查看自己的主目录 . 当前目录 ..上一级目录 ~当前用户主目录 /文件系统根目录 chmod 设置文件/目录的权限 chmod [选项] 文件和目录列表 使用八进制数设置权限三位八进制数字分别代表:u(user:用户)、g(group:组用户)、o(other:其他用户)的权限。可读权限、可写权限和可执行权限所对应的数值分别是4,2和1。 若要rwx属性则4+2+1=7; 若要rw-属性则4+2=6; 若要r-x属性则4+1=5 如:chmod 755 file1 chown:改变文件和目录的所有权 chgrp:改变文件和目录的所有权 find find . -maxdepth 1 -name "@*" 这个命令意思是,查找当前目录下以@开头的文件或者目录,搜索深度为一级也就是只在当前目录找,不进入子目录,如果你要从/目录开始找就: find /

重定向与管道

你。 提交于 2019-11-28 15:19:00
1.重定向概述 1.1什么是重定向 将原本要输出到屏幕的数据信息,重新定向到某个指定的文件中 名称 文件描述符 作用 标准输入(STDIN) 0 默认是键盘,也可以是文件或其他命令的输出。 标准输出(STDOUT) 1 默认输出到屏幕。 错误输出(STDERR) 2 默认输出到屏幕。 1.2进程将从标准输入中得到数据,将正常输出打印至屏幕终端,将错误的输出信息也打印至屏幕终端 以 cat 命令为例, cat 命令的功能是从命令行给出的文件中读取数据,并将这些数据直接送到标准输出。若使用如下命令: `[root@chengyinwu ~]# cat /etc/passwd` 但如果 使用 cat 命令没有跟上输入的文件名,那么cat命令则会通过命令行标准输入中读取数据, 并将其送到标准输出 [root@chengyinwu ~]# cat hello 标准输入 hello 标准输出 ^C - 用户输入的每一行都立刻被cat命令输出到屏幕上 1.3 持续追踪查看文件内容 [root@chengyinwu ~]# tail -f /etc/passwd ctrl+z 将进程转到后台 1.4 查看运行的进程 [root@chengyinwu ~]# ps PID TTY TIME CMD 5848 pts/1 00:00:00 bash 6885 pts/1 00:00:00 tail

文件查找-find命令

倖福魔咒の 提交于 2019-11-28 15:18:40
find 命令的基本语法如下: 命令 路径 选项 表达式 动作 find [path...] [options] [expression] [action] 查找 地区 妹纸 18-25岁 约? (1) 按名称查找 1.按照名称进行查找 [root@yinwucheng ~]# find ./ -name "*eth0" 2.按照名称查找(不区分大小写) [root@yinwucheng ~]# find ./ -iname "*eth0" (2) 按文件大小查找 size 1.查找/etc/目录下大于5M的文件 [root@yinwucheng ~]# find /etc/ -size +5M 2.查找/etc/目录下小于5M的文件 [root@yinwucheng ~]# find /etc/ -size -5M 3.查找/etc/目录下等于5M的文件 [root@yinwucheng ~]# find /etc/ -size 5M (3)按文件类型查找 -type f 文件 d 目录 s socket套接字文件 l 链接文件 c 字符设备 b 块设备 1.查找当前目录下类型是文件的,并且名称跟eth0相关的都列出来 [root@yinwucheng~]# find ./ -type f -iname "*eth0" |xargs ls -l 2.查找/etc

How to use > in an xargs command?

↘锁芯ラ 提交于 2019-11-28 14:58:26
I want to find a bash command that will let me grep every file in a directory and write the output of that grep to a separate file. My guess would have been to do something like this ls -1 | xargs -I{} "grep ABC '{}' > '{}'.out" but, as far as I know, xargs doesn't like the double-quotes. If I remove the double-quotes, however, then the command redirects the output of the entire command to a single file called '{}'.out instead of to a series of individual files. Does anyone know of a way to do this using xargs? I just used this grep scenario as an example to illustrate my problem with xargs so

Linux基础之输入输出

天大地大妈咪最大 提交于 2019-11-28 11:23:40
第十五章 输入输出 一、重定向概述 1.1、什么是重定向? 将原本要输出到屏幕的数据信息,重新定向到指定的文件中。 比如:每天凌晨定时备份数据,希望将备份数据的结果保存到某个文件中。这样第二天通过查看结果文件,就知道昨天备份数据是成功还是失败。 1.2、为何要使用重定向? 1)当屏幕输出的信息很重要,而且希望保存重要的信息的时候。 2)后台执行中的程序,不希望它干扰屏幕的正常输出结果的时候。 3)系统的例行命令,比如定时任务的执行结果,希望它可以存下来的时候。 4)一些执行命令,我们已经知道它可能出现错误信息,想将它直接丢弃的时候。 5)执行一个命令,可能报错输出和正确输出并存,类似错误日志与正确日志需要分别输出到不同的文件的时候。 1.3、学习重定向的预备知识,标准输入与输出 当运行一个 shell 程序时通常会自动打开三个标准文件,分别是标准输入、标准输出、错误输出。 1.4、标准输入与输出 执行一个shell程序时通常会自动打开三个文件描述符 名称 文件描述符 作用 标准输入(stdin) 0 通常是键盘,也可以是其他文件或者命令的输出。 标准输出(stdout) 1 默认输出到屏幕。 错误输出(stderr) 2 默认输出到屏幕。 文件名称(filename) 3+ 进程将从标准输入中得到数据,将正常输出打印至屏幕终端,将错误的输出信息也打印至屏幕终端。进程是使用文件描述符

Unix - “xargs” - output “in the middle” (not at the end!)

烈酒焚心 提交于 2019-11-28 07:24:27
问题 example use of xargs application in Unix can be something like this: ls | xargs echo which is the same as (let's say I have someFile and someDir/ in the working directory): echo someFile someDir so xargs take its input and place it at the end of the next command (here at the end of echo). But sometimes I want xargs to place its input somewhere in the middle of next command. For example: find . -type f -name "*.cpp" -print | xargs g++ -o outputFile so if I had in the current directory files a

xargs、sort、uniq命令

為{幸葍}努か 提交于 2019-11-28 06:29:02
xargs、sort、uniq命令,我们由LeetCode的一道题来引入,并使用加以理解; 题目是这样的:写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。 words.txt的内容为: the day is sunny the the the sunny is is 1.cat words.txt | sort 来看下会是什么效果 [root@Server-n93yom tmp]# cat words.txt | sort the day is sunny the the the sunny is is sort 命令将以默认的方式将文本文件的第一列以ASCII 码的次序排列,并将结果输出到标准输出。 2.使用 cat words.txt | xargs -n1 | sort | uniq -c 看下是什么效果 [root@Server-n93yom tmp]# cat words.txt | xargs -n1 | sort | uniq -c 1 day 3 is 2 sunny 4 the uniq命令只能对相邻行进行去重复操作,所以在进行去重前,先要对文本行进行排序,使重复行集中到一起,这就是为什么要先sort的原因;-c 是统计数量 3.使用 cat words.txt | xargs -n1 | sort | uniq -c |

ct lsco -a -s -cview | xargs ct ci -nc (Clearcase multiple files check-in)

只愿长相守 提交于 2019-11-28 06:12:22
问题 I get error while running this command on linux. ct lsco -a -s -cview | xargs ct ci -nc ( ct is for cleartool ) xargs: ct: No such file or directory How can I avoid this error? 回答1: Don't use the alias ' ct ' with xargs . Use cleartool . As explained in "xargs doesn't recognize bash aliases": This doesn't work because xargs expects to be able to exec the program given as its parameter. Since ct in your case is just a bash alias or function there's no program to execute. More details in "How

Is there a grep equivalent for find's -print0 and xargs's -0 switches?

不打扰是莪最后的温柔 提交于 2019-11-28 05:15:22
I often want to write commands like this (in zsh , if it's relevant): find <somebasedirectory> | \ grep stringinfilenamesIwant | \ grep -v stringinfilesnamesIdont | \ xargs dosomecommand (or more complex combinations of greps) In recent years find has added the -print0 switch, and xargs has added -0 , which allow handling of files with spaces in the name in an elegant way by null-terminating filenames instead, allowing for this: find <somebasedirectory> -print0 | xargs -0 dosomecommand However, grep (at least the version I have, GNU grep 2.10 on Ubuntu), doesn't seem to have an equivalent to

Using grep to search for hex strings in a file

我与影子孤独终老i 提交于 2019-11-28 04:58:57
I have been trying all day to get this to work. Does anyone know how to get grep, or something of the like, to retrieve offsets of hex strings in a file? I have a bunch of hexdumps that I need to check for strings and then run again and check if the value has changed. I have tried hexdump and dd, but the problem is because it's a stream, I lose my offset for the files. Someone must have had this problem and a workaround. What can I do? To clarify, I have a series of dumped memory regions from GDB. I am trying to narrow down a number by searching out all the places the number is stored, then