Tag Info

Hot answers tagged

9

I always get burned when I try using .* for anything and long ago switched to using character classes: chown -R username.groupname .[A-Za-z]* is how I would have done this. Edit: someone pointed out that this doesn't get, for example dot files such as ._Library. The catch all character class to use would be chown -R username.groupname .[A-Za-z0-9_-]*


6

There's no need to do that, it's already in a variable: $ echo $PWD /home/terdon The PWD variable is defined by POSIX and will work on all POSIX-compliant shells: PWD Set by the shell to be an absolute pathname of the current working directory, containing no components of type symbolic link, no components that are dot, and no components that are ...


6

Using the extended globbing (shopt -s extglob), you can use .!(.|) i.e. dot not followed by dot or nothing.


5

If the directory itself shares the same ownership as its files (hidden or not), then you can chown it recursively instead. The -R option will include hidden files when recursing inside the current directory. $ chown user:group . -R # Will include all hidden files


4

The -C option makes tar change to an existing directory before starting to extract: tar xv -C /mnt/archive -f /home/user/Downloads/archive-latest.tar.gz If you are already located in the directory /home/user or /home/user/Downloads you can shorten the path after -f accordingly. If there is a chance the target path doesn't exist you can created it with ...


4

Consider using find (-maxdepth is a non-POSIX extension, but it should be readily available on Linux): find . -maxdepth 1 -type d -name '.*' -exec chown -R user:group {} +


3

This is about as inelegant as the other answers, but maybe less inefficient: locate --regex --basename "xfce4-keyboard-overlay$" | while IFS= read -r f; do [ -f "$f" ] && echo "$f"; done (broken into two lines for readability).  The above will handle names containing spaces.  The IFS= seems to be necessary to handle names with trailing ...


3

I would use find <PARENT_DIR> -type f -mtime 1 With 1 the time of last modification in days (you can prefix it with - or + to indicate "less than X days" or "more than X days") : so, if you want the the file modified in the last 3 days, you'll do -mtime -3


2

Use one slash THEDIR="${1%/*}" Slower but easier to remember is dirname.


2

Each process has its own "current working directory", which can't be changed from outside the process. So when you do grep some-string -r . & your shell starts grep in the background, and grep's current working directory is initialised to the same value as the shell's at that moment. grep's definition of . here is its own current directory, not ...


2

With GNU find (the implementation on non-embedded Linux and Cygwin): find /search/location -type l -xtype d With find implementations that lack the -xtype primary, you can use two invocations of find, one to filter symbolic links and one to filter the ones that point to directories: find /search/location -type l -exec sh -c 'find "$@" -L -type d -print' ...


2

The modification time of a directory, like any other file (note how directories are called directories (a list of name/number mappings like a phone directory) and not folders) is updated whenever the content is modified. That is when a file is added (linked), removed (unlinked), or renamed in it. Beware that files can be linked to several directories. The ...


1

I'd think you could use ls -A instead, specifically: chown -R username:groupname $(ls -A | grep '^\.') This does what you'd expect .* to do, match all files in the current directory that begin with a ., excluding . and ... But note this won't behave identically to a bash glob if you need it to match funky file names, like files with spaces in them.


1

A variation of Chris Down solution that filter just hidden directories and removes the -R options. Your original requirement was to change ownership and group classification of hidden directories, not their content. find /home/username -maxdepth 1 -type d -name '.*' -exec chown user:group {} +


1

As the other answers have stated: Yes, the file can be edited/modified.  And, at the risk of splitting hairs, allow me to point out that the question says … he has [write permission] on a file under [the directory]. and to make the semi-obvious comment that, to edit a file in the traditional meaning of the word, the user must also have read permission ...


1

Yes, the file can be edited. As far as the directory is concerned, the file can not be edited if you remove the execute permission on the directory for the target (owner/group/others). EDIT: If you want the owner to not be able to edit the file by changing the permission of the directory (assuming the same user owns the directory and file), then you can ...


1

Try: find /search/location -type l -exec test -e {} \; -print From man test: -e FILE FILE exists You might also benefit from this U&L answer to How can I find broken symlinks; be sure to read the comments too. Edit: test -d to check if "FILE exists and is a directory" find /search/location -type l -exec test -d {} \; -print


1

How B can access this directory? Well, the directory belongs to A, and A did not grant any permissions on this directory to B. Therefore B cannot access the directory. It's that simple. If A (or root) wants to grant permissions to B then they should do so with chmod (or chown if root does it).


1

dir=$(pwd) This is more portable and preferred over the backticks method. Using $() allow you to nest the commands eg : mech_pwd=$(pwd; echo in $(hostname))


1

You need to use command substitution to save output of pwd command to a variable. Command substitution can use backticks or dollar characters. Like this: $ mkdir "/tmp/new dir" $ cd "/tmp/new dir" $ CWD="$(pwd)" $ echo $CWD /tmp/new dir $ cd ~ $ echo $CWD /tmp/new dir $ pwd /home/ja


1

You can either use the environment variable $PWD, or write something like: dir=`pwd`


1

Not everything about the file, most of the metadata about the file is stored within the file inode, not the directory entry. The directory entry is just a struct of inode and filename - just enough information to translate from a filename to an inode and get to the actual file. You can safely imagine a directory as a dictionary: filename1 :> inode1 ...


1

There's no system-wide rule; but, the behavior you see in rsync is documented near the beginning of the rsync man page: rsync -avz foo:src/bar /data/tmp This would recursively transfer all files from the directory src/bar on the machine foo into the /data/tmp/bar directory on the local machine. The files are transferred in "archive" mode, ...


1

Processes attempting to access a filesystem block indefinitely if the filesystem driver never responds. For a filesystem that is stored on a storage device, the main cause for not responding is that the underlying hardware is not responding or is faulty. This usually produces copious messages in the kernel logs (visible with dmesg on Linux or in the ...



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