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/

464 Comments

  1. Tomi Engdahl says:

    Hack Another ELF On The Stack
    https://hackaday.com/2022/05/22/hack-another-elf-on-the-stack/

    dropbear] recently found herself in a pickle. Dumping some data out of an Android app at a specific point for reverse engineering purposes. While it worked great in the simulator, it was painfully slow on hardware via lldb. The solution was to write a patch and apply it to the ELF file.

    dropbear] found a NOTE section that just contained some metadata. She created a new section at the end of the file for her custom assembly and modified the header to declare the NOTE section as a LOAD section that pointed at her new section, which would get mapped into memory. All that was left to do was tweak the assembly in the actual code to jump to her new code that dumps.

    Adding code to an existing ELF file
    https://dropbear.sh/blog/elf-patching.html

    Reply
  2. Tomi Engdahl says:

    Linux Fu: Easy Widgets
    https://hackaday.com/2022/06/02/linux-fu-easy-widgets/

    Here’s a scenario. You have a microcontroller that reads a number of items — temperatures, pressures, whatever — and you want to have a display for your Linux desktop that sits on the panel and shows you the status. If you click on it, you get expanded status and can even issue some commands. Most desktops support the notion of widgets, but developing them is a real pain, right? And even if you develop one for KDE, what about the people using Gnome?

    Turns out there is an easy answer and it was apparently inspired by, of all things, a tool from the Mac world. That tool was called BitBar (now XBar). That program places a widget on your menu bar that can display anything you want. You can write any kind of program you like — shell script, C, whatever. The output printed from the program controls what appears on the widget using a simple markup-like language.

    That’s fine for the Mac, but what about Linux? If you use Gnome, there is a very similar project called Argos. It is largely compatible with XBar, although there are a few things that it adds that are specific to it. If you use KDE (like I do) then you’ll want Kargos, which is more or less a port of Argos and adds a few things of its own.

    Good News, Bad News

    The good news is that, in theory, you could write a script that would run under all three systems. The bad news is that each has its own differences and quirks. Obviously, too, if you use a complied program that could pose a problem on the Mac unless you recompile.

    Reply
  3. Tomi Engdahl says:

    Optimizing Linux Pipes
    https://hackaday.com/2022/06/03/optimizing-linux-pipes/

    In CPU design, there is Ahmdal’s law. Simply put, it means that if some process is contributing to 10% of your execution, optimizing it can’t improve things by more than 10%. Common sense, really, but it illustrates the importance of knowing how fast or slow various parts of your system are. So how fast are Linux pipes? That’s a good question and one that [Mazzo] sets out to answer.

    The inspiration was a highly-optimized fizzbuzz program that clocked in at over 36GB/s on his laptop. Is that a common speed? Nope. A simple program using pipes on the same machine turned in not quite 4 GB/s. What accounts for the difference?

    Did he finally get to 36GB/s? No, he actually got to 65 GB/s! There is a lot to learn both in specific techniques and the approach.

    How fast are Linux pipes anyway?
    https://mazzo.li/posts/fast-pipes.html

    Reply
  4. Tomi Engdahl says:

    Need A Linux Kernel Module? Scratch That
    https://hackaday.com/2022/07/04/need-a-linux-kernel-module-scratch-that/

    If you have been for (or against) Rust in the Linux kernel, get ready for a Linux kernel module written in… Scratch. That’s right. Scratch, the MIT-developed language with blocks popular for teaching kids to code. We didn’t mean “from scratch.” We meant IN Scratch. The bootstrap code and Makefile is out there on GitHub.

    Of course, it is a simple module and the reason it is possible is because of the scratchnative system that lets you compile Scratch into C code. If you want to look at the decidedly simple code, you can open it in your browser.

    https://www.reddit.com/r/linux/comments/vm9r63/i_wrote_a_kernel_module_in_scratch/

    Reply
  5. Tomi Engdahl says:

    Here is a quick tutorial explaining how to convert JSON files to CSV format per applications needs using the Linux, macOS or Unix/*BSD system CLI. https://www.cyberciti.biz/faq/how-to-convert-json-to-csv-using-linux-unix-shell/

    Reply
  6. Tomi Engdahl says:

    https://www.facebook.com/groups/2420755034736319/permalink/2879582035520281/

    For any novice Linux users out there. Here’s a few examples of how to record and playback audio from the Linux command line (console). These examples are all centred around creating sine waves, but of course you can play music (including formats other than wav).
    #
    # some examples to play and record audio using arecord and sox
    # all examples process 24 or 32 bits of audio at 96khz
    # aplay -l will list playback devices
    # arecord -l will list capture devices
    #
    #
    # arecord – capture 60 seconds of 2 channel audio from hw:2,0 and write it to tmpwav.wav
    #
    arecord -D hw:2,0 -c 2 -r 96000 -fS24_3LE -d 60 tmpwav.wav
    #
    # sox – capture 60 seconds of 2 channel audio from hw:2,0 and write it to tmpwav2.wav
    #
    sox -b 24 -r 96000 -c 2 -t alsa hw:2,0 tmpwav2.wav trim 0 60
    #
    # generate a tone using play (part of sox)
    # generate a sinewave – this will generate a 2 channel 1khz sinewave at -9dB
    # of 100 seconds duration on playback hardware device 3,0 using a sample rate of 96khz
    #
    AUDIODEV=hw:3,0 play -r 96000 -n -b 24 -c 2 synth 100 sin 1000 vol -9dB
    #
    # create a file with the above instead of generating a tone
    #
    sox -b 32 -r 96000 -c 2 -n soundfile.wav synth 100 sine 1000 vol -9dB
    #
    # play a .wav file with aplay – the “-f” switch here is crucial (as with arecord above) and will vary according to your hardware
    # most likely options are S24_3LE or S32_LE (there are many more – see the aplay man page for details)
    #
    aplay -D hw:3,0 -f S24_3LE
    #
    # do the same with the play (sox) utility
    #
    AUDIODEV=hw:3,0 play
    #
    # the AUDIODEV variable is not required if ~/.asoundrc is configured correctly.
    #

    Reply
  7. Tomi Engdahl says:

    Adding comments to ufw rules helps understand the purpose of firewall rules easily. It also supports other Linux users /dev why the firewall rules were added by previous IT staff. Hence, I strongly suggest you document adding rules to your ufw firewall. https://www.cyberciti.biz/faq/howto-adding-comments-to-ufw-firewall-rule/

    Reply
  8. Tomi Engdahl says:

    11 dangerous Linux terminal commands every Linux user must be aware of (don’t run).

    https://twitter.com/linuxopsys/status/1555508963914813441?t=dhNZ6quME0m-n8jKtqGwRw&s=19

    Reply

Leave a Comment

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

*

*