Tag Info

Hot answers tagged

7

You can use : find . -type f -printf '%p::' | sed 's/::$/\n/' The -printf predicate of find will print the file names in a single line delimited by :: and then sed will substitute the last :: with a newline. Example : $ find . -type f -printf '%p\n' ./foo ./test ./bar $ find . -type f -printf '%p::' | sed 's/::$/\n/' ./foo::./test::./bar


6

Assuming you are using GNU find or another find which has these options, find . -mindepth 8 -maxdepth 8 -name '*XYZ*' If you don't have such a find command, you can use this POSIX version: # must contain exactly 7 slashes find . -path '*/*/*/*/*/*/*/*' -prune -name '*XYZ*' -path '*/*/*/*/*/*/*/*' selects paths that are at least 8 levels deep (contain ...


4

You have an NTFS filesystem. In this case you cannot safely fix the problem on anything except a Windows machine. (The Linux code is good, but I cannot recommend you trust it to fix a foreign filesystem.) Take the disk to your Windows system and run CHKDSK /F Q:, or whatever drive letter it's been assigned. Then try deleting the file. If that fails you're ...


4

You have some solid answers already, however I'll offer an alternative - the XML spec is quite strict, and files that don't start with < isn't actually XML at all. So a simple approach might be to simply test if the file is 'valid' or not. All XML parsers can do this, but here's an example: #!/usr/bin/perl use strict; use warnings; use XML::Twig; ...


3

You can't use capture groups from the regexp in the command to execute. If you use find -regex to restrict matches, you'll have to do some extra matching in the command. You can do that by invoking a shell and using its own pattern matching constructs. For example, if foo and bar are constant strings and regex1 can't match bar: find … -exec sh -c ' ...


3

The better way to change the column separator and use columncommand: sed 's/ */;/g' file | column -ts';' which produce: Item Code Active Description Store Room Row Shelf Bin On Hand 38NUTZSL Y 3/8"-16 HEX ZINC NUT B 03 C 2 0 WELD-AL Y WELD, ALUM. ROD, ...


3

If your awk supports the nextfile statement (most do): find . -name '*.xml' -type f \( -size 0 -print -o -exec awk ' !/^</ {print FILENAME}; {nextfile}' {} + \)


3

To grep the first line of each file and print if they match you can use xargs and awk find . -type f -name "*.xml" -print0 | xargs -0 -I{} awk 'NR==1&&!/^</' {} To print the filename of the files find . -type f -name "*.xml" -print0 | xargs -0 -I{} awk 'NR==1&&!/^</{print FILENAME}' {}


3

