Linux / Unix Command Examples

Here are links to some useful Linux tips:

https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-cat-command-examples/

https://peteris.rocks/blog/htop/

https://www.cyberciti.biz/faq/searching-multiple-words-string-using-grep/

https://www.cyberciti.biz/faq/using-sed-to-delete-empty-lines/

https://www.cyberciti.biz/faq/linux-hide-processes-from-other-users/

https://www.cyberciti.biz/faq/bash-check-if-process-is-running-or-notonlinuxunix/

https://www.cyberciti.biz/faq/unix-linux-bsd-appleosx-bash-assign-variable-command-output/

http://unixmillenniumbug.com/

https://bash.cyberciti.biz/file-management/linux-shell-script-to-reduce-pdf-file-size/

https://www.cyberciti.biz/faq/bash-file-command-not-found-how-to-install-file/

https://www.cyberciti.biz/faq/set-up-a-basic-iptables-firewall-on-amazon-linux-ami/

https://www.cyberciti.biz/faq/fedora-redhat-centos-5-6-disable-firewall/

https://bash.cyberciti.biz/virtualization/shell-script-to-setup-an-lxd-linux-containers-vm-lab-for-testing-purpose/

https://hackertarget.com/ossec-introduction-and-installation-guide/

Awesome. VIM “for people who don’t want to use it , but have to…”. Or see my page https://www.cyberciti.biz/faq/linux-unix-vim-save-and-quit-command/

sudo is the right choice for granting admin rights on the CentOS Linux 8 server. Learn how to create a new user and grant her admin rights https://www.cyberciti.biz/faq/add-create-a-sudo-user-on-centos-linux-8/

