why does not work this condition?  if [ -d /home/virt -a $(ls -A /home/virt/) = 0 ]   Exists of directory /home/virt AND check if the directory is /home/virt/ empty  Thank you...
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).
26761
I was viewing my .bash_profile file, and I saw this written inside a block of if statement:  if [ -f ~/.bashrc ]; then        . ~/.bashrc    Can someone explain what the second line is actually doing?
58458
I was working in my terminal, when I misspelled while cd to root (/). Accidentally, I typed // and I got in terminal:  root@weblocalhost://#   When i type pwd, i get response // but when I type ls -s i got same list as in / directory.  When you type more than 2, i.e. /// you get:  root@weblocalhost:/#   Always 1 / except for 2. Is there any difference and what is // for?
24526
When trying to move a test_dir directory to /dev/null, I get the message  mv: cannot overwrite non-directory ‘/dev/null’ with directory ‘test_dir/’   Then why do people say "Don't run the command sudo mv ~ /dev/null, it will move your home directory to a hole?"    But /home is also a directory.
25194
I am trying to pull logs and doing few others things directly. written a small line BASH but not working. I am sure thats with IF Condition.    sed -rne '/21:25:07/,/21:50:07/ p'  server.log.2015-04-21 &gt; /tmp/filename.log ; du -sh  /tmp/filename.log ;  if [`du -sh  /tmp/filename.log` -gt 0] then gzip /tmp/filename.log ;
31242
How to match the hidden files inside the given directories   for example   If I give the below command it's not giving the result of the hidden files,     du -b maybehere*/*   how to achieve this simple using a single command instead of using   du -b maybehere*/.* maybehere*/*   as I need to type maybehere twice.
42698
That is literal, {fd} isn't a placeholder. I have a script that does this, and does not source in anything, nor does it reference {fd} anywhere else.  Is this valid bash?  exec {fd}&lt;/dev/watchdog
72084
I'm learning Ubuntu and experimenting with things.  I noticed I couldnt create a directory within /sys  Is this a special directory or something? Are there other types of directories?  (I did a sudo -i and a chmod a+w /sys)
65386
In a few spots I got this to work  ls -rt /path/to/log/file/ | tail -1 | xargs tail -f   But I can't figure out why it won't always work (This is quick fix until I get the log rolling fixed here)
18550
In bash all I know is that   rmdir directoryname   will remove the directory but only if it's empty. Is there a way to force remove subdirectories?
40712
Edit: This is a duplicate of .  I don't have the reputation to close this question as duplicate.  I'm not referring to ~ as in the home directory but rather this:  $ ls ~foo/bar /some/mount/point/foo/bar   However if I attempt it with a different mount point, e.g.:  $ mount | ag "/dev " devfs on /dev (devfs, local, nobrowse) $ ls /dev/stdin /dev/stdin $ ls ~stdin zsh: no such user or named directory: stdin .  # bash has a similar error message:  ls: ~stdin: No such file or directory   What is the ~ called in this context?  How does it work?  Edit: More information based on some of the comments below:   I can attest that foo is not a username on my system. When attempting to autocomplete ls -lah ~ not all options are shown.  i.e. I'm able to cd ~qux, when qux doesn't show up in the autocomplete.  Again qux is not a user in my system. If it matters /some/mount/point is a network share. All of the details suggest some named path muckery, a Z shell feature of pathname expansion, but this works in bash as well, which apparently doesn't support things like the Z shell's named paths.
3269
Well, I have few directories have name contains hashes (#, eg: #abczxy). Now I can't to execute this cd #foo it will redirect me back to the root directory equal with this command cd  The question is, is this possible to do that or is there any tricks allow me do that?  Thanks.
31266
I want to do some housekeeping in a directory, and I want to see if a given directory has any symlinks pointing to it. I can easily enough see what directory a symlink points to, but now I want to see the relationship in reverse.
27066
I have a requirement, if I execute a script ./123 with an arguments of empty path, say /usr/share/linux-headers-3.16.0-34-generic/.tmp_versions(this directory is empty). It should display "directory is empty"  My code is:  #!/bin/bash dir="$1"  if [ $# -ne 1 ] then     echo "please pass arguments"  exit fi  if [ -e $dir ] then printf "minimum file size: %s\n\t%s\n" \  $(du $dir -hab | sort -n -r | tail -1)  printf "maximum file size: %s\n\t%s\n" \  $(du $dir -ab | sort -n | tail -1)  printf "average file size: %s" du $dir -sk | awk '{s+=$1}END{print s/NR}' else    echo " directory doesn't exists" fi  if [ -d "ls -A $dir" ]  then     echo " directory is  empty" fi   I have an error displays like, if I execute the script name ./123 /usr/src/linux-headers-3.16.0-34-generic/.tmp_versions (this directory is empty).  minimum file size: 4096     /usr/src/linux-headers-3.16.0-34-generic/.tmp_versions maximum file size: 4096     /usr/src/linux-headers-3.16.0-34-generic/.tmp_versions average file size: 4   instead of showing output only "directory is empty" its shows the above output  The below output has to be display if I exceute the script with correct arguments( I mean with correct directory path). say ./123 /usr/share  minimum file size: 196         /usr/share     maximum file size: 14096         /usr/share     average file size: 4000   my expected output is: ./123 /usr/src/linux-headers-3.16.0-34-generic/.tmp_versions  directory is empty.
88942
I have two directories that should contain the same files and have the same directory structure.  I think that something is missing in one of these directories.  Using the bash shell, is there a way to compare my directories and see if one of them is missing files that are present in the other?
119503
I want to create this folder: $HOME/a/b/c/d while $HOME/a has not yet been created! Is it possible with one line in Terminal?
102550
I am writing a nightly build script in bash. Everything is fine and dandy except for one little snag:   #!/bin/bash  for file in "$PATH_TO_SOMEWHERE"; do       if [ -d $file ]       then               # do something directory-ish       else               if [ "$file" == "*.txt" ]       #  this is the snag               then                      # do something txt-ish               fi       fi done;   My problem is determining the file extension and then acting accordingly.  I know the issue is in the if-statement, testing for a txt file.    How can I determine if a file has a .txt suffix?