Tag Info

Hot answers tagged

5

The curly braces will be replaced by the results of the find command, and the chmod will be run on each of them. The + makes find attempt to run as few commands as possible (so, chmod 775 file1 file2 file3 as opposed to chmod 755 file1,chmod 755 file2,chmod 755 file3). Without them the command just gives an error. This is all explained in man find: -exec ...


4

With GNU find: find . -regextype posix-extended ! -regex '.{253,}' ! -type d (that prints a ./ prefix which is not included in the 250 count). With zsh: setopt extendedglob # if not already in your ~/.zshrc printf '%s\n' **/*~?(#c251,)(D^/) That's all paths recursively (**/*) including hidden ones ((D)), but not (^) those of type directory (/), except ...


4

Yes, it's possible. One way to do it might look like this: cd /den/of/gifs && \ for f in ./*t.gif; do mv -- "${f%%t.gif}.gif" "$f" done The ${var%%pattern} thing is standard/POSIX sh syntax for removing the longest string that matches pattern from the end of $var.


3

In addition to terdon’s answer, “Obviously” -exec … must be terminated with either a semicolon (;) or a plus sign (+).  Semicolon is a special character in the shell (or, at least, every shell I’ve ever used), so, if it is to be used as part of the find command, it must be escaped or quoted (\;, ";", or ';'). With -exec … ;, the {} string may appear any ...


3

To find files that have been modified a certain days ago, it is better to use -mmin instead of -mtime as the latter will ignore any fractional part. So, 1 day 23 hours is also treated as 1 day. From man find: -atime n File was last accessed n*24 hours ago. When find figures out how many 24-hour periods ago the file was last accessed, any ...


3

Perl module Unicode::Tussle comes with a very useful script named rename (which is unfortunate, because the name clashes with the standard rename(1) on Linux). With it, you could do something like this: mkdir xyz find . -name '*.pdf' -print0 | \ rename -0 's!^\.!xyz!; s!/[^/]*\.pdf$!.pdf!' Without Perl, you could still do the same thing with a bit ...


3

