Tag Info

Hot answers tagged

8

The second example: find . -name *.txt -print0 | xargs -0 cat > out.txt Is completely legal and will recreate the file, out.txt each time it's run, while the first will concatenate to out.txt if it runs. But both commands are doing essentially the same thing. What's confusing the issue is the xargs -0 cat. People think that the redirect to out.txt is ...


4

Using awk is not so complicated: find . -name '*.c' -type f | awk -F/ '{print $NF}' Or sed: find . -name '*.c' -type f | sed 's|.*/||' (assuming file names don't contain newline characters) and that will work with any find implementation.


4

What is the purpose of having these two operators then? That's an easy one: Because there are different use cases. Sometimes it is useful to truncate the target file to size 0 first, sometimes (e.g. log files) it makes more sense to append data to a file. In this case it makes no sense to append. You want a file with exactly the content of the files ...


2

You can't really influence environment "horizontally" in the pipe - the processes in a ... p_n | p_n+1 | p_n+2 ... pipe are spawned by the same shell interpreter, hence there is no way to change environment variable of say p_n from p_m, echii is in the same pipeline. If you just need to do a simple transformation of the filenames, which can be achieved with ...


2

chmod -R o-w . Will remove write permissions to others for every file in a safe way. It will however update the ctime of every file including the ones for which others already didn't have write access. With GNU chmod, you can make it show which files needed updated with the -c option: $ chmod -cR o-w . mode of `./a' changed from 0777 (rwxrwxrwx) to 0775 ...


1

I would go with the second one. The redirect of stdout gets caught by bash when you hit enter, so it's not like you create a new redirect for every line of find/xargs (which might have been their thinking). If out.txt doesn't exist they should be identical, if it already has data, then the second one at least resets the file to known content (that is, no ...


1

Your approach is a performance nightmare: You create two processes for every file! One completely uselessly because find already has this information and can easily print it. This is a better solution: find . -perm -o=rwx -printf "%m %p_\0" 2>/dev/null | while read -r -d '' perms path; do path="${path%_}" echo "${perms} '${path}'" >&2 ...


1

/007 will show your only files that have no permissions for owner and group, and all permissiosn (rwx) for other. You might have more luck with /o=rwx. That will match only the other permissions for the file. EDIT FOR CORRECTNESS: Apparently, you'll need to use -perm -o=rwx, because the /o is an inclusive filter, and would match files where other has ...



Only top voted, non community-wiki answers of a minimum length are eligible