I have a file with a list of directories and I need to find out if they actually exist on the system. It's quite a large list so I'd like to figure out how to automate the check.  The file is formatted with each directory on a new line:  /usr/bin /usr/sbin /bin /sbin   Any suggestions? Thanks!
121065
How can I check if /bin/x86_64/bin/ls is a directory in a bash shell script  Here is what I tried:  #!/bin/bash  if [ $# -eq 2 ]; then     if [[ "$1" = /* ]]     then     cd ./bin/x86_64/bin/ls         if [ -d "$1" ]; then             echo "ok"             i="$1"             echo $i         else             echo "error2"             exit         fi     else         echo "error"         exit     fi fi
29342
Within a set of directories, how do I find a file whose name includes a given string, such as "abcde"?
81833
Just started reading a bit about the linux file system. In several places I found quotes like this one:      Unix directories are lists of association structures, each of which contains one filename and one inode number.   So I expected to find out that each directory would contain the names of the files under it, with each file mapped to an inode. But when I do vim directory_name in ubuntu, I get something like this:  " ============================================================================ " Netrw Directory Listing                                        (netrw v156) "   /Users/user/workspace/folder "   Sorted by      name "   Sort sequence: [\/]$,\&lt;core\%(\.\d\+\)\=\&gt;,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$,\.obj$,\.info$,\.swp$,\.bak$,\~$ "   Quick Help: &lt;F1&gt;:help  -:go up dir  D:delete  R:rename  s:sort-by  x:special " ============================================================================== ../ ./ folder1/ folder2/ file1 file2   I expected to see an inode number next to each file name, why isn't this the case?
34727
I want to test if a directory doesn't contain any files. If so, I will skip some processing.  I tried the following:  if [ ./* == "./*" ]; then     echo "No new file"     exit 1 fi   That gives the following error:  line 1: [: too many arguments   Is there a solution/alternative?
11145
I have a directory with a large number of files. I don't see a ls switch to provide the count. Is there some command line magic to get a count of files?
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.
17409
From a shell script, how do I check if a directory contains files?  Something similar to this  if [ -e /some/dir/* ]; then echo "huzzah"; fi;   but which works if the directory contains one or several files (the above one only works with exactly 0 or 1 files).
51957
if I want to count the lines of code, the trivial thing is  cat *.c *.h | wc -l  But what if I have several subdirectories?
93240
I'm looking for a script that counts files in the current directory (excluding sub directories). It should iterate through each file and if not a directory increment a count. The output should just be an integer representing the number of files.  I've come up with  find . -type f | wc -l   But I don't really think it does the whole counting bit. This is for an assignment so if you only want point me in the right direction that would be great.
22675
I have a text file that has a list of paths to various files. Is there a command I can use that will iterate through each line and delete the file at the stated path?
2402
What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:  import os  file_path = "/my/directory/filename.txt" directory = os.path.dirname(file_path)  try:     os.stat(directory) except:     os.mkdir(directory)         f = file(filename)   Somehow, I missed os.path.exists (thanks kanja, Blair, and Douglas). This is what I have now:  def ensure_dir(file_path):     directory = os.path.dirname(file_path)     if not os.path.exists(directory):         os.makedirs(directory)   Is there a flag for "open", that makes this happen automatically?
120423
I'm trying to compare files on the root file system with a backup, and I'd like the comparison to work a bit like git or svn diff when a file has been added or removed - That is, display the full file diff. diff unfortunately just prints a No such file or directory message, which is not very useful. I couldn't find an option for this.  The simplest workaround I could find is to parse the diff output and diff -u path &lt;(printf '') or diff -u &lt;(printf '') path depending on which path exists. That's a bit of a kludge - Probably 10 lines of code for what could be a simple diff option.  Another workaround is  diff -u &lt;([ -e "$path1" ] &amp;&amp; cat "$path1") &lt;([ -e "$path2" ] &amp;&amp; cat "$path2")   , but that loses the file names in the diff.  Based on  and the previous workaround, I ended up with this:  diff -u \     "$([ -e "$path1" ] &amp;&amp; echo "$path1" || echo /dev/null)" \     "$([ -e "$path2" ] &amp;&amp; echo "$path2" || echo /dev/null)"   Edit: Turns out there is an option for it:  -N, --new-file        treat absent files as empty   In other words:  diff -Nu "$path1" "$path2"
113848
I got a bunch of files in some directory (along with many other files) that I want to move.   Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.   But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?
112469
Say, I have some files, and I want to find the files among them which contain a string but do not contain another.  grep being line based, conditions such as grep -q printf file &amp;&amp; grep -vq '#include &lt;stdio.h&gt;' file will not work.   How should I go about doing this?  (I am on Debian, so answers specifically targeted at GNU versions of tools are fine.)
90281
I want to get a list of the directories and their sizes in a list format like how you get when you do a ls -l.  The thing is that is there a one line command that can do this? I see others have long commands just to output this. That's just too long.  What command can do this or combination of commands that can be easily typed? du -h gives it, but it displays all of the sub-folders which is not what I want. just the current directories folders.
34800
I want to find all files which contain a specific string of text. The grep command works, but I don't know how to use it for every directory (I can only do it for my current directory). I tried reading man grep, but it didn't yield any help.
73558
How can use dir command to check how many .txt files there are in a folder (for example,  C:\Temp\)?