643 Comments

  1. Tomi Engdahl says:

    Awesome feature added by OpenBSD. crontab now supports random numbers https://marc.info/?l=openbsd-cvs&m=158691599313802&w=2

    We need this feature ported to other Linux/Unix version of crontab.

    Reply
  2. Tomi Engdahl says:

    Bash shell script pro tip add the following after shebang to catch and avoid unwanted errors/side effects:

    set -euo pipefail

    -e : stop script after 1st cmd failed
    -u : exit when 1st unset variable found
    -o pipefail : exit after 1st piped commands failed

    See https://bash.cyberciti.biz/guide/Set_command

    Reply
  3. Tomi Engdahl says:

    I prefer the more verbose variant
    set – o errexit
    set – o nounset
    set – o pipefail

    Reply
  4. Tomi Engdahl says:

    Fun from nixcraft
    https://m.facebook.com/story.php?story_fbid=3397583100255044&id=12600011741337

    $ sudo systemctl restart 2020
    Failed to restart 2020.service

    $ sudo systemctl stop 2020
    Failed to stop 2020.service

    $ sudo killall -9 2020
    2020: process cannot be killed by root (0)

    $ sudo systemctl status 2020
    2020: It is not a bug, it is a feature.

    $ sudo systemctl reboot
    2020: A lockdown job is waiting in background … reboot of economy and society will have to wait till kernel module named vaccine loaded in the background.

    Reply
  5. Tomi Engdahl says:

    Quick tutorial for new users: How to change hostname on Ubuntu Linux 20.04 LTS
    https://www.cyberciti.biz/faq/how-to-change-hostname-on-ubuntu-20-04/

    Reply
  6. Tomi Engdahl says:

    How to save terminal output to a file under Linux/Unix
    https://www.cyberciti.biz/faq/how-to-save-terminal-output-to-a-file-under-linux-unix/

    How do I save the terminal output to a file when using BASH/KSH/CSH/TCSH under Linux, macOS, *BSD or Unix-like operating systems?

    Reply
  7. Tomi Engdahl says:

    This quick tutorial explains how to find/list all failed systemd services/units on Linux operating systems using the systemctl command.

    https://www.cyberciti.biz/faq/systemd-systemctl-list-all-failed-units-services-on-linux/

    #opensource #linux #sysadmin #IT

    Reply
  8. Tomi Engdahl says:

    How do I find out running processes were associated with each open port on Linux?
    https://www.cyberciti.biz/faq/what-process-has-open-linux-port/

    Reply
  9. Tomi Engdahl says:

    lsof -i
    OR
    netstat -antp

    netstat is deprecated. ss is its new reincarnation

    ss can filter without adding grep in the mix:
    # ss -tul ‘( sport = :3306 )’
    Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
    tcp LISTEN 0 128 *:3306 *:*

    Reply
  10. Tomi Engdahl says:

    {new user shell tip} Learn how to remove the last character from the line or shell variable using sed command on Linux/Unix.

    https://www.cyberciti.biz/faq/sed-remove-last-character-from-each-line/

    #sysadmin #programming #opensource #scripting

    Reply
  11. Tomi Engdahl says:

    As you know, WireGuard recently becomes a stable release & now part of the official Linux kernel. It is an alternative to OpenVPN with the clean codebase. Learn how to set up WireGuard VPN on Debian 10 server with a firewall from backports.

    https://www.cyberciti.biz/faq/debian-10-set-up-wireguard-vpn-server/

    #opensource

    Reply
  12. Tomi Engdahl says:

    TMUX FOR MERE MORTALS
    https://zserge.com/posts/tmux/

    Tmux has liberated me from tiling window mangers. Not that I didn’t like those, but I occasionally have to work with macOS or default GNOME setups. And over the years I realised that I only need a terminal multiplexor to do terminal tiling for me, the rest of the windows are just fine to be full-screen in separate workspaces.

    So, I ended up doing 80% of my work in terminals with tmux.

    Reply
  13. Tomi Engdahl says:

    The purpose of this guide is to introduce a user to the Nmap command line tool to scan a host or network to find out the possible vulnerable points in the hosts. You will also learn how to use Nmap for offensive and defensive purposes https://www.cyberciti.biz/security/nmap-command-examples-tutorials/ #security #infosec

    Reply
  14. Tomi Engdahl says:

    In this tutorial, we explains how to add and create a Linux Network Bridge on CentoS 8 Linux server for virtualization or Linux containers.

    https://www.cyberciti.biz/faq/centos-8-add-network-bridge-br0-with-nmcli-command/

    #opensource #linux #KVM #Docker #LXD

    Reply
  15. Tomi Engdahl says:

    Quickly create dirs pattern. Less typing and more work ;)

    mkdir -vp /etc/tinc/mdb{1..3}_vpn0
    mkdir -vp /etc/tinc/mdb{1..3}_vpn0/host{1..3}

    Works with many other commands.

    Reply
  16. Tomi Engdahl says:

    bat command is a cat(1) command clone with syntax highlighting and Git integration written in Rust lang. Let us see how to install bat on Linux, macOS, FreeBSD and Unix-like system for fun and profit.

    https://www.cyberciti.biz/open-source/bat-linux-command-a-cat-clone-with-written-in-rust/

    #OpenSource

    Reply
  17. Tomi Engdahl says:

    https://www.cyberciti.biz/faq/how-to-check-how-long-a-process-has-been-running/

    How do I check how long a process or pid has been running on my Ubuntu/Debian or CentOS Linux server?

    You need to use the ps command to see information about a selection of the active processes. The pid command provide following two formatting options for a PID (process identification number).

    How to check how long a process has been running?
    You need to pass the -o etimes or -o etime to the ps command. The syntax is:
    ps -p {PID-HERE} -o etime
    ps -p {PID-HERE} -o etimes

    Reply
  18. Tomi Engdahl says:

    Explains various Linux command line tricks to find ulimit values of currently running processes such as Nginx, PHP, MySQL, and users. https://www.cyberciti.biz/faq/how-to-find-ulimit-for-user-on-linux/ #opensource #sysadmin #IT

    Reply
  19. Tomi Engdahl says:

    Sending a hex string to a remote via netcathttps://stackoverflow.com/questions/43919867/sending-a-hex-string-to-a-remote-via-netcat

     how to transmit binary/hex data to the remote device. 
      
    You can do it with command: echo -n -e “\x02\x45\x31\x38\x03\x34\x43\x0d\x0a” | nc [-u]

    The -n supresses outputting the trailing newline.
    The -e enables the interpretation of backslash escapes -> allowing usto send hex codes.’x’ before each character specifies that the byte is in hexadecimal form.
    -u switch to UDP traffic (optional)

    Reply
  20. Tomi Engdahl says:

    sudo apt install food medicine
    sudo apt reinstall oldjob salarybump
    sudo apt –purge remove covid19 recession

    E: Could not find package oldjob

    Reply
  21. Tomi Engdahl says:

    Exit command: . Let us see how to use the exit command and the exit statuses in our scripts or at the CLI.

    https://bash.cyberciti.biz/guide/Exit_command

    Reply
  22. Tomi Engdahl says:

    Learn how to configure road warrior WireGuard VPN with NAT (Network Address Translation), which allow @WireGuardVPN [WireGuard] clients to access the Internet from home or public WiFi securely.

    https://www.cyberciti.biz/faq/how-to-set-up-wireguard-firewall-rules-in-linux/

    #sysadmin #networking #security #ubuntu #debian #centos

    Reply
  23. Tomi Engdahl says:

    Sure way to ruin your Linux box by calling Daemons from the past:

    source .bash_history

    Reply
  24. Tomi Engdahl says:

    https://www.facebook.com/126000117413375/posts/3566246583388694/

    ssh and scp command have different option to specifies the port to connect to on the remote host and it drives me crazy so much on my Linux desktop.

    scp -P {PORT} file user@server: # CAPITAL P

    ssh -p {PORT} user@server # small p

    Reply

Leave a Comment

Your email address will not be published. Required fields are marked *

*

*