New answers tagged

0

ls -lhS sort by size, in human readable format


0

You can check the ACL access given to the directory_name run getfacl directory_name to understand the access given to the users.


0

This + symbol mean that the file has some additional attributes, like ACL


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

#!/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 ...


0

With gnu you could try: find "$(pwd)" -mindepth 2 -maxdepth 2 -type d -printf "d%h\0%T@ %p\0" | awk -v RS="\0" ' /^d/ {directoryname=substr($0,2)} /^[0-9]/ && (!lmtimes[directoryname] || lmtimes[directoryname] < $1) { lmtimes[directoryname]=$1; lmtimedns[directoryname]=substr($0,index($0," ")+1); } END {for (directoryname in ...


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 ...


0

The difference is that if you use -name you only match against the basename of the file. From man find: -name pattern Base of file name (the path with the leading directories removed) matches shell pattern pattern. The metacharacters (`*', `?', and `[]') match a `.' at the start of the base name (this is a change in ...


-2

If you like to write portable scripts, do not use GNUisms, e.g. long options. The options defined by POSIX are usually sufficient and most of the GNU long options are just aliases to the official short options that work everywhere.


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 ...


0

Try using ls abc*.zip to narrow down the results to those matching your criteria for a starting string of abc and an ending of .zip The asterisk will expand to match those results without including xvz starting characters.


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 ...


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 ...


0

Since Wildcard's solution is the one I eventually used, I've marked his answer as accepted, but if it's useful for people stumbling across this in the future, below is my code for distributing 330 directories amongst 11 other directories evenly. Perhaps worth pointing out that it seemed pretty damn fast too! #!/bin/bash numdirs=11 for ((i=1; ...


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.


3

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


0

find .content/media -type f -exec stat -c '%n : %U : %G : %s : %x : %y : %z' {} + %n File name, %U User name of owner, %G Group name of owner, %s Total size, in bytes, %x Time of last access, %y Time of last modification, %z Time of last change.


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.


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 ...


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 ...


0

This will use the find command to retrieve dot files and files with the "hidden" flag set. The matching files are fed as an argument list into ls via sed (to remove the "." result as well as leading "./" prefixes) and xargs. This allows for the specification of additional ls parameters (e.g. -l). alias l.="find . \( -flags +hidden -or -name '.*' \) ...


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.


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 ...


0

The -n argument to xargs can be sometimes used for this. If you want to run jobs in parallel, the -P option can be used as well. /tmp/t$ ls -1 dir1 dir2 dir3 dir4 /tmp/t$ ls -1 |xargs -n 3 echo runcmd runcmd dir1 dir2 dir3 runcmd dir4 Don't worry too much about parsing the output of ls|nl. If you need to worry about that kind of thing, you can use find ...


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.


-1

To stop all ls processes: pkill --signal SIGKILL ls


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.


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 ...


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 ...


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


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 ...



Top 50 recent answers are included