I run the next:   find . -type f -printf '%T@ %p\n' | sort -n | tail -1   this return me the next:  1376221215.000000000 ./Rev.12345/run.exe   I want to get only the 12345 number. Which command I should use (I try to use cut command, without success)?
145
Given a filename in the form someletters_12345_moreleters.ext, I want to extract the 5 digits and put them into a variable.  So to emphasize the point, I have a filename with x number of characters then a five digit sequence surrounded by a single underscore on either side then another set of x number of characters.  I want to take the 5 digit number and put that into a variable.  I am very interested in the number of different ways that this can be accomplished.
12595
I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;).   How do I correctly place (and if needed, escape) redirect and other execution control symbols that could syntactically apply to either of the exec command or the find command, such as > >> | and &amp;, where I might want the symbol to apply to the find or the exec commands on different occasions?  On the same theme, what is the syntax if I want to use tee to view the output of the -exec commands on the console (to watch progress) and also appended to a file (for later use)?   (I know shells vary but hopefully the most used shells such as sh/csh are quite similar?)  Update:  In part, I want to learn if nested find -exec can be done without scripting, as a simple command. Here is the use-case that prompted the questio :   outer find: find all subdirs matching DIR_MATCH_TEXT in DIR1  inner find: for each matching subdir found in the outer loop (call it DIR2), execute the commandfind DIR2 -name "FILE_MATCH_TEXT" -exec sha1 {} \; &gt;&gt; DIR1/DIR2_hashes.txt   The aim being to create a set of files, one for each matching subdir, containing the output of some find -exec action on that subdir.  By this I mean that, if /backups contains /jan2017 and /feb2017, the result will be two files at /backups/jan2017_hashes.txt and /backups/feb2017_hashes.txt, with jan2017_hashes.txt containing the output from sha1 for (say) all .pdf files in /backups/jan2017, and feb2017_hashes.txt containing the output from sha1 for all .pdf files in /backups/feb2017.  From replies so far I gather the outer find would have to use a shell call as the argument to -exec?
16320
When I'm using  find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt"  it finds all the types of file. But when I add -exec at the end:  find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt" -exec sh -c 'echo "$0"' {} \;  it seems it only prints .txt files. What am I doing wrong?  Note: using MINGW (Git Bash)
94270
The command that I have prints out two of the lines whenever FW_6.0.0 is found, below is the code:  grep -oP 'FW_6.0.0, (.*)$' file   Below is the output, both has the same value of FW_6.0.0  FW_6.0.0, SUCCESS FW_6.0.0, OK   I would like to match two words, that is FW_6.0.0 and SUCCESS that can be found on the same line so that it prints this out:  FW_6.0.0, SUCCESS and eliminates FW_6.0.0, OK
99810
I run this command:  ~/shell_temp$ find . -type f -name "IMAG1806.jpg" -exec rm -f {}\   i got output below:  &gt; IMAG1806.jpg  Error: find: missing argument to `-exec'   what is exact command for find any file from current directory and remove with -exec?
20132
I was just trying to list all directories and files under current directory and also write if they are file or directory with the following command:  find -exec echo `echo {} : ;if [ -f {} ]; then echo file; else echo directory;fi` \;   I know it is a silly command, I can use other things like -type f or -type d, but I want to learn why that piece of code did not work as I expected. It just prints directory to all of them. For example while output of find is:  . ./dir ./dir/file   output of my code is :  . : directory ./dir : directory ./dir/file : directory   And output of   echo `echo dir/file : ;if [ -f dir/file ]; then echo file; else echo directory;fi`   is  dir/file : file   I am working on Ubuntu 14.10 and using find (GNU findutils) 4.4.2
120194
I used this command to display the first result of files in my directory.    ls | head -n 1   My simple question is, how can I modify this command to display say the nth result?  Thanks!
42775
I had a command which would work through a text file, count all the occurrences of the words and print it out like this:  user@box $˜ magic-command-i-forgot | with grep | and awk | sort ./textfile.txt 66: the 54: and 32: I 16: unix 12: bash 5:  internet 3:  sh 1: GNU/Linux   So it does not search line-by-line, but word by word, and it does it for all the words, not just for 1 word. I'd found it somewhere on the internets a long time ago, but I cannot find or remember it..
33970
I am trying to get a list of open files per process. I ran the following one-liner from :  lsof | perl -lane '$x{"$F[0]:$F[1]"}++; END { print "$x{$_}\t$_" for sort {$x{$a}&lt;=&gt;$x{$b}} keys %x}'   It returns the total count of open files, and the process name and pid. The result is sorted in ascending order, and the last line is as follows:  1065702 java:15437   So when I run lsof -p 15437, I would expect it to return the same number, however I'm getting:  $ lsof -p 15437 | wc -l 403   Why the discrepancy?  Addendum  A third source of discrepancy:  $ cd /proc/15437/fd $ ls -1 | wc -l 216
5216
In FreeBSD and also in Linux, how can I get the numerical chmod value of a file? For example, 644 instead of -rw-r--r--? I need an automatic way for a Bash script.
42204
If I have really long output from a command (single line) but I know I only want the first [x] (let's say 8) characters of the output, what's the easiest way to get that? There aren't any delimiters.
62418
I am using find -type f command to recursively find all files from a certain starting directory. However, I would like to have some directories prevented from entering and extracting names of files inside. So basically I am looking for something like:  find . -type f ! -name "avoid_this_directory_please"   Is there a functioning alternative to this?
100828
For use in a shell-script, I'm looking for a commandline-way to get the destination of a symbolic link. The closest I've come so far is stat -N src, which outputs src -&gt; dst. Of course I could parse the output and get dst, but I wonder if there is some direct way of getting the destination.
111324
I declare a variable for a 64 bit counter as :  long long call_count;   What is the format specifier that I should use in print statements?  I tried, %l, %ld, %ll. None seems to be correct.  I use Diab C compiler for compiling my application code to run on pSOS operating system.
7604
I keep stumbling on the format specifiers for the printf() family of functions.  What I want is to be able to print a double (or float) with a maximum given number of digits after the decimal point.  If I use:  printf("%1.3f", 359.01335); printf("%1.3f", 359.00999);   I get  359.013 359.010   Instead of the desired  359.013 359.01   Can anybody help me?
10724
Here is my script (to find the files that contain a specified pattern):  find . -type f \     -exec awk -v vawk="$1" '/'"$vawk"'/ {c++} c&gt;0 { print ARGV[1]; exit 0 } END { if (! c) {exit 1}}' \{\} \;   I would like to use my script with an argument §:  MyScript.sh pattern   My problem is that I don't manage to put the $1 variable in awk.  When I try to debug my script  bash -x MyScript.sh pattern   Here is the output :  + find . -type f -exec awk -v vawk=pattern '// {c++} c&gt;0 {print ARGV[1] ; exit 0 } END { if (! c) {exit 1}}' '{}' ';'   The $vawk variable seems to be empty.  Any idea?
15189
time is a brilliant command if you want to figure out how much CPU time a given command takes.  I am looking for something similar that can list the files being accessed by a program and its children. Either in real time or as a report afterwards.  Currently I use:  #!/bin/bash  strace -ff -e trace=file "$@" 2&gt;&amp;1 | perl -ne 's/^[^"]+"(([^\\"]|\\[\\"nt])*)".*/$1/ &amp;&amp; print'   but its fails if the command to run involves sudo. It is not very intelligent (it would be nice if it could only list files existing or that had permission problems or group them into files that are read and files that are written). Also strace is slow, so it would be good with a faster choice.