Tag Info

New answers tagged

9

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


0

With zsh: print -rl -- **/*.(rar|zip)(DoL) Replace with ls -lUd -- if you want to see ls -l information about them (-U being a GNU extension). Note that it sorts by size, not disk usage.


1

The possible duplicate Link answered the question partly. To provide multiple name patterns to 'find' use this find $directory -type f \( -name "*.zip" -o -name "*.rar" \) The complete answer to the question is: find $directory -type f \( -name "*.zip" -o -name "*.rar" \) -print0 | xargs -0 -n1 du -b | sort -n -r with $directory being comp_tuts/ dir


3

There's no property on a file that indicates that it's hidden. Early versions of Unix had an ls command that hid files whose name begins with . (“dot files”) and that tradition stuck. The ls command, by default, hides files whose name begins with . and shows all other files. Some graphical file managers hide files whose name begins with ., just like ls, ...


3

opencv.sh~ is not a hidden file. POSIX defines a hidden file as one starting with a dot, but opencv.sh~ does not start with a dot. If you don't want to see these files, you can explicitly avoid them by using a glob that doesn't include them (for example, shopt -s extglob followed by ls !(*\~)), or (as I assume these are from vim), you can configure vim not ...


1

Most likely, for historical reasons and/or backward compatibility. It's part of the GNU core utilities package, so it'll be around until Richard Stallman et al feel it's necessary to purge it from existence.


2

With zsh and glob qualifiers: ls -d -- *([7]) or print ./*([7]) Ideally, if you're processing ls output, you should use something like ls -q | command(s) where -q prints ? instead of funky chars (like newlines) and command(s) processes only N lines of output, prints the Nth and then stops.


1

With tail and head (added nl for clarity). Let's fetch the fifth line : ychaouche@ychaouche-PC ~ $ ls | nl 1 total 8.3M 2 -rw-r--r-- 1 ychaouche ychaouche 20K Jul 8 15:53 2.docx 3 -rw-r--r-- 1 ychaouche ychaouche 20K Jul 8 15:53 3.docx 4 drwxr-xr-x 2 ychaouche ychaouche 4.0K Jul 7 10:11 AUDIO 5 drwxr-xr-x 3 ychaouche ...


0

The following little loop will list a count of all files (excepting symlinks) in child directories of . which exist on the same filesystem as the child directory. for d in ./* ./.[!.]* ./..?* do ! [ -h "$d" ] && cd "$d" 2>&3 || continue printf "%s:\t" "$d" find .//. -xdev -depth ! -type l | grep -c '^\.//\.' ...


4

You have an NTFS filesystem. In this case you cannot safely fix the problem on anything except a Windows machine. (The Linux code is good, but I cannot recommend you trust it to fix a foreign filesystem.) Take the disk to your Windows system and run CHKDSK /F Q:, or whatever drive letter it's been assigned. Then try deleting the file. If that fails you're ...


3

If you try ls -ld *z , you will see a directory ending in z. So, ls *z becomes ls "One-Directory-Ending-With-z" and so you get the contents of that Directory, which seems to have a lot of xml files.


0

Refer to Mat's comment. It is time for fsck. The situation you describe is rare. It appears you have at least two inodes pointed to dorothy[1].js + the directory entry for one inode is corrupt + thinks it's pointing to a directory. This should never happen, unless you're using dev/beta code for a filesystem. First run fsck. Then ensure you're running ...


0

try find * -print | awk -F/ '{c[$1]++;} END { for (c2 in c) printf "-%s -- %d\n",c2,c[c2] ;} ' where find from directory above the ones you want to sum up awk will count top level dir and file and sum up at the end.


1

Pure ksh93 solution: FIGNORE='@(.|..)' for dir in */; do a=( "$dir"/**/* ); printf "%s\t%s\n" "$dir:" "${#a[*]}"; done Result from /usr/src: linux-3.17.7-gentoo/: 561 linux-3.5.7-gentoo/: 517 linux-3.7.10-gentoo/: 505 linux-3.7.9-gentoo/: 513 linux-3.8.13-gentoo/: 551 linux-4.0.5-gentoo/: 1849


