*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 ofcd
command is only for the child process, not the parent. By usingpushd
andpopd
we can achieve traversing directories.Example Solution:
$ pushd Downloads $ cat download.txt $ popd $ pushd Downloads/movies $ ls $ popd
Files:
/sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
- Real time speed of the CPU(ability to adjust their speed to help in saving on battery/power usage)/proc
Directory/proc/cpuinfo | grep MHz
- The absolute (max) CPU speed/proc/sys/net/ipv4/*
- Get more info under this directory from kernel.org docs/proc/net/tcp and /proc/net/tcp6
- Get complete info of variables for these files from kernel.org.docs
/proc/sysctl
https://www.kernel.org/doc/Documentation/sysctl/ https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Reference_Guide/s3-proc-sys-net.htmlNetwork related in Linux - Refer kernel.org.doc
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 Moreudev
- Linux dynamic device management Read man pagesudevadm
- command to query the udev database andsysfs
Read More
Commands/Tools
lscpu
- Display CPU architecture informationcat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 40 | head -n 1
- Generates 40 characters long random stringmtr
- 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.