
LINUX USEFUL COMMANDS
I have posted few basic regularly using commands. Which makes ease for the routine job sometimes.
For best results, search the keyword you want to see.Hope it helps you.
HAPPY READING :-)
*) screen
screen command for remote terminal access on interrupt :
screen -r --> last opened session
screen -S 23536 -X quit ---> Quit existing sockets
screen -S pavi --> Creates a new socket
*) fallocate
fallocate -l <lengthin KB, MB, GB, PB and EB> filename
Ex: fallocate -l 1KB dummy.jpg
Helps to create a space filled file with the size specified.
fallocate -l <lengthin KB, MB, GB, PB and EB> filename
Ex: fallocate -l 1KB dummy.jpg
Helps to create a space filled file with the size specified.
readelf <path to elf formated files.
ELF stands for "Executable and Linkable Format.We can generate .elf file or .out file from compilers. readelf command parses the file, and reads out the symbol from the file. It does more or same the job of objdump, but with more details.
Ex: readelf /path/to/program
*) pmap - memory usage
pmap <pid> will tell the memory consumed by the process.
Alternatively with command ps -aux | grep -i <processName> . With pid, top command displays the mem info in VIRT column.
*) ldd (List Dynamic Dependencies)
ldd <executable name>
It will lists the shared library dependency of the executable file.
Ex: ldd /path/to/program
*) nm (path of the object file+name)
Lists the symbols/functions from the object file or the executable.
Note: if using execuatble, it should be built with the symbols.
Ex: nm -l *.o | grep func
*) read (reads the value from the stdin aloneand stores in the variable)
read varname
echo $varname
*) systemd cmds
Path:
Usual conf file are stored in "/etc/systemd/" (or) "/usr/lib/systemd"
Unit files are stored in "/etc/systemd/system" (or) "/usr/lib/systemd/system" ( or) "/lib/systemd/system"
systemctl displays detailed view of all installed system service units
systemctl list-unit-files displays the installed list of unit files
systemctl --all -t service lists services acc. to the loading time
systemctl start/stop/status/disable/enable <serviced file name> operating with service
systemd-analyze help to analyse the boot performance
systemd-analyze blame/critical-chain
systemd-analyze plot > imageName.svg displays the systemd image in the boot time order
*) ssh cmds
~/.ssh This is the regular placeholder of the ssh generated keys in unix based systems
ssh-keygen will generate the public keys ida_rsa.pub
ssh-keygen -t ed25519 -C "<comment>" Generate ED25519 SSH keys
ssh-keygen -t rsa -b 2048 -C "email@example.com" Generate RSA Keys with key size of 2048
ssh-keygen -R <hostNameIP> Removes the hostName details from known_hosts file
ssh -p <portNo> username@ip Login to the user shell/console
scp -P <portNo> source destination Copies individual files
scp -r -P <portNo> source destination Copies entire directory recursively
problems faced while using existing keys:
- zip and unzip the ssh content files and restart the linux machine.
- you might get error "sign_and_send_pubkey" because of invalid permission and the unrecognized ssh public keys. Because, after the copy of ssh keys, the system will not recognize the public keys
- in this case, use eval $(ssh-agent) -> "ssh-add" -> chmod 600 id_ed25519 id_rsa -> chmod 644 id_ed25519.pub id_rsa.pub known_hosts -> restartthe linux machine
*) Debian files installation
sudo apt install <path to deb>
*) alias (its a substitute command)
alias ll="ls -al"
*) clear (clears the screen of console/terminal)
ctrl+r is the shortcut command. It just clears the display console.
*) reset (resets the terminal/console)
Its contrasts to clear command. It clears everything in the console buffer.
*) ls (lists the directory structure)
Very basic command. It will display/ lists the files and folder in the given path.
*) cat (displays the contenets of the file)
This is not allowed to edit the file.
*) tail & head
tail and head are the commands to display the file contents in limited stream.
tail -f <filename> ===> to display the latest updated contents
*) ps -e -aux
display the process list
*) netstat -tulpn -r
to check the network related statistics or other info
*) tcpdump
to get the tcp data to a file
tcpdump -i eth0 -w /lcfg/tcpdump_linux_failsafe.cap
*) strip
strip the debug symbols and generates a release variant binaries
*) grep
search tool. to find the contents.
grep -E '199|200' -> grep for multiple searches
*) find
find ./ -iname filename_to_search
*) useradd -m <username>
Adds user to the linux machine. Helpful for jenkins machine to add jenkins user
sudo passwd <username>
sudo su - <username> for login to the user
sudo -i -> to login as the root user
*) tar -xvf filename
Extract the tar file
*) set -e stop on error in shell script
if we are executing the commands in the shell script and we want stop on error
use set -e -> then command in the next line. to close te loop, use set +e
we can also pass as arg like "bash -e <script.sh>"
we can also pass as arg like "bash -e <script.sh>"
*) busybox Linux light-weight utility
BusyBox is a software suite that provides several Unix utilities
in a single executable file. It runs in a variety of POSIX environments
such as Linux, Android, and FreeBSD, although many of the tools it
provides are designed to work with interfaces provided by the Linux
kernel.
But busybox has the restrictions of supporting limited options.
To overcome this problem, we can build our own toolset in the respective SDK and deploy in the platform.
*) tools Build procps, pscommand, top etc
BUILD :
https://gitlab.com/procps-ng/procps/-/tree/master/
source sdk environment
./autogen.sh
./configure=aarch64 (or) ./configure --prefix=<path to install> -host=arm64 (or) ./configure --help
make
source sdk environment
./autogen.sh
./configure=aarch64 (or) ./configure --prefix=<path to install> -host=arm64 (or) ./configure --help
make
Ex: ./pscommand -p 6374 -L -o pid,tid,psr,pcpu
BUILD:
https://github.com/Atoptool/atop.gi
make
BUILD PERF:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tag/?h=v5.14-rc2
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tag/?h=v5.14-rc2
reset ; make WERROR=0 ARCH=arm64 CROSS_COMPILE=aarch64-mbient-linux- NO_LIBPERL=1 NO_LIBPYTHON=1 NO_AIO=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_LIBBIONIC=1 NO_SLANG=1 NO_LIBAUDIT=1 NO_LIBCRYPTO=1 NO_LIBDW_DWARF_UNWIND=1 SKIP_TARGETS=selftests NO_LIBBABELTRACE=1 NO_LIBNUMA=1 NO_DWARF=1 NO_BACKTRACE=1 NO_LZMA=1 NO_LIBCAP=1 NO_SDT=1 LIBBPF_DYNAMIC=1 EXTRA_PERFLIBS=-lpthread
Reference: https://www.brendangregg.com/perf.html
*) top / atop / htop [ CPU Monitor Commands ]
top displays the cumulative cpu consumption for every process. Ex: In 8core machine, the top lists the average result of the cpu consumption in each core. 10% is the consumption in all cores.
atop displays the highest cpu consumption in the cpu core. Accurate and reliable.
htop is interactive process-viewer and process-manager for Linux.(depends on ncurses).
top -p < PID> Details in each cpu level.
top -H -p <pid> Thread level cpu and memory consumption
atop -y Thread details
atop -m Memory usage
atop 1 | grep -i <processName> List entry for every 1 second
*) pfctl -d
controls the packets filter device. 'd' is for disabling the filter.
https://man.openbsd.org/pfctl
This is used in specially for the someip tracking or the packet send/receive communication.
Linux:
MAN : For any detailed help, 'man' command helps to display the usage and options.
Ex: man <command>
QNX:
USE : For any detailed help, 'use'command helps to display the usage and options.
Ex: use <commandName>
Links:
https://courses.cs.washington.edu/courses/cse390a/14au/bash.html
https://pubs.opengroup.org/onlinepubs/009696699/utilities/contents.html
Thanks for reading the blog. Hope to see you again.
Pavanashree Krishnappa.
Thanks for reading the blog. Hope to see you again.
Pavanashree Krishnappa.