find

how to get file path without the filename itself

how to get file path without the filename itself im trying to find my .csv files then cd into their directory: find Documents/notes -type f -name "*.csv" | head -1 | xsel -b this copies the first file dir into my clipboard and i’d like to then run: cd $(xsel -b) but ofcourse I can’t …

Total answers: 2

Using find in order to detect a magento module

Using find in order to detect a magento module At magento routes are located in adminhtml/routes.xml each module has a folder named adminhtml with a file routes.xml each module has its own folder. In other words I have the following file structure: vendor + MyModule ++ etc +++ adminhtml ++++ routes.xml + AnotherModule ++ etc …

Total answers: 2

How does `ls` find hard links?

How does `ls` find hard links? Setup The following sequence of commands is setup for my question. root@cd330f76096d:/# cd root@cd330f76096d:~# ls root@cd330f76096d:~# mkdir -p my_dir/my_subdir root@cd330f76096d:~# ls -hAil total 12K 6175969 -rw-r–r– 1 root root 3.1K Oct 15 2021 .bashrc 6175970 -rw-r–r– 1 root root 161 Jul 9 2019 .profile 7382820 drwxr-xr-x 3 root root …

Total answers: 1

Pass result of find command as another command's multiple options

Pass result of find command as another command's multiple options I have a CLI tool that can take an option with multiple values – The syntax is like this: CLI -I path/to/file1 -I path/to/file2 … How can I pass the result of the find command to this CLI? For reference If it’s positional multiple arguments: …

Total answers: 3

How to find and exec with or

How to find and exec with or I am trying to find files with *.c and *.h extensions. I use the following command find "$path" -type f -iname "*.c" -o -iname "*.h" -exec ls {} ; This only executes ls the *.h matches. I have tried -o -iname *.c -o -iname *.h same thing happens. …

Total answers: 1

How do I find all directories that contain matching files?

How do I find all directories that contain matching files? I am looking for directories that contain files that match a pattern, say, foobar*.csv. Directories that do contain such files may contain hundreds of them (and no subdirectories!), so I want find to print here/is/the/path/to/dir as soon as it finds here/is/the/path/to/dir/foobar-2022-01-01.csv and stop descending. How …

Total answers: 5

Execute on all files without corresponding extension

Execute on all files without corresponding extension How can I find and execute a program when the said file does not have a corresponding file? Example files: /file1.c /file1.h /file2.c /file3.c /file3.hpp /file4.c/unrelated.txt find / -type f -name ‘*.c’ -exec my_program_here {} ; executes on: /file1.c /file2.c /file3.c but I want to filter out those …

Total answers: 2

Deleting files whose filenames match strings contained in a file

Deleting files whose filenames match strings contained in a file There is a text file, del.txt, containing a list of randomly-generated identifying strings, for example: 07ckv978yk0 HuinLBoZHcY _oR7ccXiunY I would like to delete any files whose filenames contain any of the identifying strings. The filenames would be in the format of 20191223_abcdef_07ckv978yk0.json, where the matching …

Total answers: 3

Detect multiple files at subfolder containing specific string on Linux

Detect multiple files at subfolder containing specific string on Linux I have multiple files of work.log at different subfolders need to detect two keyword Can’t find file or Not pass by number Direct path like : /folder/Date/Job1/20190116_ADMtest_1/ADM.log /folder/Date/Job1/20190122_ADMtest_2/ADM.log /folder/Date/Job1/20190203_ADMtest_4/ADM.log /folder/Date/Job1/20190217_ADMtest_3/ADM.log /folder/Date/Job1/20190218_ADMtest_21/ADM.log /folder/Date/Job1/20190225_ADMtest_18/ADM.log In every log will look like: [Message] 2019-01-16 11:13:21 Read 2 files from: …

Total answers: 3

find -exec bash -c {} +: why only one file of found two?

find -exec bash -c {} +: why only one file of found two? touch 1.txt 2.txt find . -name "[12].txt" -exec sh -c ‘echo "${1}"’ sh {} + -exec echo {} + ./2.txt ./2.txt ./1.txt Why echo within sh -c outputs only one file? Today I thought I understood how find works from Understanding the …

Total answers: 1

Find(1): test 'A' pass but test 'A -o B' fails

Find(1): test 'A' pass but test 'A -o B' fails This function doesn’t print out anything; skyrimse_testroot() { local directory="$1" find "$directory" ( -type f -ipath "${directory}/data/scripts/*.pex" ) -o ( -type d -ipath "${directory}/data/meshes" ) -print -quit } But this one does (I removed the second test group); skyrimse_testroot() { local directory="$1" find "$directory" ( …

Total answers: 1

Just as there is "locate" to "find". Is there a database for a faster "grep"?

Just as there is "locate" to "find". Is there a database for a faster "grep"? locate (or rather, updatedb) is somewhat simple: it takes the output of find for the required paths (usually ‘/’), sorts it, and then compresses it with a front-compression tool (frcode), in which the consecutive common prefixes are replaced by number …

Total answers: 1

find command – list all directories with a set sticky bit

find command – list all directories with a set sticky bit This doesn’t work find / -type d -perm 1000 The problem is, that it matches only the exact permission (1000), but I only want to find out if the sticky bit is set or not. I don’t care about the other permissions… My solution …

Total answers: 2

Rename the sub-sub-directories of a directory named _QWE

Rename the sub-sub-directories of a directory named _QWE I can run a command in all directories named _QWE using: find . -name ‘_QWE’ -type d -execdir touch {}/1234.txt ; However, I need to run -execdir rename ‘s!^./(d+ -)s(d+.)!$1!’ {} ; in all the immediate sub-directories of _QWE to rename the sub-directories of the sub-directories of …

Total answers: 1

find -name -path

find -name -path I have a some tree. . ├── 1 │   └── a │   └── script.a.sh ├── 2 │   └── a │   └── script.b.sh … └── a └── script.sh And I need to find script.*.sh. I execute ./a/script.sh: #!/bin/bash # path="/tmp/test" readarray files < <(find ${path} -path "*/a/script.*.sh") if [ ${#files[@]} -ne 0 ] …

Total answers: 2

find combine many names and paths in one command

find combine many names and paths in one command I have a rather complex set of files to be found and reacted upon (e.g. paths copied to a text file): For example: find / ( -iname "*ssh*" -or -iname "*scp*" ) ( -not -path -"/run" -not -path "/rw/*" -and -not -path "/home/*" -and -not -path …

Total answers: 2

How to find the most recent file that contains a string

How to find the most recent file that contains a string I have a directory containing several files. I need to know the full path of only the most recent file that contains a certain string. This needs to work on macOS, and the directory path contains spaces. I need to be able to invoke …

Total answers: 2