Code Snippets

I use them to manage our lab’s server all the time, so I put them here for easy reference.

Unix Server Commands

  • Use setfacl to control file access groups

    • Grant siconghuang read, write, and execute access to the /data/datasets/ directory

      setfacl -R -m u:siconghuang:rwx /data/datasets/

  • Use tmux to create a persistent window for long experiments or persistent processes

    • Create a new persistent window named sicong

      tmux new -s sicong

    • Detach from a persistent window

      Press Ctrl + B, then press D

    • list all existing persistent windows

      tmux ls

    • attach to the persistent window named sicong

      tmux a -t sicong

    • If you (sadly) don’t have tmux, try screen
  • To check server space

    • Use df to check the entire storage space

      df -h

    • Use du to check the /data/datasets/ diectory

      du -sh /data/datasets/

  • To find a file or directory from a scoped directory

    • Use find to locate directories with keyword MNIST from /data/datasets/ directory

      find /data/datasets/ -type d -name "MNIST"

  • To reload swap memory memory

    • Use swapoff/swapon to switch on and off

      free -m; swapoff -a; swapon -a; free -m

  • To limit your job’s resource usage

    • Use nice and taskset to set your job’s priority and CPU resource usage
    • Making your job run with the lowest priority and only use the first 8 cores

      nice -n 19 taskset -c 0-7 [run your job here(i.e. python train.py)]

  • To send files/data to another server

    • Use scp to send files from your current machine/server to another
    • Securely sending your saved_models directory to your home directory on another server

      scp -r ~/saved_models/ [username]@[server address]:~