Why you should not rely on /bin/cat to read a script before running it…
How to write a script for Linux in bash that can hide code from cat.
How to write a script for Linux in bash that can hide code from cat.
The unneeded use of the cat command is very annoying, this is wasteful. Something like this is very annoying to see. cat unixhell.txt | sed ‘s/program/application/g’cat unixhell.txt | sed ‘s/program/application/g’ Do it like this instead. This is the proper way to use sed. sed ‘s/program/application/g’ unixhell.txtsed ‘s/program/application/g’ unixhell.txt The user gets the same output but … Read more
The gunzip utility can uncompress logfiles that are gzipped in archives, but this is not needed. To read a logfile that is gzipped, you can also use this command to print the contents to a terminal and not bother uncompressing the file. This allows reading log files in /var/log without needing root access. This is … Read more
This is the proper way to use grep. You do not need to use cat at all. This method works well and is one command, not two piping together. jason@jason-desktop:~/Documents$ grep apt-get ../.bash_history sudo apt-get update sudo apt-get install me-tv sudo apt-get update && sudo apt-get install xvst apt-get moo apt-get moojason@jason-desktop:~/Documents$ grep apt-get ../.bash_history … Read more
How to read a file and display the contents with Python. This sample code reads and outputs the contents of a file using Python. This is a very simple code sample for reading in a file and displaying it. #!/usr/bin/env python forme = "f.txt"; # Read a file and print the contents to … Read more
This is how to use grep to search a file without using cat. homer@neo:~/Documents$ grep "gcc" ../.bash_history gcc my.cpp gcc gcc hello.java gcc hello.java gcc hello.java gcc hello.java gcc mein.c -o mein gcc -c99 mein.c -o mein gcc -std=c99 mein.c -o mein gcc hello.c -o hello gcc hello.c -o hello gcc hello.c -o hello gcc … Read more
This is a neat trick that allows you to use cat to view the contents of a directory. This library is loaded before the cat command is executed and modifies its behavior to allow you to use cat to list a directory. #include <unistd.h> #include <stdio.h> #include <dirent.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include … Read more
The UNIX tail command is very useful for viewing the last number of lines of a logfile. As in this example. Showing the last 10 lines in the file /var/log/syslog. |{~}-{Thu Feb 16 21:36:44} -{john@deep-thought } $ tail -n 10 /var/log/syslog Feb 16 21:31:01 deep-thought cron[1480]: (*system*anacron) WRONG FILE OWNER (/etc/cron.d/anacron) Feb 16 21:31:29 deep-thought … Read more
I was playing around with /bin/cat on my FreeBSD laptop and I typed this command. This is a useful trick to join mp3 files together in one long audio file. jason@Yog-Sothoth:~/Music$ cat Dune\ \(1983\)\ OST\ -\ Dune\ Prophecy\ \(Long\ Version\)-UWFm2LIYNjg.mp3 > ambient-winter.mp3jason@Yog-Sothoth:~/Music$ cat Dune\ \(1983\)\ OST\ -\ Dune\ Prophecy\ \(Long\ Version\)-UWFm2LIYNjg.mp3 > ambient-winter.mp3 And now … Read more