1

Will something like this suit your need: The path /boot is used for sample demonstration. Change it to the directory you need. for DIR in $(find /boot/* -maxdepth 1 -type d) do printf "%40s: %10d\n" "${DIR}" $(find ${DIR}|wc -l) done Output: /boot/grub: 282 /boot/grub/fonts: 2 ...


1

You could find the toplevel directories first, then use a second find, to count the number of files and directories within the toplevel directory: $ for dir in $(find . -maxdepth 1 ! -path . -type d | sort); \ do echo -n "$dir " && find $dir ! -path . | wc -l ; done ./adir 1151 ./anotherdir 140 ./623de41e44 280 ./examples 154 ...


-1

[On Linux / Bash] I'd do this: ls -l | sed -e"s/ \+/ /g" | cut -d' ' -f 9- The sed command collapses multiple spaces to a single space; the cut extracts the 9th field onwards where the field-separator is a space. Typical output from this: libboost_atomic.a libboost_atomic.so -> libboost_atomic.so.1.57.0 libboost_atomic.so.1.57.0 ... ...


3

q1) Doing a ls -ld show me a . - why ? When you give no arguments to ls, the default is to run the command on the current directory, also known as .. Normally that means listing the contents of the directory, but you have used the -d option which requests listing the directory itself, not its contents. So you get the information for ., the current ...


0

Native ls does not support this. Consider installing GNU coreutils.


1

Try file -sL /dev/sdXY. Will give you some limited information without mounting the filesystem. $ file -sL /dev/sdc1 /dev/sdc1: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=aa84c5a8-6418-4952-b577-578f2a67af86, volume name "music" $


2

The tool looking inside an unmounted partition would need to interprete the filesystem's sturctures itself. Such tools exist for various filesystem (cpmtools, mtools, ...) and some filesystems have similar functionality primarily intended to be a debugging help (as example see debugfs). But why do you think, looking into the filesystem first is neccessary? ...


1

you can skip Backup keyword from shell expansion by using !(keyword) ubuntu@vm-ubuntu:~$ ls *.log 1.log 2.log backup.log ubuntu@vm-ubuntu:~$ ls !(backup).log 1.log 2.log


3

I have this in my .bashrc. lsn () { ls ${@:2} | head -n $1 | tail -n 1 } This is called as such: lsn 4 for example. The $2 allows you to use options on ls so lsn 4 -lah is also valid. Note: when using the -l flag on ls there is an additional line at the top of the result. Which would skew this function's result.


8

Straight forward with awk: $ ls / | awk 'NR==4' etc


15

You could use sed to select a single line, for example line 12: ls | sed -n 12p Option -n asks sed not to print every line (which is what it normally does), and 12p asks to print the pattern space when the address is 12.


8

There may be better ways to do this, but this is probably the easiest: ls | head -<n> | tail -1


1

TXR: $ ls *.patch install-tests.patch match.patch netbsd.patch specials.patch wlist.patch $ txr -t '(glob "*.patch")' install-tests.patch match.patch netbsd.patch specials.patch wlist.patch $ txr -t '(set-diff (glob "*.patch") (glob "[mn]*.patch"))' install-tests.patch specials.patch wlist.patch


-3

What about parsing the output of ls through grep: ls -l *.log | grep -v backup.log


4

The shell expands the wildcard, so ls gets backup.log as one of the parameters. Use an extended pattern (enabled by shopt -s extglob): ls !(backup).log


3

One possibility would be: find . -maxdepth 1 -mindepth 1 -name \*.log -a -not -name backup.log i.e. find all files in the current directory or below, with an exact depth of 1 (so really only in the current directory and not the name of the current directory itself) with name matching the pattern *.log and not backup.log



Top 50 recent answers are included