Hot answers tagged

12

If you have GNU find, you can use -printf: find content/media/ -type f -printf '%p : %u : %g : %k'


11

Use stat on the -exec action of find: find .content/media/ -type f -exec stat -c '%n : %U : %G : %s' {} + Change the format sequences of stat to meet your need.


7

ls doesn't do pattern matching on file names. It just lists the content of the directories and the files it is being given as arguments. Your shell on the other hand has a feature called globbing or filename generation that expands a pattern into a list of files matching that pattern. Here that glob pattern would be abc*.zip (* being a wildcard that stands ...


5

No, since ls (or any other file-operating process) is in the process state "uninterruptible sleep", there is nothing that can interrupt it, even SIGKILL can't. Maybe you can lower the timeout values when mounting remote filesystems. sshfs has ServerAliveInterval and ServerAliveCountMax.


4

The problem is that find finds the Webcam directory, too, and runs ls Webcam which lists all the files there. To only list files, not directories, tell find -type f


4

Your problem is that ls -lR will be executed for all files (which will display the files) and every directory (which will display the contents of the directory). If your directory-hierarchy would not be flat, but contain sub-directories, this would display the contents even more often, as -R tells ls to traverse subdirectories again. Instead you should ...


3

With printf/xargs: printf "%s\0" */ | xargs -0 -n3 echo do-something printf prints the current directory contents null delimited. The slash after the * matches only directories, not files. xargs reads the input null delimited -0 -n3 splits the input in 3 parts. The output (with your example directories): do-something abc/ def/ hij/ do-something ...


3

Throw xargs into the mix. E.g.: ls | xargs stat


3

What is wrong with a simple Bash for-loop? for f in ./* do stat "$f" done With the quotes and the ./ prefix, this is safe against the worst file names.


2

It seems you can't do this with dircolors, but you can do it by modifying LS_COLORS directly: eval "$(dircolors)" LS_COLORS="${LS_COLORS}*~=01;34:" export LS_COLORS dircolors only seems to handle three types of descriptors: terminal names (starting with TERM), file types (e.g. DIR), and extensions starting with .. The latter get expanded by prefixing them ...


2

If you are developing and targeting OS X, better to look at OS X ls manual page, not Linux one and stick to the options documented there. Alternatively, if you want your script to "unbreakably" work on every Unix implementation, you are more or less doomed. While there is a common set of options you'll find in all implementations which are the ones defined ...


2

There's no reason to do either of the following mistakes for this situation: Use non-portable GNU extensions (such as xargs -0) Parse the filenames as a stream of text only, pretending that they can't contain newlines. You can handle this portably without much difficulty at all: set -- */ while [ "$#" -gt 0 ]; do case "$#" in 1) my-command ...


2

The root cause of this problem is amazingly short: . (yes: a dot). Understand that find (without a dir) is equivalent to find .. From man find: If no paths are given, the current directory is used. And, when you execute find . the dot appears in the generated list ( Using only four files with distinct names to make it simple ): $ find ...


2

If you define an alias such as alias ls='ls --time-style=long-iso' then ls invocations which end up displaying dates will use that.


1

Breaking it into two parts: ls -Ra List all (-a) files recursively (-R). The -a means that files which start with the "." character, which are normally not shown, will be included. The -R means that any subdirectory that ls finds will also be listed, and all subdirectories within those, and so on. grep -cve/ -e'^\.*$' The -c means return the count of ...


1

If I could modify Otheus's answer little bit, it would be like this for d in ``ls -1 | xargs -n 3 echo` ; do (cd "$d" && somecommand); done and so on with other directories too.


1

The problem What are you trying to do? Let me try to explain your command so I understand it: ls -Ra | grep -cve/ -e'^\.*$' will give you: The number of files, directories, symbolic links, ... Including the current directory Excluding files with names only consisting of dots: touch '...' (!!!) The solution If you want to do the exactly the same with ...


1

#!/bin/bash # Array of root folders folders=("a" "b") # Search all specified root folders for f in ${folders[@]}; do # Descend hierarchy and retrieve modification date of each file with "stat" find $f -type f -exec stat -f "%m,%N" {} ';' | \ # sort by date, most recent first sort -gr | \ # extract first (most recent) file ...


1

Once the output of ls is on the terminal, it stays colored. But if you run ls again, whether the output is colored depends on the options you pass to ls this time. The ls command doesn't remember settings from one time to the next. If you want to have default settings for a command, define an alias for it. For bash, the file where aliases are defined is ...


1

ls abc*.zip This however will fail if there are too many files (there is a limit to shell expansion in term of how many arguments it can expand to). find . -name "abc*.zip" This is probably the most universal. The quotes must be there. With some find implementations, you can also use -iname instead of -name for case insensitive search ...



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