Hot answers tagged

14

This can happen if the current directory is renamed or moved while you're in it. For example: $ mkdir /tmp/X $ cd /tmp/X $ mkdir Y Z $ cd Y $ touch a b c d e f $ mv ../Y ../A $ mv ../Z ../Y $ echo $PWD /tmp/X/Y $ ls a b c d e f $ ls $PWD $ You can spot the difference in looking at the inode number of the directory: $ ls -ldi . $PWD 26871815 drwxr-...


9

As you've noticed, the file is created before ls is run. This is due to how the shell handles its order of operations. In order to do ls > file the shell needs to create file and then set stdout to point to that and the finally run the ls program. So you have some options. Create the file in another directory (eg /tmp) and then mv it to the final ...


8

The output file is created by the shell before ls begins. You can get around this by using tee: ls | tee list To thoroughly defeat any race condition, there is always ls | grep -vx 'list' > list Or if you like that tee displays the results as well: ls | grep -vx 'list' | tee list However, as pointed out in comments, things like this often break ...


5

First, the extglob controls what ls sees on its command line. It does not control what ls does with what it sees on the command line. This is important because the -R option to ls tells ls to explore recursively any directories it sees on the command line. So, even if the *uploads* directories are not given explicitly on the command line, ls will find them ...


4

This is not caching. You have to understand that in UNIX-like operating systems, there is a distinction between a name of a file, the file itself, and its contents. For example, a file might be found at /home/adam/myfile, but this maps to an 'inode' in the underlying filesystem. A hardlink is a different name for the same inode. The inode maps to some data ...


3

The problem you are having is not a sudo problem, but a root permission problem. The filesystem that has hduser's home directory is not local to the machine and doesn't grant root permission to it. So when you did su - hduser you automatically changed to that directory, so sudo ls tried to run the ls command as root and that is where the error came from. ...


3

You can make the filename temporarily hidden: ls >.list && mv .list list


3

To get ls to display the folder name instead of listing its contents, use its -d argument such as: ls -ld ~


3

You can use moreutils sponge: ls | sponge list Or with zsh: cp =(ls) list With GNU ls: ls -I list > list (though if there had been a file called list before, that means it won't be listed). Since ls output is sorted anyway, you can also use (assuming your filenames don't contain newline characters): ls | sort -o list Or to avoid the double ...


3

It looks like that's actually the username. Try checking the passwd file, and you might find that somebody tried to comment out a line: grep owner /etc/passwd If you find that there is a line starting with #, then if there is another line which doesn't have it, you may want to remove the line with the #. Otherwise, you may just want to remove the #. That ...


3

From the mv man page -t, --target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY mv's default behavior is to move everything into the last argument so when xargs executes the command it does it like mv /destinationFolder pipedArgs without the -t it would try to move everything into the last arg piped to xargs. With the -t ...


3

It's possible for a command to detect when its output is going to a TTY or not. Thus in this particular case, when ls detects that its output is not going to a TTY, it behaves as if -1 were passed as an argument. You can see this, and that grep is not doing anything special by using cat: ls | cat


2

To see how ls behaves when its output is being redirected, you can try running ls | cat or ls -1 which is how ls behaves when its output doesn't go to a TTY.


2

Partial/most credit goes to @StephenHarris... echo "`ls`" > list equivalent to echo "$(ls)" > list


2

Without ls, in bash, or some other shell that has arrays (this should work even with names that have funny characters in them): $ names=( my.parent/my.folder* ); echo ${names[-1]} my.parent/my.folder2 Without arrays (not so robust against funny characters, but saves a fork of the ls): $ printf "%s\n" my.parent/my.folder* | tail -1 my.parent/my.folder2


1

GNU du --max-depth=1 directly translates to BusyBox du -d 1. There's no equivalent of xargs -d; you can translate newlines to null bytes if xargs -0 is supported. du -d 1 -k | sort -nr | cut -f2 | tr '\n' '\0' | xargs -0 du -sh BusyBox has a lot of compilations to tune the compromise between size and features. If you don't have du -d, you can use du | ...


1

John1024 has added a good solution to your apparent problem, but based on the comments, you'd like to understand extglob better. I suspect that one of the core misunderstandings may have been that extglobs would work in a recursive manner -- that saying ./public_html/!(*uploads*) would exclude something named ./public_html/wp-content/uploads/. The globs (...


1

GNU ls gives you a choice between coloring files by their type or (if a given type is not colored) by a pattern. That is done by the dircolors program which has a built-in database of types, patterns and colors. ls does not care about the directory path itself. The aspect of "where they refer to" is not easily done with that program. Symbolic links ...


1

from man ls -h, --human-readable with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G) Meaning that it will display file sizes using K, M, G postfixes: 1K = 1024, 1M = 1024K, 1G = 1024M (all in bytes). see http://www.athropolis.com/popup/c-comp2.htm This is very similar to how the metric (SI) system works ( 1000μ = ...



Only top voted, non community-wiki answers of a minimum length are eligible