You could try sudo find / -name "studio.*". The way this command works is simple: sudo runs the find command as superuser (supersuser do) so you can check all the directories in the file system including the locked ones. find searches a given location (/ in our case) for a given file or directory. / is the parameter that dictates find where to search (in ...


3

find <path>/. -type f -size 1033c ! -perm -0001 -ls


3

Get the file size: size="$(stat --printf="%s" "$path")" Get the path without the last extension: path_without_extension="${path%.*}" Compare the two: [ "${path_without_extension}.${size}" = "$path" ]


2

With GNU find and GNU coreutils, and assuming your directories don't have newlines in their names: find ~/foo -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50' | cut -f 2- This will list directories with total contents smaller than 50K. If you're happy with the results and you want to delete them, add | xargs rm -rf to the end of the ...


2

The -path argument is a pattern, so you have to use wildcards, or it will only match exact: find . -not -path "./.local/share/Steam/steamapps/common/*" -empty Also, you have to use absolute or relative paths, not mix them. The above one is with relative paths, this one is with absolute paths: find /home/tjuh -not -path ...


2

It means that the filesystem that is mounted on /hgfs (a filesystem of type vmhgfs, the VMware host/guest filesystem) doesn't support the stat system call. stat is used to return details about nodes on a filesystem and there's no requirement that every filesystem support it. You can ignore the error message. If you won't want it appearing in the output of ...


2

What are the %s %p options used here? From http://unixhelp.ed.ac.uk/CGI/man-cgi?find: %s File's size in bytes. %p File's name. Scroll down on that page beyond all the regular letters for printf and read the parts which come prefixed with a %. Are there any other options that can be used? There are. See the link to the manpage.


2

If you want to skip the unreadable files: find /external/hd/folder ! -readable -print >unreadable_files rsync -a --exclude-from=unreadable_files /external/hd/folder/ /local/folder This assumes that you're using GNU find, and that your filenames don't have embedded newlines. If you want to copy all files, regardless of whether they are readable or not ...


2

Answering the second part of your question, the "best" way to watch for filesystem changes is by using inotify(7). There is a set of utilities that can hook into the kernel interface, inotify-tools. In particular, you want inotifywait from that set of utilities: inotifywait efficiently waits for changes to files using Linux's inotify(7) interface. It ...


1

mv path_to_example_dir/*_jony /jony


1

The possible duplicate Link answered the question partly. To provide multiple name patterns to 'find' use this find $directory -type f \( -name "*.zip" -o -name "*.rar" \) The complete answer to the question is: find $directory -type f \( -name "*.zip" -o -name "*.rar" \) -print0 | xargs -0 -n1 du -b | sort -n -r with $directory being comp_tuts/ dir


1

In the unlikely event that your filesystem is mounted with strictatime or lazytime you could use: find /tools -atime +365 However if your filesystem is mounted with relatime, then this information is not being recorded. This is usually done for performance reasons. You can check using the mount command: $ mount /dev/sda3 on / type ext3 ...


1

find .//. -name \*.xml -type f -exec head -n1 {} + | sed -ne:n -e'\|^==> \.//\.|!{H;$!d' -e\} \ -ex -e'\|\.xml <==\n|!{G;x;d' -e\} \ -e's|[^/]*//\(.*\) <==\n[^<]*$|\1|p' head lists filenames all on its own. So you can just -exec it and have sed watch its input for head's report on the names for those files which don't match a ...


1

Pure ksh93 solution: FIGNORE='@(.|..)' for dir in */; do a=( "$dir"/**/* ); printf "%s\t%s\n" "$dir:" "${#a[*]}"; done Result from /usr/src: linux-3.17.7-gentoo/: 561 linux-3.5.7-gentoo/: 517 linux-3.7.10-gentoo/: 505 linux-3.7.9-gentoo/: 513 linux-3.8.13-gentoo/: 551 linux-4.0.5-gentoo/: 1849


1

Will something like this suit your need: The path /boot is used for sample demonstration. Change it to the directory you need. for DIR in $(find /boot/* -maxdepth 1 -type d) do printf "%40s: %10d\n" "${DIR}" $(find ${DIR}|wc -l) done Output: /boot/grub: 282 /boot/grub/fonts: 2 ...


1

You could find the toplevel directories first, then use a second find, to count the number of files and directories within the toplevel directory: $ for dir in $(find . -maxdepth 1 ! -path . -type d | sort); \ do echo -n "$dir " && find $dir ! -path . | wc -l ; done ./adir 1151 ./anotherdir 140 ./623de41e44 280 ./examples 154 ...


1

If you mount the external HDD to your system locally, then it's not remote. Unless I misunderstood and your HDD is running a rsync daemon and say, connecting over a network? But forget that, can you just mount the drive locally and as @mjturner says, all you need to do is make sure you run rsync as root and it's a direct copy sudo rsync -a ...


1

With zsh you could use the function age to print only the names of files that have been modified on a certain date: autoload age print -rl -- *.php(.e:age 2011/02/08:) or, if you want to search recursively: autoload age setopt extendedglob print -rl -- **/*.php(.e:age 2011/02/08:)


1

Here is a method that only uses POSIX shell features: find ~/dim_import/* -type f ! -name xdir -exec sh -c ' p=${1%/*}; d=${p##*/}; f=${1##*/}; mkdir -p new/"$d"; cp "$1" new/"$d"' -- {} \;



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