Hot answers tagged

6

// is a special case, covered in the POSIX definition of the word "Pathname": Multiple successive <slash> characters are considered to be the same as one <slash>, except for the case of exactly two leading <slash> characters. On most systems // is the same as /, but it is allowed to be different according to POSIX. Further reading: ...


6

As others have explained, using inotify is the better solution. I'll just explain why your script fails. First of all, no matter what language you are programming in, whenever you try to debug something, the first rule is "print all the variables": $ ls file1 file2 file3 $ echo $PWD /home/terdon/foo $ for FILE in "${PWD}/*"; do echo "$FILE"; done ...


4

The simplest solution is: for dir in *; do mv "$dir"/v2.3.0/* "$dir"/; done To only move php files use: for dir in *; do mv "$dir"/v2.3.0/*php "$dir"/; done And to avoid error messages if you have files (an not only directories) in the top level: for dir in *; do [ -d "$dir" ] && mv "$dir"/v2.3.0/* "$dir"/; done


4

Tilde expansion only works in the beginning of a word. (At least in bash, see e.g. https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html ) You could use, say --something=$HOME/filename if you only need to refer to the current user's home directory. Since --output-document takes a mandatory argument, writing the argument in a separate ...


4

I'm assuming you want to create a directory which other members of your group cannot list, but where you can make files accessible to them anyway... Accessing a directory requires the "execute" permission, listing its contents requires the "read" permission. If you make a directory executable but not readable, users can access files stored within but can't ...


4

It doesn't duplicate the information: you can have more suffixes in a given directory than the plain ".1" or ".3", e.g., (depending on the platform) letters following the numbers. For example, Debian follows the ".3" with a an application suffix such as "pm" for Perl modules. Here is (part) of the listing from /usr/share/man/man1, to illustrate: ...


3

With zsh: printf '%s\n' d/*.txt(:t) :t like for csh history modifiers but here in a glob qualifier, gets you the tail of the file name. Also: files=(d/*.txt) printf '%s\n' $files:t In other Bourne-like shells, you could always do: (cd d && printf '%s\n' *.txt) Note that it doesn't fork a new shell, it creates a subshell environment. In most ...


3

What you want is pwd -P. From man pwd on CentOS 6: -L, --logical use PWD from environment, even if it contains symlinks -P, --physical avoid all symlinks Or, from the BSD pwd man page and slightly more helpfully worded: -L Display the logical current working directory. -P Display the physical current working ...


2

You can usefully add the -i option to rsync to make it show you why it wants to copy the file again. For example, you might see .f...po.... somefilename which means the remote file has different permissions and owner. One solution is to use --size-only to only compare the sizes of files, but obviously this might cause some changed files not to be sent. ...


2

Given a path to the file ./some/where/thatcertainfile, stripping off the final /thatcertainfile gives you a path to the directory. Launch a shell to be able to use string manipulation on the path. find . -name thatcertainfile -exec sh -c 'rm -r "${0%/*}"' {} \; Alternatively, use zsh. To transform a path into the name of the containing directory, use the ...


2

A solution that works for me is to downgrade the ntfs-3g version from the 2014 release to the 2012 release. This should solve your ntfs partition access problem. In the long run this is not a solution because eventually you will need to run the latest release. More info here


2

I believe that the simplest way to do what you ask is: $ ( cd d; ls *.txt ) 1.txt 2.txt 3.txt that is happening inside a sub-shell ( ... ) so the directory change is not permanent, is valid only for the execution of the two commands. A more robust version is: $ ( cd d && ls -d -- *.txt ) 1.txt 2.txt 3.txt In which ls is not executed unless ...


2

At this point I'd say the main reason is backwards compatibility — the directory split was there right from the start, in V4 (that's the fourth release of UNIX, not SVR4). Back then there could have been any number of reasons: avoiding having to handle many files in a single directory, thinking of the manual pages as parts of a book...


2

Use the -prune option to skip that directory find ~/.jenkins/jobs/subco -path ~/.jenkins/jobs/subco/myapp -prune -o -name '*.jar' -exec rm -r {} +


2

You can use the inotify-tools package to monitor all changes in a folder in real time. For example, it contains the inotifywait tool, which you could use like : > inotifywait /tmp Setting up watches. Watches established. /tmp/ MODIFY test You can use flags to filter certain events only or certain files. The inotifywatch tool collects filesystem ...


2

You need to run cloc on the source package, not on the binary package — cloc_1.60-1.1_all.deb is the binary package. This works: dget -d http://httpredir.debian.org/debian/pool/main/c/cloc/cloc_1.60-1.1.dsc cloc cloc_1.60.orig.tar.gz and shows 12 text files. 7 unique files. 9 files ignored. ...


2

Your use of 'parent folder' is a little confusing, this will find all the folders (actually directories) in a given path, without traversing the entire tree, that are made up only of A-Z. find /given/path -type d -maxdepth 1 -regextype sed -regex ".*/[A-Z]*" For example, to do the current directory, find . -maxdepth 1 -type d -regextype sed -regex ...


1

As far as I know the '=' shouldn't be there... wget --option-document ~/.vimrc


1

If you want to monitor on a two second interval you can surround your check with: while true do <your steps> sleep 2 done While this will sequentially test for files and will wait 2 seconds for each file found I suggest to transform your check into a function: function _check_file() { SUM1=$(md5sum "$@") sleep 2 SUM2=$(md5sum ...


1

Try: ( cd ~/.jenkins/jobs/subco find . -path ./myapp -prune -o -type f -name '*.jar' -print0 | ... ) Adding -type f to restrict the condition, since when you want to match JAR files only. And also, you used -print0, it's likely that your find supports -delete, so you can use: ( cd ~/.jenkins/jobs/subco find . -path ./myapp -prune -o -type f -name ...


1

From man pwd on my Ubuntu: your shell may have its own version of pwd I use bash. Simple pwd command gives me a path with respect to the symbolic link; yet /bin/pwd returns the actual path. The cd command is also a bash builtin. In other words: this is shell specific. EDIT: thrig's comment (see below) seems to be a better alternative to everything I ...



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