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:

    Want to find out available auth methods for remote sshd on Linux/Unix? Try

    s=box1
    u=vivek
    timeout 8 ssh -v ${u}@${s} true 2>&1 \
    | egrep “Authenticating to|Authentications that can continue”

    Make sure you disable ssh pass login to increase security. See https://www.cyberciti.biz/faq/linux-run-a-command-with-a-time-limit/

    Reply
  2. Tomi Engdahl says:

    Learn how to set/change server’s Fully Qualified Domain Name (FQDN) on Ubuntu 20.04 LTS “Focal Fossa” Linux https://www.cyberciti.biz/faq/how-to-set-change-fqdn-on-ubuntu-20-04-linux/

    Reply
  3. Tomi Engdahl says:

    Did you know you can kill an unresponsive ssh session from your Linux or macOS or Unix/*BSD desktop using the following tricks? No need to close terminal:

    First hit [Enter] key to start a new escape sequence

    Then press ~ (tilde)

    And finally, type . (dot)

    Reply
  4. Tomi Engdahl says:

    I/O redirection for both bash and POSIX shell to write data to the file under Linux or Unix-like systems. See https://www.cyberciti.biz/faq/how-to-write-the-output-into-the-file-in-linux/

    Reply
  5. Tomi Engdahl says:

    Learn how to make LUKS (Linux Unified Key Setup, disk encryption) header backup and restore it in case of urgency or misconfiguration.

    https://www.cyberciti.biz/security/how-to-backup-and-restore-luks-header-on-linux/

    #Linux #OpenSource

    Reply
  6. Tomi Engdahl says:

    Are you missing less command on your CentOS/RHEL/Fedora Linux cloud server? Here is how to install it manually using CLI or bundle with your Docker/Podman based Linux container using Dockerfile https://www.cyberciti.biz/faq/how-to-install-less-on-centos-rhel-fedora/

    Reply
  7. Tomi Engdahl says:

    Forgot privilege escalation on Linux or Unix while running a command that needs root-level access? Do not type the whole command again. Simply type:

    sudo !!

    ## OR ##

    sudo !-1

    !! or !-1 is a bash history feature that refers to the previous command. #OpenSource

    Reply
  8. Tomi Engdahl says:

    Want to find out an IP address of Linux KVM guest from Linux host itself? Try these methods.

    https://www.cyberciti.biz/faq/find-ip-address-of-linux-kvm-guest-virtual-machine/

    Reply
  9. Tomi Engdahl says:

    Learn various commands for iptables firewall rules that can be stored permanently on Debian/Ubuntu/RHEL/Centos Linux server or desktop.

    https://www.cyberciti.biz/faq/how-to-save-iptables-firewall-rules-permanently-on-linux/

    #Linux #OpenSource

    Reply
  10. Tomi Engdahl says:

    BASH Prepend A Text / Lines To a File

    https://www.cyberciti.biz/faq/bash-prepend-text-lines-to-file/

    #Linux #Unix #OpenSource

    Reply
  11. Tomi Engdahl says:

    How to install and setup PostgreSQL on RHEL (Red Hat Enterprise Linux) 8 server https://www.cyberciti.biz/faq/install-and-setup-postgresql-on-rhel-8/

    Reply
  12. Tomi Engdahl says:

    telemetry domains. DNS level block list. You can find such lists on Github and other pages for your personal or office usage. Or install pi-hole https://cyberciti.biz/faq/ubuntu-linux-install-pi-hole-with-a-openvpn/ on your Debian/Ubuntu/CentOS home server.

    Reply
  13. Tomi Engdahl says:

    Want to show and count all open files and list the top 10 processes on #Linux or Unix? Try:

    lsof | awk ‘{print $1}’ | sort | uniq -c | sort -r | head

    See my page for more tips https://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/

    Reply
  14. Tomi Engdahl says:

    Learn how to view the status of a service on #Linux using systemctl for debugging purposes.

    https://www.cyberciti.biz/faq/systemd-systemctl-view-status-of-a-service-on-linux/

    Reply
  15. Tomi Engdahl says:

    Quick and dirty way to find out remote ssh server version using #Linux, macOS or Unix desktop with bash only:

    timeout 1 cat </dev/tcp/ip_addr/22
    timeout 1 cat </dev/tcp/192.168.2.236/22
    timeout 1 cat </dev/tcp/localhost/22

    You need bash v2.04+ and must be compiled with networking support. Hiding OpenSSH/sshd version is not important. Instead of that, make sure you patch your system on time, including OpenSSH, disable root login, enable ssh keys based login, 2FA and more. See OpenSSH security best practices https://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html guide.

    Reply
  16. Tomi Engdahl says:

    for i in /proc/[0-9]*; do cmd=$(cat $i/cmdline|tr ” ‘ ‘) a=( $i/fd/* ); echo “${#a[*]} $cmd”; done|sort -nrk1|head -n10

    Reply
  17. Tomi Engdahl says:

    Advance your Linux skills with these 3 command line primers
    You can’t rely on a GUI forever. Instead, check out these helpful Linux guides on how to manage users and servers with the command line.
    https://www.techrepublic.com/article/advance-your-linux-skills-with-these-3-command-line-primers/

    Reply
  18. Tomi Engdahl says:

    Want to find out hard disk drive specs under Linux? Try these commands
    https://www.cyberciti.biz/faq/find-hard-disk-hardware-specs-on-linux/

    Reply
  19. Tomi Engdahl says:

    Learn how to keep your CentOS 8 Community Enterprise Linux server or desktop secure by installing security updates on time.
    https://www.cyberciti.biz/faq/centos-8-update-installed-packages-for-security/

    Reply
  20. Tomi Engdahl says:

    //Pro tip: If possible, always avoid white spaces and special characters in your filenames. It will save so many headaches and time when scripting common tasks on your Linux or Unix boxes. Exhibit A.
    TL;DR; always use camel case or under score.

    A well written script should be able to deal with the broad range of allowed symbols. Always. Otherwise you have very propably a serious security problem.

    But you should create your files in a way to make it easier to handle them.

    Reply
  21. Tomi Engdahl says:

    and don’t use & ” ‘ ; etc

    Reply
  22. Tomi Engdahl says:

    //Kotlin is an open source, statically typed, programming language running on the JVM. It can also be compiled to Javascript source code. Let us see how to install Kotlin on an Ubuntu or Debian Linux dev system. https://www.cyberciti.biz/faq/how-to-install-kotlin-programming-language-on-ubuntudebian-linux/

    Reply
  23. Tomi Engdahl says:

    // Did you know we can create a Linux swap file to optimize server configuration or immediately increase swap space? Useful for desktop/laptop users for hibernation too.
    https://www.cyberciti.biz/faq/how-to-create-a-linux-swap-file/

    Reply
  24. Tomi Engdahl says:

    Learn how to protect your CentOS 8 OpenSSH (sshd) server with Fail2Ban
    https://www.cyberciti.biz/faq/how-to-protect-ssh-with-fail2ban-on-centos-8/

    Reply
  25. Tomi Engdahl says:

    // This tutorial explains how to install different versions of Java (OpenJDK) on Ubuntu Linux 20.04 LTS and manage them using the CLI. Once Java is installed, we can write an application or install tomcat etc. https://www.cyberciti.biz/faq/install-java-on-ubuntu-20-04-linux/

    Reply
  26. Tomi Engdahl says:

    The Unix timestamp will begin with 16 this Sunday. Let us run simple while loop to see this on your screen (poor man’s count down):

    tput clear; while :; do tput cup 10 10; date +%s; sleep 1; done

    Reply
  27. Tomi Engdahl says:

    // Here is a pro tip to create a temporary and disposable email from your Linux and Unix/macOS terminal. https://www.cyberciti.biz/open-source/command-line-hacks/tmpmail-temporary-email-right-from-linux-unix-bash-shell/

    Reply
  28. Tomi Engdahl says:

    //Learn how to find and delete a directory recursively on Linux or Unix-like system. Useful for removing older directories or backups after 30 dayshttps://www.cyberciti.biz/faq/how-to-find-and-delete-directory-recursively-on-linux-or-unix-like-system/

    Reply
  29. Tomi Engdahl says:

    // Want to see firewalld dropped or rejected firewall log on your CentOS/RHEL/SUSE/OpenSUSE Linux server? Try these tips to enable a separate log file using rsyslogd. https://www.cyberciti.biz/faq/enable-firewalld-logging-for-denied-packets-on-linux/

    Reply
  30. Tomi Engdahl says:

    Pro tip: Here is how to kill your unresponsive hung ssh session without killing your terminal app.
    https://www.cyberciti.biz/faq/openssh-linux-unix-osx-kill-hung-ssh-session/

    Reply
  31. Tomi Engdahl says:

    Linux / Unix acronym of the day:

    dd = Disk Destroyer.

    Reply
  32. Tomi Engdahl says:

    //Quick tip: Display banner/message before OpenSSH authentication on your Linux and Unix boxeshttps://www.cyberciti.biz/howto/quick-tip-display-banner-message-before-openssh-authentication/

    Reply
  33. Tomi Engdahl says:

    //Want to manage Linux firewall rules on the LXD bridge manually? Here is how to disable NAT and firewall rules on the LXD bridge

    https://www.cyberciti.biz/faq/how-to-disable-firewall-and-nat-rules-on-the-lxd-bridge/

    Reply
  34. Tomi Engdahl says:

    // Alpine Linux is a systemd free Linux distro that comes with OpenRC. Let us see how to set up WireGuard VPN and SNAT using Awall firewall to route traffic via our VPN client. https://www.cyberciti.biz/faq/how-to-set-up-wireguard-vpn-server-on-alpine-linux/

    Reply

Leave a Comment

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

*

*