Hot answers tagged

14

1) Borrowing from don_crissti's answer using tee, without dd or bashisms: sudo tee /dev/disk2 /dev/disk3 > /dev/disk4 < masi.img 2) Using pee from Debian's moreutils package: sudo dd if=masi.img | \ pee "dd of=/dev/disk2" "dd of=/dev/disk3" "dd of=/dev/disk4" With either method the number of output disks can be extended indefinitely.


11

You could try dcfldd It's an enhanced version of gnu dd and it can output to multiple files or disks at the same time: dcfldd if=masi.img of=/dev/disk2 of=/dev/disk3 of=/dev/disk4


6

As others have explained, using inotify is the better solution. I'll just explain why your script fails. First of all, no matter what language you are programming in, whenever you try to debug something, the first rule is "print all the variables": $ ls file1 file2 file3 $ echo $PWD /home/terdon/foo $ for FILE in "${PWD}/*"; do echo "$FILE"; done ...


4

This is referring to the fact that Linux (like all Unix-style systems) exposes most of the resources it manages through objects which look like files: /dev-style devices, /proc and /sys entries... In the context of your quote, this property is mentioned because it allows access permissions to be reasoned about in a consistent fashion.


4

Do man xargs and look at the -I flag. find /path/to/directory -type f -exec grep -il "your pattern" {} \; | xargs -I % cp % /dest/dir/ To save typing put this command in shell script : #!/usr/bin/ksh # Script name: locate find /path/to/directory -type f -exec grep -il "$1" {} \; | xargs -I % cp % /dest/dir/ To run type locate searchstring where ...


3

Something like this: vimdiff <(find /home/masi -printf "%P %u:%g %m\n" | sort) <(find /home/masi_backup -printf "%P %u:%g %m\n" | sort) (this gives names without the leading /home/masi or /home/masi_backup, owning user and group, and permissions — the latter weren't mentioned in the question but seem useful, drop %m if you don't want them).


2

No, you can't. At least not directly. tar doesn't do any compression. It merely reads part of the (virtual) file system, and generates one cohesive stream from it. This stream is then often passed to a compression tool/library, for instance gzip/libz. The compression part does not see or even know about individual files. It just compresses the stream ...


2

The seeming challenges of the question / request is perhaps the recursion aspect. Assuming that cmp is an adequate utility and that both folder / directories 1 & 2 to be compared are of the same structure (ie same files & folders) and reside within the same root path - you can try something similar to: #!/bin/bash ROOT=$PWD ; # #// change to ...


2

If files are exactly the same, then their md5sums will be exactly the same, so you can use: find A/ B/ -type f -exec md5sum {} + | sort | uniq -w32 -D An md5sum is always exactly 128 bits (or 16 bytes or 32 hex digits) long, and the md5sum program output uses hex digits. So we use the -w32 option on the uniq command to compare only the first 32 ...


2

You can use the inotify-tools package to monitor all changes in a folder in real time. For example, it contains the inotifywait tool, which you could use like : > inotifywait /tmp Setting up watches. Watches established. /tmp/ MODIFY test You can use flags to filter certain events only or certain files. The inotifywatch tool collects filesystem ...


2

You can use inotify-tools definitely from command line, e.g. like this : inotifywait -r -m /dir/to/monitor/ From man inotifywait -m, --monitor Instead of exiting after receiving a single event, execute indefinitely. The default behaviour is to exit after the first event occurs. And here is a script that monitors continously, copied from the man ...


1

I think this will get you close. It will list out the cmp output for all files named results in A compared to all files named results in B. find ./A -name results | xargs -I REPLACESTR find ./B -name results -exec cmp REPLACESTR {} \;


1

You need to cd out of each subdirectory before trying the next one. Inserting... cd .. at the end of the loop would fix this for the subdirectories, but breaks when you do it in the top directory first. A cd .. from there will take you up another level, so the other directories aren't visible any more. You can address all of this by saving the top ...


1

Per your comments, you only have to descend one level deep. In that case you could use a glob to iterate over directories names and for each dir save file paths in an array, then print the last element of each path to fileNames.txt: #!/bin/sh for dir in "$PWD"/*/; do arr=( "$dir"* ) printf %s\\n "${arr[@]##*/}" > "$dir"filesNames.txt done To exclude ...


1

If you want to monitor on a two second interval you can surround your check with: while true do <your steps> sleep 2 done While this will sequentially test for files and will wait 2 seconds for each file found I suggest to transform your check into a function: function _check_file() { SUM1=$(md5sum "$@") sleep 2 SUM2=$(md5sum ...


1

startheader=$(head -1 sourcefile) endheader=$(tail -1 sourcefile) # above lines assume your sourcefile has two lines in it and # each line contains the starting header and ending header startlinenumber=$(grep -n "${startheader}" datafile|cut -d: -f1) endlinenumber=$(grep -n "${endheader}" datafile|cut -d: -f1) sed -n -e ...


1

With xargs you could run: <infile xargs -I {} mv gre_6_c1_{}.h3 /path/to/another/dir Or, with gnu parallel: cat infile | parallel mv gre_6_c1_{}.h3 /path/to/another/dir


1

One way with find and install: find /var/public/voicelogging/quality_monitoring -name \*.WAV -exec sh -c ' bn=${0##*/}; x=${bn%%-*}; dt=${x##*_}; y=${bn%_*}; id=${y##*_} install -D "$0" "/home/username/logging/${id}/${dt}/${bn}"' {} \; this uses parameter expansion to extract the date: ${dt} and the user id: ${id} from the filename and then uses install ...


1

Your case statement could look like this S*) echo Starts with S if [[ -f x && -f x.csv ]] then echo File x and x.csv exist else echo input file missing fi ;;



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