Tag Info

Hot answers tagged

30

From info ls: '-1' '--format=single-column' List one file per line. This is the default for 'ls' when standard output is not a terminal. When you pipe the output of ls, you get one filename per line. ls only outputs the files in columns when the output is destined for human eyes. Here's where ls decides what to do: switch ...


10

Because the output of ls depends on the std output, it is different for terminal and pipe. Try /bin/ls | cat


8

Historically, ls wrote its output one file per line, which is a convenient format for processing with other text-based Unix tools (like wc). However, on a 24 line terminal with no scrollback, large listings had a tendency to scroll off the screen, making it hard to find what you were looking for. So, at some point, the BSD developers changed the behavior ...


5

This usually indicates that the filesystem, specifically the meta data pertaining to that particular file has become corrupt. You could try performing a fsck on the disk, but I'd suggest doing this with the filesystem unmounted. Using /forcefsck You can usually schedule a check at the next reboot like so: $ sudo touch /forcefsck $ sudo reboot Using ...


4

Why does “ls | wc -l” show the correct number of files in current directory? Well, that's a false premise right there. It does not! Try this: mkdir testdir cd testdir # below two lines are one command, the newline is quoted so will be part of argument echo text | tee "file name" ls -l ls | wc -l Output of that last line is 2. Note how, when ...


4

Check your environment variable LC_COLLATE. The easiest thing will be to use the command locales. If you want, you can set it to a different value. For example, you can do (assuming bash) export LC_COLLATE="C" and that should fix your issue.


3

It's the programmable completion feature of the shell. You can simply press the TAB key twice to gain this behavior. Imagine you type cd Downkoads/St and then press the TAB key. St will be completed to Stuff if it is the only folder starting with St. If there are other folders starting with St in there, you will get a list of them by pressing TAB twice. For ...


3

You just need to create a list of glob matching files, separated by space: for file in .* *; do echo "$file"; done Edit The above one can rewrite in different form using brace expansion for file in {.*,*}; do echo "$file"; done or even shorter for file in {.,}*; do echo "$file"; done Adding path for selected files: for file in /path/{.,}*; ...


2

Colors The coloring is controlled by the DIR_COLORS* files that reside under `/etc. For example on Fedora 19 I have the following 3 files: $ ls -l /etc/DIR_COLORS* -rw-r--r--. 1 root root 5004 Jan 20 2014 /etc/DIR_COLORS -rw-r--r--. 1 root root 5682 Jan 20 2014 /etc/DIR_COLORS.256color -rw-r--r--. 1 root root 4646 Jan 20 2014 ...


2

They were probably pressing tab twice to get filename completion. What exactly you are shown depends a bit on the shell: zsh, for example, can be configured to show you file date and size as well, and it is clever enough to only show you directories since you can't cd into a file anyway. Example of bash output: $ cd (tabtab) dira/ dirb/ file.txt ...


1

If you use the find command you can omit the files that end in the extension .gz like so: $ ls -l total 0 -rw-rw-r--. 1 saml saml 0 Oct 15 22:42 FAIL -rw-rw-r--. 1 saml saml 0 Oct 15 22:42 FAIL.gz $ find . -name "*FAIL*" ! -name "*.gz" ./FAIL You can also filter ls output like so: $ ls *FAIL* | grep -v '.gz' FAIL But it's generally advisable to not ...


1

You can test against the presence of a regex for those extensions: for file in *FAIL*; do [[ ! $file =~ .(bz2|gz) ]] && printf "%s\n" "$file"; done Insert obligatory warning about not parsing ls...


1

Every directory has at least two references: one from its parent directory (the Volumes entry in /), and one from its own . entry. If there are subdirectories, each has a .. entry that refers back to the parent, and those also contribute toward the parent's link count. So your /Volumes directory's link count of 9 consists of one from /, plus one from ...



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