Tag Info

New answers tagged

1

Assuming your file names don't contain newline characters and your grep supports the -o option: find [[:upper:]] -type f | grep -Eo '^./[0-9]{3}' | sort | uniq -c


0

This will do what you've asked: for d in */* do n=$(find "$d" -maxdepth 1 -type f -printf "ok\n" | wc -l) printf "%s\t%d\n" "$d" $n done The primary differences to your code are that I've used find instead of ls so that weirdly named files won't break the count (think of \n in a filename), and that I've used printf to format the output.


0

Perhaps something like: find $PWD/ -type d -exec find {} -maxdepth 1 -type f -printf "%h\n\0" \; | uniq -zc find $PWD/ -type f -printf "%h\n\0" | uniq -zc Yield something like: 7 /foo/ 17 /foo/bar 9 /foo/baz Note that it only count files, not directories. Add a | sort -z before uniq to sort it.


0

The simplest way to get what you want is to use the -n option to echo when you print the directory name. That avoids printing a newline at the end of whatever you're echoing, so the next output stays on the same line. Other languages may be a better option if you want to collect the information you're looking for and then run multiple transformations on it ...


0

You can built an array of files for each directory separately, and then just count the number of elements. In bash that would be something like for dir in */*/; do a=( "$dir"/* ); printf "%s\t%s\n" "$dir:" "${#a[@]}"; done If A/001 etc. contains directories too which content you would like to include, then add ** glob: shopt -s globstar for dir in */*/; ...


-2

