New answers tagged

0

It is not limited to a fixed number of dirs, so if you want to create 2, 3 or pass your entire life creating directories and sub-directories, until causing a explosion, here is the script: #!/bin/bash enter_recursive(){ while true; do echo "Please enter the name of the directory you want to create inside $PWD or type _up to exit the directory" ...


0

I might have overseen something, but this should work as well and is IMHO more readable than set or find. -A just exclude . and .. but include other dotfiles. | head -n 5 is to shorten the ls in case of many files. You can omit it if you expect to have no or few files in the folders you are checking. Edit : I updated to 5 so we handled a sneeky file name ...


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


0

(t)csh only support old form of command substitution: $ set dir=$PWD $ set parentdir=`dirname "$dir"` $ printf '%s\n' "$parentdir" /home Scripting with csh is considered harmful, if you can, switch to other modern shells (Even there, you also want to use modern form of command substitution $(...)).


0

I wouldn't use in documentation, nor 'in anger', but if you really want tilde you can do either of VAR=~/.vimrc; wget ... --output-document="$VAR" unset VAR # to keep things tidy # or put in ( subshell ) to keep pre-existing VAR # quotes only needed if $HOME (or anything you substitute for .vimrc) # can contain whitespace or glob characters ?*[ which is ...


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


1

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


0

I just came across the original answer here by @Mehmet while searching for something unrelated and I see that although it works, it is horribly inefficient, requiring each file to be read again for each unique word in all of the files! The second answer by @Jeff is rather convoluted despite the explanation and worst of all it suffers from the cat file | ...


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


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


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


0

This works perfectly for me, tested several variations worked every time. From the directory that holds the images directory. rm -frd ./images/* before: images/ |_ header.png |_ footer.png |_ subdir/ after: images/


0

The question was to empty a directory = remove contents of a directory including hidden files, but not the directory itself. The find command with -mindepth 1 is actually the correct way to go, but to avoid error messages it must be joined with -maxdepth 1: find /path/to/dir -mindepth 1 -maxdepth 1 -exec rm -rf '{}' \;


0

sudo allows regular users to run commands as root. Unless you provide an explicit list of very specific commands it is virtually impossible to prevent a user with sudo access from doing anything they like (and subsequently covering their tracks) with content that doesn't leave the server. Your question is usually triggered by people who don't really grasp ...


0

Actually it is possible to count code directly with the .deb file--assuming the .deb file contains source code--using cloc's --extract-with switch: cloc --extract-with='dpkg-deb -x >FILE< .' ../cloc_1.60-1_all.deb 2 text files. 2 unique files. 1 file ignored. https://github.com/AlDanial/cloc v 1.66 ...


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


0

Try the following command: ls -1 | grep -w "[A-Z]*"


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


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


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


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


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


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


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


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 {} +


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


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


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

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



Top 50 recent answers are included