Tag Info

New answers tagged

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.


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 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

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 ...


0

POSIXly: find . ! -name . -prune -type f -name '*.java' -exec grep -i example /dev/null {} +


1

grep -i example *.java Displays a list of files with the lines that match.


1

Be careful with special file names (spaces, quotes) when piping to rm. There is a safe alternative - the -delete option: find /path/to/directory/ -mindepth 1 -mtime +5 -delete That's it, no separate rm call and you don't need to worry about file names. Replace -delete with -depth -print to test this command before you run it (-delete implies -depth).


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'


0

You could use Recoll that helps you to search any document type and also restrict your search to a particular folder as shown below. Simple Search Advanced Search(To restrict search to a particular folder)


0

Isn't there some way to protect spaces in backtick (or $(...)) expansion? No, there isn't. Why is that? Bash has no way of knowing what should be protected and what shouldn't. There are no arrays in the unix file/pipe. It's just a byte stream. The command inside the `` or $() outputs a stream, which bash swallows and treats as a single string. As ...


2

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


0

This should do it: for file in /Module*/*/downloads/m13312/file.pdf do file_directory="/mydir/$(basename "$(dirname "$file")")" mkdir -p "$file_directory" cp "$file" "$file_directory" done


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 ...


0

If you are the find command, you have a difficult job to do when setting your exit code. That's because you have 2 types inputs (forgetting options for the moment) with two types of jobs: The path(s) to the files you want to find. You likely would not, for example, want to exit with an error if you did find /mnt/log/storage/place -type f -mtime +7 -print. ...


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 ...


0

If you are able to use find and if you are working on a "normal Unix filesystem" (that is, as defined in find(1) under -noleaf option description), then the following command can be used: find . -type d -links 2 Each directory has at least 2 names (hard links): . and its name. Its subdirectories, if any, will have a .. pointing to the parent directory, so ...


0

This will find all files recursively, and sort them by size. It prints out all file sizes in kb, and rounds down so you may see 0 KB files, but it was close enough for my uses, and works on OSX. find . -type f | xargs ls -la | awk '{print int($5/1000) " KB\t" $9}' | sort -n -r -k1


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.


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.


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 ...


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 ...


0

Using GNU Parallel it will look like this: parallel -0 --tag 'find {} |wc -l' ::: */ It will run one find|wc per CPU in parallel. Depending on your storage system parallelization may increase or decrease speed - only way to know is to test it. The number of processes can be adjusted with -j. GNU Parallel is a general parallelizer and makes is easy to ...


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[@]}"


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 ...


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 ...


0

Use grep with option "-h" . -h, --no-filename Suppress the prefixing of file names on output. This is the default when there is only one file (or only standard input) to search. find ./files/ -name "*.txt" -print0 | xargs -0 grep -h "5|20150507"


1

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


0

find ./files/ -name "*.txt" -print0 | xargs -0 grep "5|20150507" | awk 'BEGIN{FS=":"} {print $2}' You may have to play with the delimiter "FS=" as it could be a special character.


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 ...


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.


1

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


0

With gnu tools, you could use a single invocation of gawk: awk '/pattern/{l=$0} ENDFILE{if (l) {print FILENAME ":" l; l=""}}' **/*.out (if line matches store it into l; at the end of each file, if l is not empty print file name and l then reset l) or sed: sed -ns '/pattern/h;${x;//{F;p}}' **/*.out (if line matches, copy to hold space; if la$t line, ...


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 {} +


1

I will use something like: for i in `find . -name "*.out" -type f`; do grep -l 'string' $i grep 'string' $i|tail -1 done With 1st grep you will have filename and below (second grep) the content. This works as long as the file names don't contain whitespace or \[*?. See cuonglm's answer for a robust solution.


0

There are a couple of improvements needed for your script. It's good practice to quote your variables "$folder" , "$answer". You need to use -z and -n to test for null/not null strings in your script. It's better to use read -r especially when reading input with slashes. You also need to change the order of the arguments in your find command. Depending on ...


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 ...


-1

You have a syntax error in your find options. It's -perm, for example: $ find $foldername -type f -perm -o+w


0

Use find: find / -type f -user “<SHORTUSERNAME>" -print 2>/dev/null So, in your script: echo “Enter Username:”; while read -e;do find / -type f -user $REPLY -print 2>/dev/null;done


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

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 ...


0

I'm surprised nobody mentioned the obvious zsh solution here yet: for file (**/*.csv(ND.)) { do-something-with $file } ((D) to also include hidden files, (N) to avoid the error if there's no match, (.) to restrict to regular files.) bash4.3 and above now supports it partially as well: shopt -s globstar nullglob dotglob for file in **/*.csv; do [ -f ...


1

find is rarely useful when you don't need to traverse a directory tree recursively. Here a simple loop and shell wildcards are enough. for x in */161901.pdf; do mv -- "$x" "xyz/${x%/*}.pdf" done Or, with the Perl-based rename command on Debian, Ubuntu and derivatives (prename on Arch, not the Linux rename command on other distributiosn): rename ...


0

-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. -mtime -N means files whose age A satisfies A < N, i.e. files modified less than N days ago. Less intuitively, -mtime +N means files whose age A satisfies N+1 ≤ A, i.e. files modified at least N+1 ...


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 ...


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 ...


0

find lists all the files in the directory tree. ls -R actually lists fewer files: it omits dot files — you need ls -AR to include them. If you aren't finding the files you need, there are a few possibilities: You missed them in the output. Use a search command (e.g. find … | less and use the / key in less). Keep in mind that the output of find is not ...


0

When you execute ls -R you get as output the directories names in the listing.


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 ...



Top 50 recent answers are included