Tag Info

New answers tagged

6

find will set its return code to non-zero if it saw an error. So you can do: if ! find ... then echo had an error >&2 fi | while ... (I'm not sure what you want to do with the find output). To collect all the error messages from find on stderr (file descriptor 2) you can redirect 2 to a file. Eg: if ! find ... 2>/tmp/errors then ...


1

With zsh (using the glob qualifier D): print -rl ./**/.*(D) To include non-hidden files in hidden directories: setopt extendedglob print -rl ./**/*~^*/.*(D)


1

There is no difference between directories created by the system or by the user because in the end it is the same system call. Lateron it is impossible to tell who was the owner of the process which created the file or directory. By the way, "the Linux system" is mostly the user root, there is no special user. Furhtheron, installing always sets the owner of ...


1

Depending on what you mean by "created by system", you may be able to use the packaging system to determine how a particular directory was created. For example, on an RPM-based system (e.g. RedHat, Fedora, CentOS etc): rpm -qf /var will give something like filesystem-2.4.100.x86_64 indicating it was installed as part of the filesystem package, whereas ...


0

With zsh: print -rl mydir/**/*.A(.e_'REPLY=$REPLY:r; [[ -f $REPLY.B ]]'_) :r removes the extension, so if the content of $REPLY was mydir/somedir/somefile.A after running REPLY=$REPLY:r its content becomes mydir/somedir/somefile; the rest is similar to this answer.


0

If on the mac, be aware also of *.localized files, which may become invisible even to 'ls -la', 'find' and their ilk on a FUSE filesystem. [ This discovered using a ConnectedData Transporter-created FUSE filesystem on a MacBook Pro.]


5

I don't think that there is a concept of "directory created by system". When you're installing your system, installation media often gets job done for you - you see the result(e.g. /etc directory created), but that really is done by user who happened to run script. Anything created by "system" could be treated as created by root, but there's no way of ...


0

With zsh and glob qualifiers (estring): print -rl -- *(/e_'[[ ! -f $REPLY/README ]]'_) or print -rl -- *(/^e_'[[ -f $REPLY/README ]]'_) add D to include hidden directories: print -rl -- *(D/e_'[[ ! -f $REPLY/README ]]'_) / selects only directories and e_'[[ ! -f $REPLY/README ]]'_ further selects only the directory names for which the shell code ...


2

Use this: find -name "* *" -print0 | sort -rz | \ while read -d $'\0' f; do mv -v "$f" "$(dirname "$f")/$(basename "${f// /_}")"; done find will search for files and folders with a space in the name. This will be printed (-print0) with nullbytes as delimiters to cope with special filenames too. The sort -rz reverses the file order, so that the deepest ...


0

find $1 -depth -name "* *" -type d -execdir rename 's/ /_/g' "{}" \;


0

separate between filename basename (i.e. last name in the path) and dirname: find $1 -depth -name "* *" -print0 | \ while read -d $'\0' f ; do a="$(dirname "$f")" b="$(basename "$f")" #optional check if the basename changes -> reduces errors in mv command #only needed when using -wholename instead of -name in find, so skippable if [ ...


0

To those wondering why you'd want to do this, follow this thread: https://community.linksys.com/t5/Wireless-Routers/Media-files-changing-to-folder-types/td-p/504192/highlight/true Apparently a bug in the firmware flipped the bit in the directory entry for the file, making the OS think it's a folder instead of a file. While I don't have the Linksys router ...


0

Alternatively to Fixman's idea, you could also just make it a symlink to itself. sudo ln -s foo /tmp $ touch /tmp/foo/bar touch: cannot touch ‘/tmp/foo/bar’: Too many levels of symbolic links #Or sudo mkdir -m 000 /tmp/foo # create with mode 000, no permissions at all. Creating them as root will block non-root malware from removing / renaming them. ...


6

When you run emacs it creates a backup file, int his case test.txt~. If there was already a file with that name I suspect it deletes it and creates a new one. That new file creation is modifying the directory, and thus updating its modified and changed times. If you were, instead, to say echo new line >> blah.txt you would not be creating any extra ...


2

This should do it. Where the first column (size) exceeds 10gb, output the second column (directory name) du -sk * | awk '$1 > 10485760 { print $2 }' Or as requested, to show in human readable form, as below. The regular expression ensures column 1 ends in a G (gigabytes) and the substr part strips the final letter from column 1 and looks to see if ...


7

use ls -l -d /tmp/ and you will see that the permissions are set to drwxrwxrwt, i.e. d: a directory, rwx: read, write and execute permissions allowed for owner, group and others (in this order), t sticky bit, i.e. only file owners are allowed to delete files (not the group despite permissions). Let's leave the sticky bit aside for the moment and mention that ...


1

> So why can apache open this directory (dir1) ? I haven't an answer for this, normally it should not be able to. > It is possible to make a group in a group ? No, in Linux all group members must be users. > Or to made a group the owner of a directory ? Yes, you can assign ownership of a directory to a user and a group via the command chmod ...


1

If a user can't access /a/b, then they can't access any file under /a/b/c. The permissions on /a/b/c are irrelevant since directory traversal stops at /a/b. If all you want is to prevent the directory /a/b from being listed, but you're fine with users accessing files in /a/b if they guess a file name, then you can make /a/b executable but not readable. On a ...


31

You can. You just have to set the executable bit on the /a/b directory. That will prevent being able to see anything in b, but you can still do everything if you go directly to a/b/c. % mkdir -p a/b/c % chmod 711 a/b % sudo chown root a/b % ll a/b ls: cannot open directory a/b: Permission denied % touch a/b/c/this.txt % ls a/b/c this.txt Beware that ...


8

With those permissions, you can't reach your goal. In order to get to directory c, you must allow all other users to traverse directory b which is done by giving execute permission for that directory. With /a/b set to mode 711, you can achieve what you want since you are granting directory traversal but denying read and write. But do keep in mind that while ...


1

The cache that matters most for directory traversal is the inode cache. This isn't included in the “cache” figure that free displays. It's part of the kernel data (the “slab”). You can see how much memory the various slab pools occupy in /proc/slabinfo (this requires root access). You can use slabtop to see them vary in real time, or this snippet to get a ...


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


1

If it has to be quick, I generate a new temporary directory, mv the directory below it and then recursively delete the temporary: t=`mktemp -d` mv certainFolder $t/ rm -rf $t &


5

Tracking freed blocks is unavoidable in any decent file system and ZFS is no exception. There is however a simple way under ZFS to have a nearly instantaneous directory deletion by deferring the underlying cleanup. It is technically very similar to Gilles' suggestion but is inherently reliable without requiring extra code. If you create a snapshot of your ...


4

What you're asking for is impossible. Or, more precisely, there's a cost to pay when deleting a directory and its files; if you don't pay it at the time of the deletion, you'll have to pay it elsewhere. You aren't just removing a directory — that would be near-instantaneous. You're removing a directory and all the files inside it and also recursively ...



Top 50 recent answers are included