Bash cheat sheet masterlist bible

to beggin go to your favourite folder, open konsole and run

echo amazing > file && echo superb >> file && echo magnificent >> file && echo done everything

this will create a new file there named file with three words in each line amazing superb magnificent then run

cat file | tr -d '\n' > 1 && echo done everything

this will turn those three lines into just one. So there will be new file in your current folder caled 1 with everyline joined together into one line

be carefull with this

# asks you to enter your name then puts that into variable name
echo enter your name && read name

# find process named konsole | with command that includes amazing | print only second column into variable pid && then print it
pid=`ps aux | grep konsole | grep "amazing" | awk '{ print $2 }'` && echo $pid

# change konsole window title to incredible
echo -ne "\033]30;incredible\007"

# zip the super folder into super.zip
zip -r super.zip super

# find files named project.godot recursively
find . -name "project.godot"

# run godot editor with the game
path/to/your/godot -editor path/to/game/folder/project.godot

# join text file 1 and new together
cat 1 new > together

# additions subtractions removes $old_number from $new_number
number_of_new_links=$(echo $new_number-$old_number | bc)

# enter home directory
cd $HOME

# enter folder music from your current folder
cd $PWD/Music/

# make folder named notes
mkdir notes

# go up a folder
cd ..

# remove even if files or folders do not exist
rm --force $HOME/Music/random333

# remove everything inside current directory random folder including files and folders
rm --force --recursive "$PWD/random/"/*

# left click on screen at 111 222 position
xdotool mousemove 111 222 click 1

# presses F6 for you
xdotool key F6

# press key combo ctrl+c presses ctrl+c for you
xdotool key ctrl+c

# focus on firefox put it in front
xdotool search "Navigator" windowactivate

# puts whats curently in clipboard into copy txt file
xsel > copy

# display time hour:minutes into variable timenow
timenow=`date "+%H:%M"`

# Put this before the start of commands you want to track how long they take to be done
T="$(date +%s)"

# put this at the very end of commands you wish to track how long they took
T="$(($(date +%s)-T))"
echo "It took ${T} seconds!"

# puts current time into today then makes an empty file named after current time
today() {
date "+%d.%m.%Y %H:%M"
}
touch "$(today)"

# copy files from here that are on a list into home Music folder
xargs -a list cp -t $HOME/Music/

# adds a prefix (abc) to everyline
awk '$0="abc"$0' file > 1

# removes a prefix or 1 characters or 1 bytes from beggining of every line
sed 's/^.//' 1 > 2

# adds suffix whitespace to end of every line
awk 'NF{print $0 " "}' file > 1

# # removes a suffix from every line
sed 's/.$//' file > 1

# changes all uppercase letters to lowercase letters
tr A-Z a-z < file > 1

# renames file from great to impressive
mv great impressive

# print only lines containing abc (its case sensitive so it does not find Abc)
grep "abc" file > 1

# print only first line containing abc (its case sensitive so it does not find Abc)
grep --max-count=1 "abc" file > 1

# reads line number 259
sed n '259p' 1 > 2

# searches and deletes everything before patern amazing and everthing after patern triple
sed 's/^.*\(amazing.*triple\).*$/\1/' 1 > 2

# delete everything after third "
cut -d: -f2- 3 > 4

# delete everything before last /
awk '{print $NF}' FS=/

# remove everything from 1 that is in blacklist
grep -Fvxf blacklist 1 > 2

# removes particular lines
sed -i '/--.github.io/d' 1

# removes empty lines
sed -i '/^$/d' 1

# removes all the lines that start with -
sed -i '/^-/d' 1

# remove duplicates
sort 4 | uniq > new

# keeps only first 3 lines
head -3 file > 1

# turns every space into _ underscore
sed -e "s/ /_/g" file > 1

# put every line into quotes
xargs -I {lin} echo \"{lin}\" < file > 1

# put multiple lines into one
cat file | tr -d '\n' > 1

# adds #!/bin/bash to begining of file
sed -i '1i #!/bin/bash' file

# make script executable
chmod +x script.sh

# run a script
bash script.sh

# run a script
sh script.sh

# get all the text from the website
lynx -dump -nolist https://yugioh.fandom.com/wiki/Armades,_Keeper_of_Boundaries > 1

# gets current website source code
curl https://yugioh.fandom.com/wiki/Armades,_Keeper_of_Boundaries > 1

# get code from github
git clone https://some/github/url

# split text into multiple text files 1 line each
split -l 1 file

# count how many lines text file new has then strip anything besides numbers put it into variable
line_number=`wc -l new | sed 's/[^0-9]*//g'`

# linux count how many lines a file has
wc -l file > numberoflines

# keep only number in numberoflines
sed 's/[^0-9]*//g' numberoflines > numberoflines1

# put content of a text file into a variable or put output of command into a variable
lines=`cat numberoflines1`

# make a file with ascending numbers n+
seq -f "%.0f" 1 10 > numbers

# put two text files together
# file1  +file2 =joined results
# amazing+triple=amazingtriple
# superb +uno   =superbuno
paste '-d\0' file1 file2 > joined

# do this command to every file in a folder
cd "/home/user/1/"
for i in *; do
grep "abc" $i > /home/user/2/$i; 
done

# in your current folder remove most silence of every .ogg files add prefix 0silence0. and move them into home music directory
for i in *.ogg ; do sox "$i" $HOME/Music/0silence0."$i" silence -l 1 0.1 1% -1 3.0 1% ; done

# renames every file in current folder -- removes 0silence0. from their filenames
rename "s/0silence0.//g" *

# inifinte loop never ending sleep for 1 second
while :
do
sleep 1
done

# count how many files folder 1 in current directory has and put in into lib/status
ls $PWD/1 | wc -l > $PWD/lib/status

# continue when there is correct status
while [ $status -gt 0 ]; do
    echo sleeping
    sleep 1
    ls $PWD/1 | wc -l > $PWD/lib/status
    status=`cat $PWD/lib/status`
    sh $PWD/lib/silence
done