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/

638 Comments

  1. Tomi Engdahl says:

    .A bash shell script says SEE YOU SPACE COWBOY whenever you logout from your Linux and Unix session https://www.cyberciti.biz/files/scripts/seeyouspacecowboy.sh.txt

    Reply
  2. Tomi Engdahl says:

    How to run a Google search from the Linux command line
    https://www.techrepublic.com/article/how-to-run-a-google-search-from-the-linux-command-line/

    Having the ability to Google from the command line can be an efficient way to look up something on Linux. Jack Wallen shows you how with the help of Googler.

    Reply
  3. Tomi Engdahl says:

    10 Linux commands to know the system
    https://www.cyberciti.biz/open-source/linux-commands-to-know-the-system/

    Here are 10 Linux command to know the system and increase your productivity quickly.

    Reply
  4. Tomi Engdahl says:

    Writing bash scripts and not yet using shellcheck? It is a static analysis and linting tool for sh/bash scripts. All developers and Linux/Unix sysadmin must use it. https://www.cyberciti.biz/programming/improve-your-bashsh-shell-script-with-shellcheck-lint-script-analysis-tool/

    Reply
  5. Tomi Engdahl says:

    Convert all project files in the current working dir from UPPER to lower case using Bash only on #Linux, macOS or #Unix:

    for f in *[[:upper:]]*; do mv -v — “$f” “${f,,}”; done

    See https://www.cyberciti.biz/faq/linux-unix-shell-programming-converting-lowercase-uppercase/ for more info.

    Reply
  6. Tomi Engdahl says:

    :(){ :|:& };: Bash Fork Bomb for your Linux or Unix boxes meme. See https://www.cyberciti.biz/faq/understanding-bash-fork-bomb/ for more info.

    Reply
  7. Tomi Engdahl says:

    neofetch is a blot https://www.cyberciti.biz/howto/neofetch-awesome-system-info-bash-script-for-linux-unix-macos/. Now we have a super tiny Linux system information fetch script written in BASH https://github.com/wick3dr0se/fetch.sh Enjoy! FYI, neofetch is cross platform, so i will stick with neofetch for now.

    Reply
  8. Tomi Engdahl says:

    This page explains how to check the health status of a USB stick in #Linux and obtain status so that you know if it is beyond repair or not. https://www.cyberciti.biz/faq/linux-check-the-physical-health-of-a-usb-stick-flash-drive/

    Reply
  9. Tomi Engdahl says:

    {Updated} Linux wget command examples: Your Ultimate Command Line Downloader https://www.cyberciti.biz/tips/linux-wget-your-ultimate-command-line-downloader.html Do you use wget?

    Reply
  10. Tomi Engdahl says:

    Get answer withing 15 seconds or continue with defaults when using the read command for prompting under #Linux or #Unix bash scripts:
    read -t 15 -N 1 -p “This will update nginx config FRONTEND. Continue (y/N)? ” answer

    See https://www.cyberciti.biz/tips/linux-unix-pause-command.html for more.

    Reply
  11. Tomi Engdahl says:

    Did you know? Bash can display error if ${var} is null or unset. For instance:

    var=”${var_name?:Error \$var_name not set. Bye}”
    var=”${1?:Error. Die}”

    If $1, is NULL or unset, it will show “Error. Die.” and script will terminate.

    See https://www.cyberciti.biz/faq/linux-unix-howto-check-if-bash-variable-defined-not/ for more info. #Linux #Unix #programming

    Reply
  12. Tomi Engdahl says:

    Did you know? You can prevent users from seeing processes that do not belong to them including environment variables by setting up he Linux kernel hardening hidepid flag. See https://www.cyberciti.biz/faq/linux-hide-processes-from-other-users/ for more info.

    Reply
  13. Tomi Engdahl says:

    Use delv Linux/*BSD/Unix/macOS command for sending DNS queries & validating the dnsec results. Example:
    delv cyberciti.biz
    # Test bunch of domains
    doms=”nixcraft.com google.com”
    for d in ${doms};do delv “$d”; done

    See https://www.nixcraft.com/t/dig-command-sigchase-option-is-deprecated-trusted-key-option-is-deprecated-on-linux/3979 for more info.

    Reply
  14. Tomi Engdahl says:

    Linux Fu: Don’t Share Well With Others
    https://hackaday.com/2021/12/28/linux-fu-dont-share-well-with-others/

    In kindergarten, you learn that you should share. But for computer security, sharing is often a bad thing. The Linux kernel introduced the concept of namespaces starting with version 2.6.24. That’s been a few years ago, but namespaces are not used by many even though the tools exist to manipulate them. Granted, you don’t always need namespaces, but it is one of those things that when you do need it, the capability is priceless. In a nutshell, namespaces let you give a process its own private resources and — more importantly — prevents a process from seeing resources in other namespaces.

    Turns out, you use namespaces all the time because every process you run lives in some set of namespaces. I say set, because there are a number of namespaces for different resources. For example, you can set a different network namespace to give a process its own set of networking items including routing tables, firewall rules, and everything else network-related.

    So let’s have a look at how Linux doesn’t share names.

    The possible namespaces are:

    Mount – File system mounts. It is possible to share mounts with other namespaces, but you have to do so explicitly.
    UTS – This namespace controls things like hostname and domain name.
    IPC – A program with a separate IPC namespace will have its own message queues, semaphores, shared memory, and other interprocess communications items.
    Network – Processes in the namespace will have their own networking stacks and related configurations.
    PID – Processes in a PID namespace can’t see other processes outside the namespace.
    Cgroup – A namespace that provides a virtualized view of the cgroup mounts for CPU management.
    User – Individual users, groups, etc.

    Go to Shell

    If you want to experiment with namespaces from the shell, you can use unshare. The name might seem odd, but the command takes its name from the fact that a new process typically shares the namespaces of its parent. The unshare command lets you create new namespaces.

    Mounts and More Options

    Another useful isolation is in the mount table. Linux handles mounts a bit differently. You can make mounts propagate in several ways. If you want total privacy, you can do that, but you can also share within a group, or track changes in other groups but not propagate your own changes. You can read more on the man page.

    One interesting thing is that since the namespaces are isolated, it is possible for a normal user to have quasi-root privileges in the new namespaces. The –map-root-user allows for this and also turns on an option to deny users calling setgroups which could allow them to get elevated permissions.

    Reply
  15. Tomi Engdahl says:

    This is so awesome. Get temperature in Linux, Unix, or macOS shell using the curl command:
    curl https://wttr.in
    curl https://wttr.in/London
    curl https://wttr.in/Mumbai

    Reply
  16. Tomi Engdahl says:

    CHAPTER 15. BLOCKING AND ALLOWING APPLICATIONS USING FAPOLICYD
    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/security_hardening/assembly_blocking-and-allowing-applications-using-fapolicyd_security-hardening

    Setting and enforcing a policy that either allows or denies application execution based on a rule set efficiently prevents the execution of unknown and potentially malicious software.

    15.1. Introduction to fapolicyd
    The fapolicyd software framework controls the execution of applications based on a user-defined policy. This is one of the most efficient ways to prevent running untrusted and possibly malicious applications on the system.

    Reply
  17. Tomi Engdahl says:

    The Complete Guide to User Management in Linux
    BY RUMAISA NIAZI
    PUBLISHED JAN 11, 2022
    Managing users is a crucial task every Linux system administrator should be proficient in. Here’s the ultimate user management guide for Linux.
    https://www.makeuseof.com/user-management-linux-guide/

    Reply
  18. Tomi Engdahl says:

    Did you know? You can use the dnstop on #Linux, #FreeBSD/ #Unix to monitor both authoritative & caching DNS server network traffic. It can show:
    + Source & Destination IP addresses
    + Query types
    + Response codes
    + Opcodes
    + Top level domains and much more.

    See https://www.cyberciti.biz/faq/dnstop-monitor-bind-dns-server-dns-network-traffic-from-a-shell-prompt/ for more info.

    Reply
  19. Tomi Engdahl says:

    How to issue Let’s Encrypt wildcard certificate with acme sh and Cloudflare DNS API and grab A+ ratings https://cyberciti.biz/faq/issue-lets-encrypt-wildcard-certificate-with-acme-sh-and-cloudflare-dns/ Useful when you need to TLS certs on LAN or other nodes of your Linux or Unix cluster.

    Reply
  20. Tomi Engdahl says:

    Linux fully supports OpenPGP, OTP-HOTP, OTP-TOTP, Yubico OTP, and FIDO U2F authentication protocols. The YubiKey Manager is available as both GUI and CLI mode. One can use GUI app for finding information about YubiKey & configure FIDO2 PIN, FIDO applications, the OTP application and more using GUI app. Let us see how to install YubiKey Manager on Linux
    https://www.cyberciti.biz/faq/how-to-install-yubikey-manager-gui-on-linux/

    Reply
  21. Tomi Engdahl says:

    Did you know? You can set a few Linux kernel values to increase Linux Internet speed with TCP BBR congestion control for your Linux VM or server. Try it out https://www.cyberciti.biz/cloud-computing/increase-your-linux-server-internet-speed-with-tcp-bbr-congestion-control/

    Reply
  22. Tomi Engdahl says:

    How To Reuse SSH Connection To Speed Up Remote Login Process Using Multiplexing https://www.cyberciti.biz/faq/linux-unix-reuse-openssh-connection/ #macos #linux #unix

    Reply
  23. Tomi Engdahl says:

    How to use htmlq to extract content from HTML files on Linux, macOS or FreeBSD
    Author: Vivek GiteLast updated: March 3, 20221
    https://www.cyberciti.biz/open-source/command-line-hacks/using-htmlq-to-extract-content-from-html-files-on-linux-unix/

    Reply
  24. Tomi Engdahl says:

    I AM ROOT: Enhancement to whoami on your Linux or Unix machine for fun. Get bash function code here https://www.cyberciti.biz/files/scripts/whoami.sh.txt . The user name is in /etc/passwd https://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/ while the password hash is in /etc/shadow https://www.cyberciti.biz/faq/understanding-etcshadow-file/ file.

    Reply
  25. Tomi Engdahl says:

    Did you know? You can use the disown built-in on Linux or Unix command to keep scripts or jobs running in the background after logging out from the ssh terminal session on the local/remote box:
    /path/to/my-script & # start the job
    disown -h # disown the last job (SIGHUP is not sent to the job)
    exit # terminate ssh terminal session
    See https://www.cyberciti.biz/faq/unix-linux-disown-command-examples-usage-syntax/ for more info

    Reply
  26. Tomi Engdahl says:

    Did you know? You can use the upower command under Linux to list your laptop/pc/mouse battery status:

    upower -e # get list and query it
    upower -i /org/freedesktop/UPower/devices/battery_BAT0

    See my page https://www.cyberciti.biz/faq/linux-upower-command-examples-and-syntax/ for more info.

    Reply
  27. Tomi Engdahl says:

    Did you know? The first line in your shell/python/perl script “#!/bin/sh” or “#!/usr/bin/evn python” is called Shebang, & it is used to tell the Linux/Unix OS which interpreter to use to parse the rest of the file. You can override interpreter at the CLI:
    bash foo.ksh
    Run the script as python3 instead of default python3 shabang”
    python3 old-script.py

    See https://bash.cyberciti.biz/guide/Shebang for more info.

    Reply
  28. Tomi Engdahl says:

    Linux Fu: An Odd Use For Fork()
    https://hackaday.com/2022/04/21/linux-fu-an-odd-use-for-fork/

    Parallel Processing Made Easy

    For my client’s long report, the program was mostly I/O bound. However, each report also had some pretty hairy math to go along with it, in addition to all the math required to get to the point that each report could execute. Instead of executing all of it in one process, I broke the program up into multiple pieces. The first piece did as much math as it could that applied to nearly everything. Then the program called fork a bunch of times and each child started a report which did a little more math just for itself and claimed a printer to write the output.

    Since the CPU had multiple processors, everything got sped up. Report three didn’t have to wait for reports one and two to complete. Everyone was able to drive the printers at once. It was an overall win and it took almost no time to make this fix.

    Granted, not every problem will allow for a fix like this one. But giving each report process a memory copy of the data was very fast compared to reading it from a file or database. The data didn’t change after the reports started, so real memory consumption wasn’t too bad, either.
    An Example

    So is it really that simple? It is. The only problem now is that with modern machines, it is hard to find a simple problem to demonstrate the technique. I finally settled on just doing something simple, but doing lots of it. My made up task: fill a really large array of double-precision floating point numbers with some made up but predictable data and then find the average. By really large I mean 55 million entries or more.

    Reply
  29. Tomi Engdahl says:

    Bash in 100 Seconds
    https://www.youtube.com/watch?v=I4EWvMFj37g

    Bash is the command line shell that you encounter when you open the terminal on most Unix operating systems, like MacOS and Linux. Learn how to create your own bash scripts to automate tasks on your computer.

    Reply

Leave a Comment

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

*

*