Hot answers tagged

3

Don't specify the files or Directory Lets say you created the new folder (or are going to create one) and want to copy the files to it after the folder is created mkdir /test/folder cp -rp /path/to/copy/. /test/folder This will copy all files/folder recursively from /path/from/copy in to the already existing folder created on the first line. Another ...


3

? is a special character in pattern matching, which match any single character. So the command means find all files and directories in /foo/path and its subdirectories, whose names are exactly one character long. The \? is used to prevent your shell from performing filename generation. You can use other quoting mechanisms: find /foo/path -name '?' or: ...


3

Each line you write must have a command, usually the first word. To get something printed, a common command is echo. If the pwd (present working directory) has files a, aa, bb, and ccc. Then, this command will print all files in the directory: $ echo * a aa bb ccc And this command will print all files in the pwd that have one character: $ echo ? a ...


3

.epub files are .zip files containing XHTML and CSS and some other files (including images, various metadata files, and maybe an XML file called toc.ncx containing the table of contents). The following script uses unzip -p to extract toc.ncx to stdout, pipe it through the xml2 command, then sed to extract just the text of each chapter heading. It takes one ...


2

It's a kind of necroposting but I've had the same problem recently (with a different backend) and found that the reason is in a wrong Content-Type. By default it's "text/plain" or "text/html", and in my case curl -H "Content-Type: application/json" -d ... solved the issue.


2

Looking in /media is a reasonable way to find hotplug block devices. You can also use lsblk to list the block devices and whether they are hotpluggable: $ lsblk -l -p -o name,rm,hotplug,mountpoint NAME RM HOTPLUG MOUNTPOINT /dev/sda 0 0 /dev/sda1 0 0 / /dev/sda2 0 0 [SWAP] /dev/sda3 0 0 /home /dev/sdc 0 1 ...


2

Try: cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> cp.err Note that the cp.err file will be created in the directory where you are when you run the command. If you want the error file in a differente directory, you can do: cp /usr/share/backgrounds/*.jpg /week/pictures/final/jpg/ 2> /desired_directory/cp.err


2

It might be easier to simplify the command so that you have fewer special characters on which the shell might choke: ssh jboss@myTargetServer 'ps -p $(cat /var/run/jboss-as/jboss-as-standalone8.pid) -o %cpu= 2>/dev/null' The trailing 2>/dev/null throws away the error text in the event that the PID file either cannot be found or contains a stale PID. ...


2

I would recommend putting those commands into a script that you remotely call with ssh. Otherwise you'd need to put the whole "remote" part of the command line into quotes and properly escape everything inside. This can be tedious and error prone. That's why remote script call.


2

The ? is part of a mechanism called "pathname expansion" in the shell. Colloquially, the mechanism is called "globing". The basic glob makes use just of three characters: * ? and [ that build "patterns". An asterisk * means: Any character in any quantity (any string). A question mark (?) means: Any character one time. The square braces define a ...


2

Use chown's recursive option: chown -R owner:group * .* Specifying both * and .* will match all the files and directories that find would. The recommended separator nowadays is : instead of .. If you want to change the current directory's ownership too, this can be simplified to chown -R owner:group .


1

mkdir backupcache cp -rp .cache/. backupcache that way only the conetent (/.) of .cache gets copied, not the .cache part.


1

I would put environment variables in .bash_login or .bash_profile, since they are (when exported) inherited to subshells and don't need to be reset for every shell invocation. Not that resetting them would cost practically anything, but in case I want to set an envvar to something else for the duration of a subshell. That's hard to do if the .bashrc ...


1

Since the question is essentially asking for opinions, you will get different answers. A good design practice, for example, uses as few places as possible to provide a given feature. Some put information like this in the system area to reduce the amount of work done by users to customize their shell environment. In my environment, I use the terminal ...


1

I put PS1 code in bashrc all the time. My code is as follows: export PS1="\[\e[01;37m\][\[\e[0m\]\[\e[01;32m\]\u\[\e[0m\]\[\e[00;37m\]@\[\e[0m\]\[\e[01;34m\]\h\[\e[0m\]\[\e[00;37m\] \[\e[0m\]\[\e[00;37m\]\t\[\e[0m\]\[\e[01;37m\] \W \e[1;37m(\e[1;32m|\e[1;33m|\e[1;31m|\e[1;37m]\\$ \[\e[0m\]" I use a different PS1 for root (/root/.bashrc) - red username, ...


1

The second command as you have it runs the code part ($()) in local subshell. You need to make it run on the other side by escaping special characters (basically $): ssh jboss@myTargetServer tmpValue=\$(cat /var/run/jboss-as/jboss-as-standalone8.pid) \ && top -b -U jboss -n 1 |grep \$tmpValue |awk '{print $9}' or put it all into the apostrophes ' ...


1

Try to use find command : find /usr/share/backgrounds -iname "*.jpg" -type f -exec /bin/cp {} /week/pictures/final/jpg 2>cp.err \;


1

One way with find and install: find /var/public/voicelogging/quality_monitoring -name \*.WAV -exec sh -c ' bn=${0##*/}; x=${bn%%-*}; dt=${x##*_}; y=${bn%_*}; id=${y##*_} install -D "$0" "/home/username/logging/${id}/${dt}/${bn}"' {} \; this uses parameter expansion to extract the date: ${dt} and the user id: ${id} from the filename and then uses install ...


1

The df is reporting a small number because you're mostly deleting directories, which are relatively small. Also, depending on the filesystem, changes to directories and changes to the number of links to a file are journaled and/or synced to the disk immediately, since they're critical for fault recovery, and thus slower. That's actually a testament to the ...


1

All of the above examples will tell you the size of the data on disk (i.e. the amount of disk space a particular file is using, which is usually larger than the actual file size). There are some situations where these will not give you an accurate report, if the data is not actually stored on this particular disk and only inode references exist. In your ...


1

If you see a mismatch between what df and dh report, you may have open files which are deleted but are still being written to. This takes up disk space (according to df), but is not reported anywhere (such as du) because the space doesn't belong to any existing file. If you experience this, you may need to restart some services (or the machine for a brute ...



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