Linux source

https://github/com/torvalds/linux

8 Superhero commands you should be using

1. redo last command as root

sudo !!

2. Open Editor ro run a command (if its a big command)

ctrl+x+e

3. Create a super fast ramd disk (virtual disk drive 5..100 times faster than real HD)

mkdir -p /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=8192M

test it

mkdir ram && cd ram/ && dd if=/dev/zero of=test.iso bs=1M count 8000
rm test.iso
mount -t tmpfs tmpfs /mnt.ram -o size 8192M
cd ram/
dd if=/dev/zero of=test.iso bs=1M count 8000

4. Leading space, command does not go into history

 ls -l

5. making a mistake in a command, don’t hit up and edit it use

fc

6. tunnel with ssh (local port 3337 reote hosts’s 127.0.0.1 on port 6379, great way to connect to a port without having to expose publicly

ssh -L 3337:127.0.0.1:6379 root@emkc.or -N

7. quickly create folders

mkdir -p folder/{sub1,sub2}/{sub1,sub2,sub3}
mkdir -p folder/{1..100}/{1..100}

8. what is happening between pipes

cat chase.txt | cat >/dev/null cat chase.txt | tee -a log.txt | cat >/dev/null

BONUS Exit a terminal and leave all processes (default on exit all child processes get a hang up signal)

Greate for long running jobs in the cloud, or poor connections

disown -a && exit

Linux File System

  • common executables for everyone /bin
  • kernel and boot configuration (inc grub) /boot
  • files which point to both physical and pseudo devices (everything is a file) /dev
  • system and program config /etc
  • non root user home directories /home
  • library files used by the system, include .so file and others /lib /lib32 /lib64
  • saved files due to failure /lost+found
  • auto mount point for media devices for some distributions /media
  • place to mount variosu file systems /mnt
  • software /opt
  • virtual filesystem for resources, processes and more /proc
  • home for root /root
  • like /bin but for sys admins /sbin
  • temp /tmp
  • user program, library files, docs, rtc (user operations) /usr
  • variable files.. log files /var
  • compressed version of the distro /vmlinux

Processes init fork kill fg bg

Process = A piece of running code on your computer, all processes have an id and a parent except the init process which has id 1.

ps -f 1

probably started by systemd Kernal calls thsi and only this.

hows does

ls -l

work? using a technique called fork and exec.

  1. fork the current process (e.g the bash shell)
  2. replace the copy with ls -la
  3. exec
  4. exit

in this example the bash shell is the parent.

example

exec ls -l

replaces the current process with ls -la (terminal will close)