*A blog post that I’m actively collecting “Linux pseudo files info, cheat sheets and tips”

Tips & Tricks

  • How to force a command to return exit code 0 even if the command exited non-zero?

  • How to install dependencies of .deb automatically which failed to install previously?

    Example Solution:

    $ dpkg -i r-base-core_3.3.3-1trusty0_amd64.deb || : \
    && apt-get --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -f install -y \
    
  • How to traverse directories in shell script?

    cd command should not be used to traverse directories. Remember that each commands in shell script will spawn as individual process unlink programming language, entire script as single process i.e. The scope of cd command is only for the child process, not the parent. By using pushd and popd we can achieve traversing directories.

    Example Solution:

    $ pushd Downloads
    $ cat download.txt
    $ popd
    $ pushd Downloads/movies
    $ ls
    $ popd
    

Files:

Special Device Files

  • /dev/null - Discards all data written to it but reports that the write operation succeeded Read man pages

  • /dev/full - Returns the error code ENOSPC (meaning “No space left on device”) on writing Read man pages

  • /dev/random - Special file that serves as a blocking pseudorandom number generator. It allows access to environmental noise collected from device drivers and other sources.(Block until additional environmental noise is gathered)Read man

  • /dev/urandom - Without block Read man pages

  • /dev/zero - Provides as many null characters as are read from it Read More

  • udev - Linux dynamic device management Read man pages

    • udevadm - command to query the udev database and sysfs Read More

Commands/Tools

  • lscpu - Display CPU architecture information

  • cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 40 | head -n 1 - Generates 40 characters long random string

  • mtr - mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.

  • lsblk - Lists block devices

Directories

  • /var/lock/ - Store lock files, which are simply files used to indicate that a certain resource (a database, a file, a device) is in use and should not be accessed by another process. Aptitude, for example, locks its database when a package manager is running.

  • /var/run - Used to store .pid files, which contain the process id of a running program. This is commonly used in services or programs that need to make their process id available to other processes.