du path_to_your_files/*.jpg | awk '{ total += $1 }; END { print total }'


2

My solution might be a little heavy but well, who knows. The problem is that, in order to do that, you would need to count files... which is usually done with: $ ls | wc -l Now, because the content is written to a pipe, and not to stdout, this will take a little less time to complete (writing to a terminal takes a little bit of time, which can become ...


8

You can reenable aliases as described at http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo the short version is to add and alias for sudo as alias sudo='sudo ' to get it to check the rest of the command for aliases. Otherwise, the sudo is check to see if it's an alias, it is not, so the rest of the alias checking ends. If sudo ...


3

I should think: ls ./* | cut -d '.' -f 1,2,3 | sort -u will get you there, this essentially lists the contents of the directory, then cuts off everything after the third '.' and then sorts the lines and removes duplicates. The end result would be a list of 'abc.sh.ID'. If you want you loop through this new list and do an 'ls [line]*' to get the ...


1

--hide=PATTERN in the fine manual looks promising, e.g. set a shell alias for ls that includes appropriate things to hide.


1

This method doesn't score highly in terms of correctness but should work in most cases: cat "$(ls -1t | head -n1)"


3

If you're going to just cat a newest file in one command you don't really need -l option. On Linux and Cygwin you can use -1 option and make parsing much easier: $ cat "$(ls -1rt | tail -n1)" -1 should be very portable, it's specified in POSIX. Also keep in mind that parsing ls output has its drawbacks. EDIT: As correctly noted in a comment by ...


0

Tried it on my system and: ~$ cat "$(ls -lrt | tail -n 1 | tr -s ' ' | cut -d ' ' -f9)" worked. ls -lrt Gives the files ordered by their modification time (-t) in reverse order (-r). tail -n 1 Gives you the last line of the output. tr -s '' Removes the repeat spaces in the line. cut -d ' ' -f9 Cuts the line on every space and gives you the ...


-1

Bash one-liner (provided your filenames do not contain spaces): cat $(ls -lrt | tail -1 | rev | cut -d" " -f1 | rev) Explanation: tail -1 # get last line of your ls rev # reverse characters order cut -d" " -f1 # take first field using space as a separator So the rev | cut -d" " -f1 | rev thing is a trick to be sure to get the last ...


5

Those files are special files called devices. They don't have a size parameter, but two number called major and minor number. Major is somehow related to type of device (terminal, disks, network interface, filesystems). Minor is related instance number. I use the word "related", you simply do not count, different disk might have different major number. ...


-1

for i in `ls -1`; do echo $i : `ls -1 $i|wc -l`; done


0

Yet another way to achieve it is print *(/) or echo *(/) Update1 A bit more correct version (as noted by @St├ęphane Chazelas) would be print -rl -- *(/) or echo -E - *(/) respectively to take care about spaces, escape sequences and leading hyphens inside filenames. Update2 Yet even more correct version is print -rN which additionally takes ...


2

This will get you the count of files in each subdirectory of the current directory, dealing with any strange file names (with gnu find). find . -maxdepth 2 -mindepth 2 -type f -printf "%h\0" | uniq -zc | tr '\0' '\n'


1

Assuming that you have no spaces in your directory names: for dir in $(find . -type d); do echo "${dir}: $(find ${dir} -maxdepth 1 -type f | wc -l)" done


2

With ksh93: printf '%s\n' {12}(?) for (non-hidden) files whose name are made of 12 characters. Or if you prefer regular expressions: printf '%s\n' ~(E)^.{12}$


2

With zsh you could use a glob like ?(#cN) (here the c flag requires the previous ? to match exactly N times): setopt extendedglob print -rl -- ?(#c12) if you prefer ls: ls -d -- ?(#c12) You can also add qualifiers, e.g. search recursively for regular files with fixed name length: print -rl -- **/?(#c12)(.)


1

printf '%s\n' * as a shell command will list the non-hidden files in the current directory, one per line. If there's no non-hidden file, it will display * alone except in those shells where that issue has been fixed (csh, tcsh, fish, zsh, bash -O failglob). echo * Will list the non-hidden files separated by space characters except (depending on the ...


1

If you just want a list of directory contents: find . -maxdepth 1 or for any other dir: find <dir> -maxdepth 1


1

Using the same ls -CFUd as muru but in zsh, you could try with: setopt nullglob ls --color -CFUd -- *(/) *(*) *(@) *(p) *(=) *(^/*@p=) where (...) are glob-qualifiers matching directories, executables, symlinks, pipes, sockets and respectively everything else.


1

If dirty hacks are welcomed, the following might come close: ls -C --color -F -1 | rev | sort | rev Essentially: rev to get the last character first then sort, which will now use the last character first then rev again to get back the original line This, unfortunately, has single-column output. You can apply column to it to get multi-column output, ...


0

With zsh: setopt extendedglob print -rl -- **/file.php(.om:h) .om sorts the selected files by mtime and :h removes the trailing path component. If you want to list mtimes too, you could use zstat: zmodload zsh/stat for f (**/file.php(.om)) printf '%s %s\t%s\n' $(zstat -F '%d-%b-%Y %T' +mtime -- $f) ${f:h}


0

With zsh and (.m[-|+]n) glob-qualifiers: print -rl -- *(.m90) will list files modified exactly 90 days ago, print -rl -- *(.m-90) will list files modified in the last 90 days, print -rl -- *(.m-100m+80) will list files modified between 80 and 100 days ago.


0

With zsh and glob-qualifiers: print -rl -- *(.[1,-11]) will list all regular files except the last ten ([1,-11] means from the first up to the eleventh-to-last) If you're happy with the result replace print -rl with rm: rm -- *(.[1,-11])


1

Presumably the external drive uses a filesystem such as a FAT variant which doesn't store permissions, and was mounted with all permissions allowed to everybody. The tool you used to copy files retained the original permissions. The garish color alerts you that the files are world-writable. In the output of ls -l, the rwx permissions are grouped in three ...


0

To Turn Off the color: unalias ls To Turn On the color: alias ls='ls --color=auto' To Temporarily disable the color: \ls -ltr


12

Accepting command options arguments after file operands is not standard and isn't often supported in non-GNU system, you need: ls -d1 sel* A note that -d1 isn't depth 1 like you think. -d tell ls list directories themselves, not their content -1 tell ls list one entry per line



Top 50 recent answers are included