I'm trying to use the find command to list the size of a certain set of files but am getting no output. The command I use is:  find POD -type f -name *.mp3 -or -name *.ogg -ls   Which produces no output. While:  find POD -type f -name *.mp3 -or -name *.ogg   does produce output, I've also tried the actions:  -printf "%p %k KB\n" -exec ls -ls '{}' \; -print0   but all of these give no output. When I use any of these actions with a different expression e.g.:  find . -maxdepth 1 -type f -printf "%p %k KB\n"   I also get the expected output. Does anybody have any idea what the problem is? I'm running:  Linux irimi 3.10.37-1-MANJARO #1 SMP Mon Apr 14 20:56:29 UTC 2014 x86_64 GNU/Linux   aka an up to date Manjaro linux distribution. The shell I use is: /bin/bash version 4.3.8(1)-release.  The content of my SHELLOPTS environment variable is:  braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor   my BASHOPTS environment variable is:  cdspell:checkwinsize:cmdhist:complete_fullquote:dotglob:expand_aliases:extglob:extquote:force_fignore:histappend:hostcomplete:interactive_comments:nocaseglob:progcomp:promptvars:sourcepath   Again any help on trying to debug this would be very much appreciated.
121491
I have read the man page and other references, but I am still confused by the behavior of find with -print0 option.  -print0      This primary always evaluates to true.  It prints the pathname of              the current file to standard output, followed by an ASCII NUL              character (character code 0).   First command:  $ find /some/path/ -iname "*intro*jpeg" -o -iname "*intro*jpg" 2&gt; /dev/null /some/path//asdf199Intro-5kqlw.jpeg /some/path/199intro-2jjaj.JPEG /some/path/199intro-3.jpg /some/path/wuer199intro-4.JPG /some/path/xbzf199INTRO-1.jpg   Second command:  $ find /some/path/ -iname "*intro*jpeg" -o -iname "*intro*jpg" 2&gt; /dev/null -print0 /some/path/136intro-3.jpg/some/path/wuer136intro-4.JPG/some/path/xbzf136INTRO-1.jpg   I can see that the the filenames from the second command are null character separated, but why do I get 3 output as opposed to 5 above?
16443
Using the Mac OS X Terminal, how do I write a find command that orders results by modification date (most recent first)?  There are similar questions already, but they refer to GNU find and POSIX, but I do not know whether Mac OS X is GNU or POSIX or something else.
45530
I am writing a simple helper function to show a specific folder in the format I want:  find . -maxdepth 1 -not -name "." -printf '[%TY-%Tm-%Td]\t%s\t%f\n' | sort -n   However I want to show the filesizes in a nicer format. I found  which I used to create a bash function called hr.  user@host:~$ hr 12345 12M   I tried using this in the find call as so:  find . -maxdepth 1 -not -name "." -printf '[%TY-%Tm-%Td]\t'$(hr %s)'\t%f\n' | sort -n   But it still continues to show the full filesize. How should I modify this so it works as expected?
39072
I'm trying to merge the output of 2 find commands and pipe it to the next operator. The arguments passed to both find executions are very similar so I'd like to keep it DRY  FIND_CMD_ARGS="-type f \( -iname \*.m -o -iname \*.swift \) -print0" CMD_OUTPUT=`{ find $PROJECT_PATH -not -path '*/Pods/*' $FIND_CMD_ARGS; find . -path '*/Pods/MyProject*/*' $FIND_CMD_ARGS }`   For some reason this doesn't work and this is the output I get  find: illegal option -- n usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]        find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression] find: -type f \( -iname \*.m -o -iname \*.swift \) -print0: unknown primary or operator   I think the issue is related to how the args in the FIND_CMD_ARGS environment variable are escaped but I can't figure out the right way to do it.  Any ideas? Thanks!
37896
I used ls -lS command in my home directory. This command is supposed to list down the contents of a directory by size. This is what I got after running this command  total 10148 -rw-rw-r--  1 rahul rahul 8053159 May 15 15:35 Costa_ODE.pdf -rw-rw-r--  1 rahul rahul 1755507 May 15 17:33 gnuplot.pdf -rw-rw-r--  1 rahul rahul  218048 May 13 22:14 out.log -rw-rw-r--  1 rahul rahul   98131 Feb 16 01:53 hs_err_pid8639.log -rw-rw-r--  1 rahul rahul   12364 Apr 19 14:01 Untitled 1.csv drwxr-xr-x  4 rahul rahul   12288 Jun  6  2016 cfitsio -rw-r--r--  1 rahul rahul    8980 Feb  7  2016 examples.desktop drwxrwxr-x  2 rahul rahul    4096 Mar 10 12:24 bin drwxrwxr-x  8 rahul rahul    4096 May  8 14:51 boxfitv2 drwxrwxrwx  2 rahul rahul    4096 Jan 30 11:50 dao2 drwxrwxr-x  2 rahul rahul    4096 Mar 12  2016 deja-dup drwxr-xr-x  6 rahul rahul    4096 May 16 02:12 Desktop drwxr-xr-x  3 rahul rahul    4096 May 15 10:53 Documents drwxr-xr-x  5 rahul rahul    4096 May  8 14:09 Downloads . . . .   and its a pretty big list. But I want you to focus on sub-directories, for example Desktop. Its size is shown as 4096 bytes. But when I tried to see the details of Desktop, this is what I got.    In short, the command ls -lS is not calculating the size of the contents of Desktop and other sub-directories. Is there any way to do it?    EDIT:  Output of ls -lsh command  total 10M 4.0K drwxrwxr-x  2 rahul rahul 4.0K Mar 10 12:24 bin 4.0K drwxrwxr-x  8 rahul rahul 4.0K May  8 14:51 boxfitv2 4.0K -rw-rw-r--  1 rahul rahul 3.2K May 13 13:28 c.c  12K drwxr-xr-x  4 rahul rahul  12K Jun  6  2016 cfitsio 7.7M -rw-rw-r--  1 rahul rahul 7.7M May 15 15:35 Costa_ODE.pdf 4.0K drwxrwxrwx  2 rahul rahul 4.0K Jan 30 11:50 dao2    0 -rw-rw-r--  1 rahul rahul    0 May 13 20:37 default.txt 4.0K drwxrwxr-x  2 rahul rahul 4.0K Mar 12  2016 deja-dup 4.0K drwxr-xr-x  6 rahul rahul 4.0K May 16 17:11 Desktop 4.0K drwxr-xr-x  3 rahul rahul 4.0K May 15 10:53 Documents 4.0K drwxr-xr-x  5 rahul rahul 4.0K May  8 14:09 Downloads  12K -rw-r--r--  1 rahul rahul 8.8K Feb  7  2016 examples.desktop . . .   Output of du -sh ~/Desktop command  80M /home/rahul/Desktop
70601
I need to monitor the network activities of a process and the bandwidth of the connection. So I decided to use nethog and netperf combine with grep and awk to write the values to a file.   nethog command: nethogs -t  eth0 | grep firefox | awk '{ print $3 }' (I want to take the upload/download speed). The 1st problem is that command doesn't print anything.  More detail: command: nethogs -t  eth0 | grep firefox output:  usr/lib/firefox/firefox-bi�)/4956/1000  0.338867    0.239063 /usr/lib/firefox/firefox-bi�)/4956/1000 0.543555    0.274219 /usr/lib/firefox/firefox-bi�)/4956/1000 0.794531    0.489844 /usr/lib/firefox/firefox-bi�)/4956/1000 0.794531    0.489844 /usr/lib/firefox/firefox-bi�)/4956/1000 0.749023    0.589844 /usr/lib/firefox/firefox-bi�)/4956/1000 1.30098 3.47617 /usr/lib/firefox/firefox-bi�)/4956/1000 1.90449 8.0127 /usr/lib/firefox/firefox-bi�)/4956/1000 5.31641 25.0033 /usr/lib/firefox/firefox-bi�)/4956/1000 8.60762 42.0176   I want the two values at the bottom right. But as you can see the output ain't consistent (the space), add | awk '{print $3}' most of the time return nothing. And I can't fix this.  netperf command: netperf -H 192.168.1.10 and the output is:  Recv   Send    Send                           Socket Socket  Message  Elapsed               Size   Size    Size     Time     Throughput   bytes  bytes   bytes    secs.    10^6bits/sec    524288 524288 262144    10.00    **718.62**   I want to print the value on the bottom right but have no idea how to. That's the 2nd problem => solved by  fedorqui!  Can you guys help me out? Any ideas will be appreciated!
28963
I thought this would be simple - but it is proving more complex than I expected.  I want to iterate through all the files of a particular type in a directory, so I write this:  #!/bin/bash  for fname in *.zip ; do    echo current file is ${fname} done   This works as long as there is at least one matching file in the directory. However if there are no matching files, I get this:  current file is *.zip   I then tried:  #!/bin/bash  FILES=`ls *.zip` for fname in "${FILES}" ; do     echo current file is ${fname} done   While the body of the loop does not execute when there are no files, I get an error from ls:  ls: *.zip: No such file or directory   How do I write a loop which cleanly handles no matching files?
107063
I am searching for a method to find only JPEG files/ With my limited knowledge of Linux I came to this point:   list all paths that exist from root below with find / pipe the result into next command and perform the file command on each found path with xargs file In the result of the file command is a JPEG string contained, I thought maybe it would be possible somehow to an IF-statement to filter only the JPEGs: If (JPEG contained in output of file command) {show argument of file}   once more:  find / | xargs file | "If statement"    Could you please correct me, give me a hint how to perform the task or give a solution?
59964
I can't for the life of me figure out how find with the test -name works.  I run find / -name *in and returns a bunch of results:  /sbin /sbin/sulogin /dev/stdin   to name a few.  It's as if it performed filename expansion, but that happens before the shell runs the command, so that can't be it. Also because I don't have any files in the current directory that match *in. Plus, single quoting *in yields the same results, which further supports that this can't be filename expansion.  The documentation leads me to believe that find with -name uses regular expressions, but the regex pattern *in doesn't match the results I showed above.  Can someone enlighten me?
93003
Is it possible to use the find command to find all the "non-binary" files in a directory?  Here's the problem I'm trying to solve.  I've received an archive of files from a windows user.  This archive contains source code and image files.  Our build system doesn't play nice with files that have windows line endings.  I have a command line program (flip -u) that will flip line endings between *nix and windows.  So, I'd like to do something like this  find . -type f | xargs flip -u   However, if this command is run against an image file, or other binary media file, it will corrupt the file.  I realize I could build a list of file extensions and filter with that, but I'd rather have something that's not reliant on me keeping that list up to date.  So, is there a way to find all the non-binary files in a directory tree?  Or is there an alternate solution I should consider?
124182
I want to list all the files, in directory I am currently in, with for example &quot;a&quot; in their name. I know that the first part of the command would be ls -l, but i do not know how to finish it.
61308
I've a simple bash script. PFB :  CWD=/cygdrive/c/Users/abhisek.samanta/Desktop/New_folder cd $CWD for i in `cat req_files.txt` do echo "file_found : $i"&gt;a.txt done   Note : req_files.txt is having a list of files which i need to find in this directory . If the files are found, it should list the name of the file which was found &amp; print it in "a.txt".   The req_files.txt is having multiple files,but only the first filename is getting printed &amp; not the rest of the files. Pl help.
90095
I'm trying to get my head around finding files in terminal at the moment. I've found a lot of answers about how to find files to a specific pattern, such as files ending in a certain extension, or from a certain timeframe, etc.  What I've been trying to figure out, though, is how to find and copy multiple arbitrary files, like a list of specific files.  Say, for example, I have the following folders and files  /Documents/Folder_1/ with contents:   file1.txt file2.txt file3.txt file4.txt   /Documents/Folder_2/ with contents:   file5.txt file6.txt file7.txt   /Documents/Folder_3/ with contents:   file8.txt, file9.txt   and what I want to do is to make a new folder called Folder_4 and copy file2.txt, file5.txt and file9.txt to that new folder.  Is there any way to do this through terminal?  What I've tried to do is to make a text list of the file names and call it something like list.txt, e.g.  file2.txt file5.txt file9.txt   and loading that text file into the Find command, for example like this:  find /home/usr/Documents -name $cat list.txt   with the thinking that I would then feed the output to either a text list or a copy command, but this doesn't seem to work.  I'm wondering if there is any way to find multiple arbitrary files through the Find command, or am I thinking about this in the wrong way?  EDIT: Just wanted to say thanks for the answers and summarise the way that I ended up approaching this problem. I especially appreciate that someone explained to me that the find command is not designed to accept more than one input without the -o flag, it made me feel a bit less stupid for not being able to figure it out!  What I ended up doing was to make a little shell script and ask for user input and use an array and a for loop to iterate through the list.  Basically the script that I ended up with is more or less like this:  #!/bin/bash  #take user input echo "Please enter list of filenames to search" read list echo "Please enter the folder path to search" read path echo "Please enter the destination folder path" read destination  #use inputted list as input for array, and then use a for loop to find each item on list one by one array=($list) for i in "${array[@]}" do     find "$path" -iname "i" -exec cp '{}' "$destination" \; done
5122
How can I determine the list of files in a directory from inside my C or C++ code?  I'm not allowed to execute the ls command and parse the results from within my program.
35309
I am trying to list all the files from dir1, dir2, dir3 and dir4 which might be anywhere in as a sub directory of my cwd using the find command. I tried the following with no success:  find . -type f -regextype posix-egrep -regex 'dir1/.+|dir2/.+|dir3/.+|dir4/.+'   I tried posix-extended as well. How can I list these files?
86352
I'm interesting in directing the output from two commands to a variable.  I don't want the output to be displayed on the screen, but instead assigned to a variable within my script so that I can use it again.  what I am doing is getting the file size from a directory using the commands seen below:  ls -l /var/spool | wc -c   This command gets me the file size in bytes and displays the output as an integer.  I am interested in getting this integer assigned to a variable of my liking so that I can compare it against another variable later  This doesn't seem to work:  size = ls -l /var/spool | wc -c   Would redirection work?   Like this....  ls -l /var/spool | wc -c &gt; size   Either way I want this numeric output to be assigned to a variable and not displayed on the screen.  Any suggestions are very welcomed!
27074
I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file is there. Once the largest file is found the output is displayed with the relative path name and the name and size of the largest file.  EX:  dude@shell2 (~...assignment/solutions) % bash maxfile.sh ~/test class/asn dude.h.gch: 9481628   This is what I have:  #!/bin/sh clear  recursiveS() {     for d in *; do         if [ -d $d ]; then             (cd $d; echo $(pwd)/$line; du -a; recursiveS;)         fi     done } recursiveS   I have been stuck for a while now. I cannot implement this by pipelining a number of existing Unix tools. Any ideas would be nice!