Hot answers tagged

9

One of my favourite utilties is namei, part of util-linux and hence generally present only on Linux: $ namei /usr/share/foo/bar f: /usr/share/foo/bar d / d usr d share foo - No such file or directory But its output is not very parseable. So, if you just wish to point out something is missing, namei might be useful. It's useful for troubleshooting ...


7

if the user is allowed to use at command, this is the perfect use for that: $ at 08:00 022116 at> myscript.sh at> <----------- ctrl-d here job 9 at 2016-02-21 08:00 if you get a message like "user blah is not able to run at", ask the syadmin to add this user to at.allow file or remove from at.deny file, depending on how it is used in your ...


6

The commands that read stdin are almost all of the filter family, i.e. programs that transform a flow of text data to a transformed one. cat , sed, awk, gzip and even sh are good examples of such "filters". The cited commands, cp, mv and rm are definitely not filters but commands that do things with the arguments passed, here files or directories. The cd ...


4

Go's idea of channels can be used here: mkfifo my_pipe exec 3<>my_pipe trap 'rm my_pipe' EXIT printf a >&3 function _abc { ... _check & } function _check { until read -N1 -u3; do :; done ... printf a >&3 } Essentially: Create a named pipe for communicating between instances of _abc and _check. Have _check ...


4

You have put a space between & >, which needs to be &>. This would redirect both STDOUT and STDERR to the file followed next. So you need: nohup sh cp.sh < /dev/null &> /dev/null & If you shell does not support &>, use POSIX way to redirect both STDOUT and STDERR: nohup sh cp.sh </dev/null >/dev/null 2>&1 ...


4

If you assign a value that does not influence the environment of the running shell (I do not know whether that is possible at all). The shell uses internal memory for all its variables (at least for the written ones). You can easily see that: env - TESTVAR=foo bash echo $TESTVAR foo TESTVAR=bar echo $TESTVAR bar echo $$ 13833 cat /proc/13833/environ ...


3

All shell variables live in the same storage. At startup, all environment variables are imported. When a new command is launched, a new environment if created for this new command. All variables that are marked for export or that have been imported from the original environment are put into this new environment specfic to the new command.


3

One way is to use a function instead of the alias - put this in your .bashrc or .bash_profile - sreq() { ffmpeg -f x11grab -r 24 -s 1024x768 -i :0.0 -qp 0 -c:v libx264 -preset veryslow $1.mkv }


3

There's a missing semicolon: if [ "$PS1" ]; then PS1="[\e[0;36m]\W\n[\e[m][\e[1;31m]\$[\e[m]" fi should be if [ "$PS1" ]; then PS1="[\e[0;36m]\W\n[\e[m][\e[1;31m]\$[\e[m]"; fi or, format it the same way as your other if statements above this one.


2

Well, you can do: ls | socat - foo or: ls | socat -u - foo if you don't expect anything coming back from foo. Or with socat spawning ls: socat exec:ls foo If you mean you want to run a command while you run socat - foo in a terminal and have the output sent to foo, then within GNU screen, you can use: Ctrl+A:exec .!. ls which would run ls and ...


2

The format seems to be correct (after correction applied posted in the comment above). Are there some special restrictions for having everything in a single line? In case you need to have everything in a single line, I would suggest to change the shell script to avoid Fridays 2-9am, eg #!/bin/bash # THIS CODE IS NOT TESTED # skip on fridays 2-9am # what ...


2

Most login shells by count on a newly installed system are non-interactive, actually: $ awk -F: '{print $7}' < /etc/passwd | sort | uniq -c 5 /bin/bash 23 /bin/false 1 /bin/sh 1 /bin/sync 17 /usr/sbin/nologin


2

su gives you root permissions but it does not change the PATH variable and current working directory. so you can't execute files in /usr/sbin folder. su- changes the PATH too... and root's home becomes your current working directory. you become proper root and can execute all commands.


2

#!/bin/bash NOW=$(date +"%s") SOON=$(date +"%s" -d "3:00 PM Sun") INTERVAL=$(($SOON-$NOW)) sleep $INTERVAL GNU date allows you to specify the format of the output, as well as the date to display. So I use the format string "%s" to get the time in seconds since the epoch, and the same for the arbitrary time using the -d paramater. Get the difference, and ...


2

