Tag Info

Hot answers tagged

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

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


8

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


5

You can use -o for logical OR. Beware however that all find predicates have logical values, so you'll usually need to group ORed things together with parens. And since parens also have a meaning to the shell, you'll also need to escape them: find /some/dir -maxdepth 1 \( -name '*.c' -o -name '*.h' \) -print


4

For files which are not device that is not the minor number but the size in bytes. The size of a directory depends on which filesystem is used, and how many entries (i.e. files or subdirectories) are in it.


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


4

The permissions you got were the permissions you asked for. The 't' comes from the '1' in the '1775' permissions string you specified, and sets what is called the "sticky bit". This tells the system that files in that directory can only be renamed or removed by the file's owner, the directory's owner, or the root user. The get the permissions you wanted ...


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

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.


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.


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


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


2

Those are not minor numbers (as they are for the device nodes). This answer explains each field in turn.


2

To answer your question, you can use -o option: expr1 -o expr2 Or; expr2 is not evaluated if expr1 is true. expr1 -or expr2 Same as expr1 -o expr2, but not POSIX compliant. like this: $ find . -maxdepth 1 -name "name1" -o -name "name2" ./name1 ./name2


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


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.


2

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

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


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.


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

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" $


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


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


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



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