Skip to content

Instantly share code, notes, and snippets.

@lalamax3d
Last active February 16, 2021 18:39
Show Gist options
  • Save lalamax3d/6796b0bb69c1422646c31a370ad2b132 to your computer and use it in GitHub Desktop.
Save lalamax3d/6796b0bb69c1422646c31a370ad2b132 to your computer and use it in GitHub Desktop.
ubuntu cli tips

List of useful cli tools in ubuntu

  • altinstall
  • jobs
  • rclone
  • cron
  • tmux (session continuity in remote sessions)
  • mitmproxy
  • cockpit (docker)
  • puppet | chef | ansible | rudder ( remote server compliance )
  • top | htop | ntop

ALTINSTALL (Multiple Pythons Example)

setting python versions via Altinstall

  • sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
  • sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2

To CHANGE IN FUTURE

  • sudo update-alternatives --config python3

CONCLUSION

  • not good approach, ubuntu 20, starts getting confused.(still)

JOBS

  • ctrl+z | will send current process in background
  • 'jobs' | will list background jobs with numbers or PIDS
  • 'fg #' | will bring that task/job back again

rclone (use gui)

Setup Config via rclone config

CRON

CREATING SERVICE / DAEMON

  • sudo nano /etc/systemd/system/time-laspe.service

    Enable Above service

    • sudo systemctl enable time-lapse.service
[Unit]

Description=time lapse

After=multi-user.target

[Service]

Type=simple

ExecStart=/home/pi/time-lapse.sh

User=pi

WorkingDirectory=/home/pi

Restart=on-failure

[Install]

WantedBy=multi-user.target

FINDING A SERVICE / PROCESS

  • top -p $(pgrep -d',' httpd)

COPY SERVER LOG TO LOCAL MACHINE (if needed)

pscp -sftp -P 7822 -pw password user@ip:/home/logs/topLog.txt C:\Users\me\Desktop\topLog.txt

TOP

  • top >> h ?
  • top -b -n1 > logs/topLog.txt (run in batch move | outputs data - in log file)
  • top -o %CPU -d 10 -i (sort cpu usage wise | refresh after 10 - seconds | hide idle processes)
  • top -u root (show root user processes)

SHORTCUT KEYS

  • q > quit
  • ctl+z > hide
  • fg > show again
  • a > toggle standard / alterV
  • j > align numbers to right
  • r > reverse sort (high to low)
  • i > hide idle tasks
  • m > messages
  • shift + m >
  • Z > color
  • s > summary
  • t > tasks
  • 1-9 colors
  • b > bold text
  • pgup | pgdn scroll

FLAGS

  • -h show current version
  • -d specify delay time refresh
  • -o sort by name field
  • -p show process by id
  • -u show process by user
  • -i do not show idle task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment