Linux Commands Flashcards
How check how much memory available and used on server?
- free (free - m)
- cat /proc/meminfo
- vmstat
- top
How find kernel version?
- cat /proc/version
- uname -r
- hostnamectl | grep Kernel
How find Linux distribution?
- cat /etc/os-release
- lsb_release -a
- hostnamectl
How find CPU(s) on motherboard?
- cat /proc/cpuinfo
- lscpu
How find the number of CPU cores?
- cat /proc/cpuinfo | grep ‘core id’
How list devices on PCIe bus?
- lspci
How list installed packages?
- “yum list installed”
- “dnf list installed”
How display kernel modules?
- lsmod
- /proc/modules
- dnf module list (all modules)
- dnf module list –enabled (list of enabled modules)
- dnf module list –disabled
How do you load/unload a kernel module?
- modprobe can load/unload a “loadable” module
How find more info about a module?
- modinfo (find driver name from lsmod)
Where are kernel modules stored?
/lib/modules/$(uname -r)
How mount device?
I uselsblkto get my mount points, which is different frommountFor melsblkis easier to read thanmount
Make sure that you have a directory created before you go to mount your device.
sudo mkdir /{your directory name here} sudo mount /dev/{specific device id} /{your directory name here that is already created}
You should be good to go, however check security permissions on that new directory to make sure it’s what you want
How view/modify disk partitions?
- fdisk
- parted
- df (will show partitions even if not real drives - ram drive)
What is fstab?
- file system table. Each line in the file describes a filesystem, and contain fields used to provide information about its mountpoint, the options which should be used when mounting it etc.
How run linux job in background? How bring it back to foreground?
For running a process in background use “&” in command line. For bringing it back in foreground use command “fg jobid” and for getting job id you use command jobs, for killing that process find PID and use kill -9 PID command. This is indeed a good Unix Command interview questions because many of programmer not familiar with background process in UNIX. See NOHUP for keeping process running after logout.
How see previously used commands from command line?
- “history” command
How find how much space left on drives?
- “df”
What is a zombie process?
When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child’s exit status. To be able to get this information, the parent calls ‘wait()’; In the interval between the child terminating and the parent calling ‘wait()’, the child is said to be a ‘zombie’ (If you do ‘ps’, the child will have a ‘Z’ in its status field to indicate this.)
Zombie : The process is dead but have not been removed from the process table.
How find files?
To find files that match a specific pattern, use the -name argument. You can use filename metacharacters (such as * ), but you should either put an escape character ( \ ) in front of each of them or enclose them in quotes.
For example, if we want to find all the files that start with “pro” in the Documents directory, we would use the cd Documents/ command to change to the Documents directory, and then type the following command:
find . -name pro*
How check of process is listening on a remote server and port
- telnet
How keep process running in background after user logs out?
nohup is a special command which is used to run process in background, but it is slightly different than & which is normally used for putting a process in background. An UNIX process started with nohup will not stop even if the user who has stared log off from system. While background process started with & will stop as soon as user logoff.
$ nohup command-name &
$ exit
or
$ nohup /path/to/command-name arg1 arg2 > myoutput.log &
$ exit
What is ephemeral port?
An ephemeral port is a short-lived transport protocol port for Internet Protocol (IP) communications. Ephemeral ports are allocated automatically from a predefined range by the IP stack software. An ephemeral port is typically used by the Transmission Control Protocol (TCP), User Datagram Protocol (UDP), or the Stream Control Transmission Protocol (SCTP) as the port assignment for the client end of a client–server communication to a particular port (usually a well-known port) on a server.
How see update of command/process output?
- use ‘watch’
for example to watch drive space every 5 secs, use:
“watch -n 5 df -h”
How replace words in file/data?
- use sed (stream editor):
“sed s/Unix/UNIX/g fileName”
How find how long server has been running?
-“uptime”