Handy Commands
Rerun the last command as sudo
sudo !!
#Open an editor to run long/complex commands
Opens your text editor letting you type the commands, it then closes the editor and runs it.
ctrl + x + e (x followed by e, not together)
Create a blank data test file of a set size
(XXXX=size desired)
dd if=/dev/zero of=nameoffile.iso bs=1M count=XXXX
Create a temporary ramdisk (destroyed upon unmounting or restart)
mkdir -p /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=XXXXM
(XXXXM=size in MB)
#Fix a messed up long command without needing to fully retype it
type ‘fc‘ to open that command in an editor and rerun it upon closure
#Quickly create folder setups using -p (-p creates the parent folders if they don’t exist)
mkdir -p folder/{subf1,subf2}/{sub1,sub2,sub3}
(creates the folder /folder containing /subf1 /subf2 each containing a /sub1 /sub2 /sub3)
works numerically as well
mkdir -p folder/{1..100}/{1..100}
(creates a folder /folder containing folders /1 to /100, each containing 100 numbered folders)
#Intercept stdout and write it to a text file (output of .bash_history as an example)
cat .bash_history | cat > /dev/null
result = nothing, piped to dev null and gone
cat .bash_history | tee -a file.txt | cat > /dev/null
result = nothing on screen but file.txt was created showing the output of cat .bash_history