POSIXly: $ find . -type f -exec sh -c ' for f do [ "${#f}" -le 252 ] && printf "%s\n" "$f" done ' sh {} + POSIX defined ${#parameter} as the length in characters of value parameter, but the behaviour may varies in some shells. bash, zsh, yash count characters, dash count bytes. ksh93 has a random bug depends on its ...


3

You cannot do that on the usual Linux filesystems, as it doesn't keep track of the creator of the file, only of the owner of the file. The creator and owner are usually, but not necessarily the same. If you want to find the owner of the file, you can, as Bratchley indicated, use find / -type f -user user_name to find those files and display the names. ...


2

You want it to be 2 or 3 arguments to find: ("-o"), "-name" and "$2", so that's: mopt=false case $1 in ... -m|--mask-file) "$mopt" || mask+=(-o) mask+=(-name "$2") mopt=true shift 2;; find . "${mask[@]}"


2

Yes, "start path" means one of the directory names that appear near the beginning of the find command, after the options but before the expression.  I interpret the question that you linked to as suggesting that that OP was confused about the difference between find /etc ... and find -path /etc ... "It refers to the combination of the start path ...


2

To avoid confusion you should probably think of the prototype for find(1) like this: find [-H] [-L] [-P] [-D debugopts] [-Olevel] [dir...] [expression] find(1) finds files in dir. expression is a logical expression formed of tests that are applied to the files found. -path, -name, -type are examples of such tests. above basically says -path doesn't ...


2

-mtime N means files whose age A in days satisfies N ≤ A < N+1. In other words, -mtime N selects files that were last modified between N and N+1 days ago. For example, -mtime 1 selects files that were modified between 1 and 2 days ago. To select files that were modified in the last day (as in, the last 24 hour period), use -mtime 0. -mtime -N means files ...


2

Assume you are in parent directory of sub directories: find . -type f -name '*.out' -exec sh -c ' for f do grep "string" /dev/null "$f" | tail -n 1 done ' sh {} +


2

About your errors: find: The relative path `~/program_files/internet/SSH_tunneling/' is included in the PATH environment variable, which is insecure in combination with the -execdir action of find. Please remove that entry from $PATH You have ~/program_files/internet/SSH_tunneling/ in your $PATH. That's a literal ~. That does not mean your home ...


2

If you want to stay with find and basename, this should work: find . -name "*.gif" ! -name "*t.gif" -execdir sh -c ' cp -- "$0" "$(basename "$0" .gif)t.gif"' {} \; This is performance- and resource-wise not the best option.


2

To make it even more compact and faster, you could use parallel: parallel mv {} {.}t.gif :::: <(find . -regex '.+[0-9].gif') The expression after :::: provides arguments for parallel. These arguments are then used using {}. The {.} represents the argument without the file-extension. So, in our case {} will be the file names of files without the t in ...


2

From the bash manual page: -c If the -c option is present, then commands are read from the first non-option argument command_string. If there are arguments after the command_string, they are assigned to the positional parameters, starting with $0. The filename is given to bash as an argument using the braces {}, so it is ...


2

Use find: find /path -mtime +180 -size +1G -mtime means search for modification times that are greater than 180 days (+180). And the -size parameter searches for files greater than 1GB.


2

If your pax supports the -0 option: find . -type 'f' -path '*downloads*' -print0 | pax -rw0s'|.*downloads/||' /mydir


2

The pattern [a_]* matches names that start with either of the characters a or _. The pattern *[.csv] matches names that end with one of the characters ., c, s or v. To match names that start with a_, use -name 'a_*'. To match names that end with .csv, use -name '*.csv'. find ../ -name 'a_*' -a -name '*.csv' or equivalently find ../ -name 'a_*.csv' matches ...


2

You can use the find command for this. To search your entire filesystem for files owned by user exampleuser use: $ sudo find / -user exampleuser If you want search for large files add the -size option: $ sudo find / -user exampleuser -size +10000k This: +10000k will find files greater than 10,000 kilobytes in size.


2

Try this: find / -user <someuser> -type f -printf '%s\t%p\n' | sort -rn | head -1 The above uses GNU find(1) and assumes no filenames have embedded newlines. It also has to be run as root (otherwise it wouldn't be able to read all directories).


2

You may have a symbolic link to another directory. What does ls -l ~/Documents/GamesTeam/games/ichristo_dev/fog/server/deploy display? You can use the option -L to include directories and files that are linked to, but are not really in that directory tree.


1

There are many ways of doing this. If you just want to list the files, you can use ls: ls a_date\(s\)/*csv Or, with find: find .. -path '*a_date*/*csv' find ../allCSVs/a_date\(s\)/ -name '*csv'


1

I need advice/best practice on how I can avoid keying in passphrase when I add this crontab to run everyday. Create a new ssh key with an empty password, specially for this task. Save it in a file, say, ~/.ssh/cron. Add its corresponding public key to ~/.ssh/authorized_keys on the remote machine. When you run your scp from cron(8) do it with the new ...


1

If you just run find, it has to go through all the subdirectories to find all the files. It looks like you expect the file to be at a low depth, so you could pass the -maxdepth argument to limit the depth of the search, e.g. find /mnt/build/my_project/ -maxdepth 3 -wholename "*${BUILD_NAME}*/foo.tar.gz" -type f Alternatively, you could skip find ...


1

find / -size +1G -mtime +180 -type f -print Here's the explanation of the command option by option: Starting from the root directory, it finds all files bigger than 1 Gb, modified more than 180 days ago, that are of type "file", and prints their path.


1

Probably /sys/class/graphics/fb0/virtual_size is /sys/devices/pci0000:00/0000:00:02.0/graphics/fb0/virtual_size. Try readlink -f /sys/class/graphics/fb0/virtual_size to confirm. namei -l /sys/class/graphics/fb0/virtual_size to see how that happened (one of the path components of /sys/class/graphics/fb0/virtual_size at least must be a symbolic link). find ...


1

grep command have -r option it searchs text recursive over directory example below: grep -r "5|20150507" ./ | awk -F ':' {'print $2'}


1

With zsh on a GNU system: for f (**/*.out(.)) tac < $f | grep --label=$f -m1 string



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