New answers tagged

0

I’m not sure what I can say by way of explanation that hasn’t been covered by the other answers.  Instead, I’ll try to help you with examples. Arkadiusz Drabczyk gives the example from the GNU tar manual where your archive includes a large directory tree (e.g., all of /usr): $ tar -cf usr.tar /usr and you want to drill down into the archive and extract a ...


1

The solution is to use parameter substitution, twice. We start by storing the pathname of the directory in a variable (if you're dealing with the current working directory, you can skip this and use PWD in place of p later): $ p=/a/b/c/d/e/c/f/g We may then remove the longest prefix string that matches */c/ from this: $ echo "${p##*/c/}" f/g We then ...


1

I don’t think there is a GUI equivalent to this option. The --strip-components option to tar is effectively a cut on the file paths. Going back to the tarball that started all this, tar tf shows mediawiki-1.33.0/.phan/config.php mediawiki-1.33.0/.phan/internal_stubs/memcached.phan_php mediawiki-1.33.0/.phan/internal_stubs/oci8.phan_php mediawiki-1.33.0/....


2

I understand that the rightmost file of a file tree of at least two directories, will be extracted... No, the first two directory components dir1/dir2 of the tree are omitted from extraction (if you're extracting relative pathnames). This is different. Lets assume we have the following directory structure: dir1 ├── dir2 │   ├── dir3 │   │   ├── dir4 │   │ ...


0

This solution assumes that: CHAPTER is always the first word of the line. It is always followed by one space, then a roman numeral (one or more of the capital letters I, V, X, L, C, D or M and ends with a .. Then, we do it in two steps: Split each chapter into its own file, named CHAPTER_I.txt, CHAPTER_II.txt ... CHAPTER_N.txt (file is your input file): ...


3

The fragment of manpage you included in your question comes from man for GNU tar. GNU is a software project that prefers info manuals over manpages. In fact, tar manpage has been added to the GNU tar source code tree only in 2014 and it still is just a reference, not a full-blown manual with examples. You can invoke a full info manual with info tar, it's ...


1

To supplement the good answer by larsks, to try to help clear up the confusion around the -C option: The tar man page states for the -C option: -C, --directory=DIR Change to DIR before performing any operations. This option is order-sensitive, i.e. it affects all options that follow. so, it is not like mv - it is literally ...


1

The syntax of tar is tar -f output input So you want to run tar -cvjf /path/to/output.tar.bz2 /what/you/want/to/compress


1

The permissions of a new file are set from (1) the permissions set in the open() call modified by (2) the umask of the creating process, so that bits set in the umask are zeroed. That is, a permission bit is set only if allowed by both of those, it's just that the bits in umask are inverted. In your case the users probably have different umasks, namely A ...


0

Don't know why nobody proposed something like that: for i in $(locate MYDIR); do [ -d "$i" ] && echo $i; done This just checks if any of locate strings is a directory and prints it


3

I would use find for this: find . \( -name .git -o -name node_modules -o -name wp-snapshots \) -prune -o -type f -print | wc -l This looks for all files (including directories) starting from the current directory, and processes them as follows: if the name matches .git, node_modules, or wp-snapshots, the tree starting from the matching entry is ignored ...


1

mkdir -p parent/child && touch "$_/file.txt" $_ is a shell parameter, it expands to last argument of previous command. Example mkdir test && cd "$_" will create and cd into the directory test.


1

I recommend using rsync With rsync, you can specify that you would like the files to be deleted and you can even do a "dry run" to see exactly what would happen if you were to run it for real. Try rsync -av --dry-run --delete-before fromA toB The --delete-before is great for merging files on systems that are low on space. If you are happy with the dry ...


2

info mv has this: _Note_: 'mv' will only replace empty directories in the destination. Conflicting populated directories are skipped with a diagnostic. There is no option to overrule that, so it seems. Either remove B and rename A (back to B), or empty/delete the directories in B by hand first.


0

Based on your statement that you get an error that the file already exists you already have folders and files under 'toB'? If you mainly which to merge the files from 'fromA' to 'toB' then you are probably are best to just copy the files recursively (cp -ar) and then remove 'fromA' afterward. Otherwise, if 'toB' should initially be empty and you just want ...


3

The issue was that the directory appeared to have non-visible characters at the end of its name. Using a shell globbing pattern, Gullane*, the user was able to enter the directory, and then also to rename the directory with a more usable name: mv Gullane* Gullane The * part of the globbing pattern would match the blank/non-visible characters at the end of ...


4

If you know the name of the package, e.g. xbindkeys, you can list its contents in various ways: dpkg -L xbindkeys if it’s installed; dpkg-deb -c xbindkeys_1.8.6-1+b1_amd64.deb if you have the package file (without necessarily installing it); apt-file list xbindkeys whether or not it’s installed (if the indexes are up-to-date); on the packages.debian.org ...


0

One-liner: find directory -exec md5sum {} \; 2>&1 | sort -k 2 | md5sum This lists all files and directories and gets md5sum for each. Then gets md5sum for everything. Tricky bit solved here that md5sum is not capable to do the sum for a directory, but it tells this to us: md5sum: dir/sub_dir: Is a directory. We just move this message to a standard ...


3

You can use GNU Parallel: parallel mv {} '{=s/^\.\\_//=}' ::: '.\_ValidateAll'* This will remove .\_ from the names. To also replace spaces with _ run: parallel mv {} '{=s/^\.\\_//; s/\s/_/g=}' ::: '.\_ValidateAll'*


3

In principle (and as you probably know), files and directories are hidden if their name starts with a .. Thus, you can make them "visible" again by removing that .. It can be done in bash using, the builtin string manipulation functions: user@host$ for dir in '.\_ValidateAll'*; do newname="${dir#.}"; mv "$dir" "$newname"; done You would be well-advised, ...


4

If the only issue is that the directories are hidden, you can just remove the . from the beginning of their name to make them unhidden. For example, using perl-rename (called rename on Ubuntu): rename 's/^\.//' '.\_Validate'* Or, with just shell tools: for dir in '.\_Validate'*; do echo mv "$dir" "${dir//.}"; done Bot of these leave you with horrible ...


0

Another would be ls -al <directory> | awk '{t+=$5}END{print t}}' Assuming you're looking in a single directory. If you want to look at the current directory and beneath that ls -Ral <directory> | awk '{t+=$5}END{print t}}'


2

With zsh: print -rC1 -- *(N/oe['REPLY=${REPLY#?}']) print -rC1 prints its arguments raw on 1 Column *(qualifiers): glob with glob qualifiers N: Nullglob: expands to nothing if there's no match /: only select files of type directory oe[expression]: order the list based on the result of the expression (of the value of $REPLY initially containing the file ...


2

With sort, you can use a key of the form F.C to specify a character position within a field. So for example $ printf '%s\n' */ | sort -k1.2 yalberto/ mreynolds/ lrodriguez/ Note that this will fail if any of the directory names contains a newline. That could be worked around with GNU sort by working with NUL-delimited records instead with: printf '%s\0' ...


1

If they can do that, is there really a point in e.g setting 711 permissions on a home folder to protect its content while allowing access to things like SSH keys? (I've read people advise this.) Then either (a) they were misguided, or (b) you have probably comprehended only part of the advice. OpenSSH (at least) requires that SSH keys have restricted ...


0

Good luck doing that. For even shortish filenames (10 characters) that are readable (letters and digits only) you already have $36^{10} = 3.16×10^{15}$ possible names to check...


2

Yes you can brute force such a directory. Unix was originally created in a very co-operative environment, so a set of permissions that said don't browse here would have been respected. If the users of your machine don't have that sort of culture then (assuming you can't change your users) don't create directories with execute permissions if you want to ...


2

A *nix system makes no difference between a file and a directory, whereby a directory is just a file containing names of other files (and numbers of inodes). Therefore, as the content of a directory grows with the amount of files it contains, the size (blocks) used to store this content will grow as well. To my knowledge. it will not shrink when files are ...


Top 50 recent answers are included