#] #] ********************* #] "$d_SysMaint""Linux/find notes.txt" www,BillHowell.ca ?date? initial # view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap $*.[,\] -> special characters must normally be escaped to search as character, but NOT in a [list] : opl_regexpr IS host 'grep "^#] " "$d_SysMaint""Linux/regular expression notes.txt" | sed "s/^#\]/ /" ' opl_find IS host 'grep "^#] " "$d_SysMaint""Linux/find notes.txt" | sed "s/^#\]/ /" ' opl_grep IS host 'grep "^#] " "$d_SysMaint""Linux/grep summary.txt" | sed "s/^#\]/ /" ' opl_sed IS host 'grep "^#] " "$d_SysMaint""Linux/sed summary.txt" | sed "s/^#\]/ /" ' opl_diff IS host 'grep "^#] " "$d_SysMaint""Linux/diff notes.txt" | sed "s/^#\]/ /" ' opl_geany IS host 'grep "^#] " "$d_SysMaint""text processors/geany notes.txt" | sed "s/^#\]/ /" ' 24************************24 24************************24 # Table of Contents, generated with : # $ grep "^#] " "$d_SysMaint""Linux/find notes.txt" | sed 's/^#\]/ /' # ********************* "$d_SysMaint""Linux/find notes.txt" +-----+ Search [ndf, txt] files in d_Q[root, ndfs, test] for [strings, [optr,var] symbols, etc] : $ find "$d_Qroot" -maxdepth 3 -type f \( -name "*.ndf" -o -name "*.txt" \) | grep --invert-match "z_Old" | grep --invert-match "z_Archive" | sort | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number 'ary_indexA_convertTo_boolA' "FILE" | sed "s|$d_Qroot||;s|:.*||" | sort -u >"$d_temp"'find-grep-sed temp.txt' +--+ grep words (symbols) -w = word, -i = case insensitive -maxdepth 3 specify depth to search in directoryty tree "-atime -90" find files accessed less than 90 days ago +-----+ output 2> /dev/null - send stderr to void must come AFTER normal ">" to stdout (default 1) 2>&1 - send stderr to stdout must come AFTER normal ">" to stdout (default 1) -type f filename ONLY, without path : see "$d_bin"'0_directory updates - bash & qnial.sh' -type d directories only : send stderr to a stdout then to file, when stderr floods results $ find / -type f -name "batch_access.sh" 2>&1 | tr \\n \\0 | xargs -0 -IFILE grep --invert-match "Permission denied" "FILE" +-----+ Sudo eliminates almost all "Permission denied" results : +-----+ other key examples Mindcode - search temp file use bash - see "$d_bin""email - remove emails from text file.sh" ********************* chronological entries : 16Feb2022 search "Linux find multiple names" 04May2019 search "Linux find and how do I get the fname without the path" 23May2018 find - using -maxdepth n MUST appear after the path, and before -name! maxdepth 0 only lists the directory itself ?23May2018 symbols file counts Lucas.sh 10Jan2018 example : bash_scripts list of Howells.sh 10Jan2018 example : sed-cmakes - pull out my modifications to cmake files 10Jan2018 How do you select files by date modified in UNIX/Linux? 24************************24 #] +-----+ #] Search [ndf, txt] files in d_Q[root, ndfs, test] for [strings, [optr,var] symbols, etc] : #] +--+ #] -type [f, d] [f=file, d=directory] only one or the other #] #] $ find "$d_Qroot" -type f \( -name "*.ndf" -o -name "*.txt" \) | grep --invert-match "z_Old" | grep --invert-match "z_Archive" | sort | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number 'ary_indexA_convertTo_boolA' "FILE" | sed "s|$d_Qroot||;s|:.*||" | sort -u >"$d_temp"'find-grep-sed temp.txt' #] #] find "$1" -maxdepth 1 -type f -name "$3" | sed 's#'$1'##g' >"$d_lst" $ find "$d_bads" -maxdepth 1 -type f -name "*.pdf" | sed "s#.*N-##g;s#\.pdf##g" >>"$p_badList" #] -type d directories only : $ find "$d_Qndfs" -maxdepth 1 -type d | sed "s|""$d_Qndfs""||" #] grep words (symbols) -w = word, -i = case insensitive $ find "$d_Qndfs" -type f -name "*.ndf" | grep --invert-match 'z_Archive' | grep --invert-match 'z_Old' | tr \\n \\0 | xargs -0 -ILINE grep -w -i --with-filename --line-number "str_to_phrases1" LINE #] -maxdepth 3 specify depth to search in directoryty tree $ find "/media/bill/SWAPPER/Website - raw/" -maxdepth 3 -name "*.html" | tr \\n \\0 | xargs -0 -IFILE grep -w -i --with-filename --line-number ':&file-insert &:' "FILE" | sed 's#:.*##' | sort -u #] "-atime -90" find files accessed less than 90 days ago $ find "$d_Qndfs" -atime -90 -type f -name "*.ndf" | grep --invert-match 'z_Archive' | grep --invert-match 'z_Old' | tr \\n \\0 | xargs -0 -ILINE grep --with-filename --line-number "_test" LINE | sed 's/^\(.*\):[0-9]\+:.*/\1/' | sort -u #] #] 01Jul2023 find cannot use regular expressions in general form? : #] works : find "$pinn' -name "*tbl*" #] noWork: find "$pinn' -name "^p[0-9]\{3\}tbl[0-9]\{2\}\.[0-9]\{2\}*" #] works : find "$pinn' || grep "^p[0-9]\{3\}tbl[0-9]\{2\}\.[0-9]\{2\}*" #] +-----+ #] output #] 2> /dev/null - send stderr to void must come AFTER normal ">" to stdout (default 1) #] 2>&1 - send stderr to stdout must come AFTER normal ">" to stdout (default 1) #] send stderr to a stdout then to file, when stderr floods results Can I find old bash scripts? #] $ find / -type f -name "batch_access.sh" 2>&1 | tr \\n \\0 | xargs -0 -IFILE grep --invert-match "Permission denied" "FILE" $ find / -type f -name "batch_access.sh" 2>"/media/bill/ramdisk/permission denied.txt" $ grep --invert-match "Permission denied" "/media/bill/ramdisk/permission denied.txt" >"/media/bill/ramdisk/permission denied2.txt" $ grep --invert-match "Operation not permitted" "/media/bill/ramdisk/permission denied2.txt" >> Not found anywhere #] +-----+ #] other key [issue, example]s #] Sudo eliminates almost all "Permission denied" results : $ sudo find / -type f -name ".Xdefaults" >"/media/bill/ramdisk/tmp find.txt" #] Mindcode - search temp file # $ find "$d_Qndfs""MindCode" -type f -name "*.ndf" | tr \\n \\0 | xargs -0 -ILINE grep --with-filename "^#]" LINE | grep --invert-match 'z_Archive' "$d_temp""5_MindCode globals temp.txt" | grep --invert-match 'z_Old' | sed 's/.*#]//' #] use bash - see "$d_bin""email - remove emails from text file.sh" d_remove_emails() { if [ -d "$d_withEml" ]; then if [ -d "$d_noEmail" ]; then find "$d_withEml" -maxdepth 1 -type f -name "*" | sed "s#$d_withEml##" >"$d_temp""d_remove_emails files.txt" while read -u 9 line; do cat "$d_withEml""$line" | sed 's/[A-Za-z0-9._-]*@[A-Za-z0-9._-]*//g' >"$d_noEmail""$line" done 9< "$d_temp""d_remove_emails files.txt" else echo "directory doesnt exist : $d_noEmail" fi else echo "directory doesnt exist : $d_withEml" fi } #] ********************* #] chronological entries : 24************************24 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] ??Jul2023 08********08 #] 01Jul2023 find: cannot use regular expressions in general form #] works find "$pinn' -name "*tbl*" #] noWork find "$pinn' -name "^p[0-9]\{3\}tbl[0-9]\{2\}\.[0-9]\{2\}*" 08********08 #] 16Feb2022 search "Linux find multiple names" Search [ndf, txt] files in d_Q[root, ndfs, test] for [strings, [optr,var] symbols, etc] : https://www.tecmint.com/linux-find-command-to-search-multiple-filenames-extensions/ $ find "$d_Qroot" -type f \( -name "*.ndf" -o -name "*.txt" \) | grep --invert-match "z_Old" | grep --invert-match "z_Archive" | sort | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number 'ary_indexA_convertTo_boolA' "FILE" | sed "s|$d_Qroot||;s|:.*||" | sort -u >"$d_temp"'find-grep-sed temp.txt' 08********08 #] 04May2019 search "Linux find and how do I get the fname without the path" https://superuser.com/questions/559824/how-to-get-only-names-from-find-command-without-path#559827 Use find trunk/messages/ -name "*.po" -exec basename {} .po \; Example and explanations: Create some test files: $ touch test1.po $ touch test2.po $ find . -name "*.po" -print ./test1.po ./test2.po Ok, files get found, including path. For each result execute basename, and strip the .po part of the name $ find . -name "*.po" -exec basename \{} .po \; test1 test2 edited Mar 2 '13 at 14:52, slhck answered Mar 2 '13 at 14:37, Hennes same URL : Based on a command I found here: http://www.unixcl.com/2009/08/remove-path-from-find-result-in-bash.html You could do this using sed (which executed faster for me, than the basename approach): find trunk/messages/ -name "*.po" | sed 's!.*/!!' | sed 's!.po!!' edited Oct 16 '16 at 20:33, DavidPostill answered Oct 16 '16 at 19:13, Anon567 08********08 #] 23May2018 find - using -maxdepth n MUST appear after the path, and before -name! #] maxdepth 0 only lists the directory itself Lessons : -maxdepth 1 MUST appear after the path, and before -name! -maxdepth 0 only lists the directory itself - don't use -path OR -name !!! just put path in quotes as first argument BEFORE options !!! THEN use grep ! example : # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -maxdepth 1 -name "sym*" 08********08 #] ?23May2018 symbols file counts Lucas.sh #!/bin/sh # /media/bill/PROJECTS/Qnial/MY_NDFS/symbols file counts Lucas.sh # www.BillHowell.ca 23May2018 initial # to run : $ bash "/media/bill/PROJECTS/Qnial/MY_NDFS/symbols file counts Lucas.sh" dater=$(date +"%y%m%d %kh%Mm") d_Lucas="/media/bill/PROJECTS/Lucas - Universal Force/" d_temp="/media/bill/ramdisk/" p_fSym_names="symTranslate_file_test fSym_names.txt" p_f_bash="symTranslate_file_test f_bash.sh" p_f_counts="symTranslate_file_test f_counts.txt" find "$d_Lucas" -maxdepth 1 -name "symList*" >"$d_temp$p_fSym_names" find "$d_temp" -maxdepth 1 -name "symDiff*" >>"$d_temp$p_fSym_names" cat "$d_temp$p_fSym_names" | xargs --max-args=1 -Ifiler echo >"$d_temp$p_f_bash" 'cat "$d_Lucas""filer" | grep --count ".*" ' bash "$d_temp$p_f_bash" >"$d_temp$p_f_counts" # final lusting if symbol files and counts paste "$d_temp$p_f_counts" "$d_temp$p_fSym_names" >"$d_Lucas""symbol names & counts$dater.txt" # see "/home/bill/System_maintenance/Linux/find notes.txt" for my sad story of getting find to work!! # FINALLY!!!??? what a stupid set of man page guides! # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -maxdepth 1 -name "sym*" +-----+ Man, what a pain in the ass, lousy fucking man page grammatical specs! None of these worked # $ find -maxdepth 0 -path "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find -maxdepth 0 "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find -maxdepth 0 -name "sym*" "/media/bill/PROJECTS/Lucas - Universal Force/" # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" -maxdepth 0 # $ find -maxdepth 0 -path "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*.*" # $ find -maxdepth 0 -path "/media/bill/PROJECTS/Lucas - Universal Force/" -name "symList bads Lucas.txt" # $ cd "/media/bill/PROJECTS/Lucas - Universal Force/" # $ find -maxdepth 0 -name "sym*" # $ find -maxdepth 1 -name "sym*" # $ find -maxdepth 1 -path "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find -maxdepth 1 -path "/media/bill/PROJECTS/Lucas - Universal Force" -name "sym*" # $ find -maxdepth 2 -path "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find -maxdepth 2 "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -maxdepth 0 -name "sym*" # $ find -maxdepth 0 "/media/bill/PROJECTS/Lucas - Universal Force/" -name "sym*" # FINALLY!!!??? what a stupid set of guides! # $ find "/media/bill/PROJECTS/Lucas - Universal Force/" -maxdepth 1 -name "sym*" 08********08 #] 10Jan2018 example : bash_scripts list of Howells.sh #!/bin/sh # /media/bill/HOWELL_BASE/System_maintenance/Linux/bash_scripts list of Howells.sh # www.BillHowell.ca 10Jan2018 initial # $ bash "/media/bill/HOWELL_BASE/System_maintenance/Linux/bash_scripts list of Howells.sh" dater=$(date +"%y%m%d %kh%Mm") d_out="/media/bill/HOWELL_BASE/System_maintenance/Linux/" f_out="bash_scripts list of Howells.txt" p_out="$d_out$f_out" echo >"$p_out" "$p_out" echo >>"$p_out" "wwwBillHowell.ca this listing generated : $dater" echo >>"$p_out" "" echo >>"$p_out" "to generate this file with the list below, run : " echo >>"$p_out" "$ bash '/media/bill/HOWELL_BASE/System_maintenance/Linux/bash_scripts list of Howells.sh'" echo >>"$p_out" "" echo >>"$p_out" "" find "/media/bill/HOWELL_BASE/" -name "*.sh" | sort >>"$p_out" echo >>"$p_out" "" echo >>"$p_out" "" find "/home/bill/" -name "*.sh" | sort >>"$p_out" ?date? 08********08 #] 10Jan2018 example : sed-cmakes - pull out my modifications to cmake files sed-cmakes() { p_log="$d_log""OPM build.txt" p_out="$d_log_grep""grep cmakes-Howell in OPM $dater.txt" becho 'cd "/home/bill/OPM" ' cd "/home/bill/OPM" becho 'find -nowarn -name -print ".cmake" ' find -nowarn -name "?*cmake" | grep "?*Find?*" | grep "(copy)" | sed 's/^\.\//\/home\/bill\/OPM\//' #| grep >"$p_out" 2>&1 --invert-match ":" # "/home/bill/OPM" #becho "sed -ri \"$3\" | grep >\"$p_out\" 2>&1 --invert-match \"Binary file \" " # grep -ri "$3" | grep >"$p_out" 2>&1 --invert-match "Binary file " becho ">> Results (manually copy-paste pertinent parts) : " becho "" } 08********08 #] 10Jan2018 How do you select files by date modified in UNIX/Linux? https://www.quora.com/How-do-you-select-files-by-date-modified-in-UNIX-Linux How do you select files by date modified in UNIX/Linux? Hemanth Kumar Mantri, Linux user since 2005 Updated 5 Mar 2013 If you are using Linux, then you can use only atime (access time), ctime (last time when file attributes changed) and mtime (last modification time of file contents). However, if you are using BSD, apparently on Mac you also have file creation time maintained with every file's metadata. If you are just looking to sort files in a directory based on modification times: ls -lt sorts the files/directories such that the most recently modified ones are on top. ls -ltr sorts in the reverse order. In Mac, use -U option instead of -t above to sort based on file creation time. If you are looking to pick files based on mtime, then You can use find -mtime . For example to find all files modified in last 1 month, use -mtime +30 option. -mtime +30 for files modified 30 days ago -mtime -30 for less than a month -mtime 30 indicates exactly a month Note: You can replace mtime above with atime and ctime For example, $ find /path/to/search -mtime -30 -print gives all files modified in this month. $ find /path/to/search -iname "*.mp3" -type f -atime 15 shows all mp3s that were accessed exactly 15 days ago. If you like to find timestamps relative to a given file with known time, you can use -newer option. Remember that you can set timestamp to a file using touch command. Example: find /path/directory1 -newer /my/file finds all files and directories in /path/directory1 that are newer than the file /my/file You may want to find files modified after a certain date. In that case you set the reference file's timestamp as follows: touch --date "2013-02-14" /tmp/dummy and now, find /path/directory1 -newer /tmp/dummy finds files newer than Feb 14 2013 in /path/directory1 # enddoc