Command-line arguments are not at all the same thing as stdin; even commands that use both generally use them for different things. Take cat for example: echo foo bar | cat # outputs "foo bar" cat foo bar # looks for files named "foo" and "bar", and concatenates them (if found) If you look at most other commands that read from stdin, you'll ...


2

This is not an answer, but maybe it's an acceptable work-around: alias p='perl; echo hit control-d again; cat > /dev/null' Then, if your perl script exits prematurely, you'll harmlessly paste the remainder to /dev/null; if the perl script succeeds, you'll see your friendly reminder and hit control-d to exit the cat catcher.


2

Since you need floating point calculation, you will end up using bc, or awk, anyways. Why not use Awk to solve the whole problem? Here is a Awk only solution, I used n for numerator and d for denominator: $ printf "4\n1\n2\n9\n8\n" | awk '{if (NR == 1) {d = $0}; if (NR != 1) {n += $0}} END{printf "%.03f\n", n/(d*1.0)}' 5.000


2

If you want to chown the directories only (and not the subfiles), use find -exec, as like: find -type d -name objects -exec chown myUser {} \; Going through this: -type d selects only directories -name objects looks only for directories named exactly "objects" -exec chown myUser {} \; executes chown myUser {} for each path found (with {} replaced by the ...


2

If unalias removes the issue (even temporarily) we have confirmation it is an alias. It could be "brute forced" out by adding an unalias ls in ~/.bashrc. echo "unalias ls" >> ~/.bashrc That will get excuted every time bashrc is read and will remove the alias. That will buy you some peace but will not resolve the actual issue that some file is still ...


2

If you don't need to see the output in real time, you can do something like: git push 2>&1 > ~/git-push-$(date +"%Y%m%d-%H%M").log & The above will create a file in your home directory with the date and time you invoked it in its filename (e. g. git-push-20160208-1201.log). You can put this into an alias or shell function so that you don't ...


1

You almost answered your own question.. the answer is to use the recursive option -R run the command sudo chown -R richie codeRepo/ (assuming your username is richie) This will recursively set each file/folder to you as the owner, but does so; as far down the tree as it can get so is more of a sledgehammer approach.


1

Make grep do the work of strings. If you have GNU grep, pass the -z option to make it read null-delimited records instead of newline-delimited records. This will also match at the end of the file, but that should be ok in practice. find . -maxdepth 1 -type f -size +1M -print0 | xargs -0 grep -Eoz '[[:print:]]{3,}$' If you don't have GNU utilities, pass ...


1

Instead of pasting into the terminal, have the command read from the clipboard. You can use xclip or xsel to print the clipboard content (or conversely write their input to the clipboard). xsel | perl # automatic selection (click+drag, middle click) xsel -b | perl # manual selection (Ctrl+C, Ctrl+V) This only works if the shell in the ...


1

In addition to the "solution/work-around" by Jeff Schaller , the proper solution seems to be to make the environment aware of copy-paste, both from sender side and from receiver side, which is known as "bracketed paste mode". From https://cirw.in/blog/bracketed-paste , here is a short snippet to explain a little more : In summary: Enable ...


1

Why don't you just upgrade the alias to a function, e.g function sreq() { ffmpeg -f x11grab -r 24 -s 1024x768 -i :0.0 -qp 0 -c:v libx264 -preset veryslow "$1".mkv } When you type sreq /path/to/filename it would become ffmpeg ..(redacted)... /path/to/filename.mkv


1

You could just check whether there is a terminal connected to standard input (that's what the tty command does). Add these lines to your script: if ! tty >/dev/null; then echo "Must be run from a tty" exit 1 fi Your script will now exit with an error unless run correctly: $ ssh badabing ~/scripts/a.sh Must be run from a tty $ ssh badabing ...


1

Something like this (accounting for pathnames with embedded blanks): #!/bin/sh explain() { if [ -d "$1" ] then printf "\t%s: is a directory\n" "$1" elif [ -e "$1" ] then printf "\t%s: is not a directory\n" "$1" else printf "\t%s: does not exist\n" "$1" fi } for item in "$@" do last= test="$item" ...


1

HELP 1 Due to the whitespace you need quoting: INPUT= "${file##*/}" OUTPUT= "${file%.txt}"_exd.txt It seems a bit strange, though, that there is a space between INPUT= and the file name. HELP 3 If you have a file input_1.txt then ${file%.txt}_1.txt becomes input_1_1.txt. I would match the exact file name: for file in ~/Desktop/parent\ ...



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