User Tools

Site Tools


system

System


SYSTEM
uname (-s) prints the name of the OS, -r kernel version, -v kernel release date, -p processor architecture, -n nodename (the name by which the system is known to the network), -a all the information above
lsb_release prints LSB (Linux Standard Base) version
lsb_release -d / cat /etc/redhat-release prints linux distribution name and version
dmidecode displays the system’s hardware components and BIOS information, -s <keyword> information only about a particular item from the list of available keywords
# dmidecode -s system-uuid
(prints the system ID)
# dmidecode -s system-product-name | egrep -i 'virtual|vm|bochs'
(prints information whether the system is a virtual server)
lscpu displays information about the CPU
cat /proc/cpuinfo displays detailed information about the particular CPU cores
free displays the amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel in kB (data from /proc/meminfo), -m in MB, -t total
nmon displays detailed CPU, memory, network, disks, kernel, file systems, NFS, and top processes statistics information (the output changes according to the current state)
ulimit prints or sets the resource usage limits of the shell and any processes started by it (by default with option "-f"), -a prints all current limits, -H sets a "hard" resource limit, -S sets a "soft" resource limit, -f <limit> the maximum size of files created by the shell in MB, -n <limit> the maximum number of open file descriptors, -t <limit> the maximum amount of the CPU time in seconds , -u <limit> the maximum number of processes available to a single user; (permanent setup in /etc/security/limits.conf)
chroot <root_directory> changes the root directory to that specified by the parameter and starts a new shell (handy when working in a rescue mode from an external media)
# chroot /mnt/sysimage
(connects directly to the hard disk with the original installation from where it is possible to repair the damaged system)
setup starts a configuration tool for the system setup
cal / cal <MM> <YYYY> displays a calendar (the current month) / the particular month of the year, -m Monday is the first day of the week, -y the whole year
$ cal 8 2005
date / date <MMDDhhmmYY>

date +<format>



date -d @<number_of_seconds>
displays / sets the current system date and time
# date 0321120098
displays the date in the particular format, e.g. %H prints hour in a 2-digit 24-hour format, %M prints minute in a 2-digit format, %d prints day in month in a 2-digit format, %m prints month in a 2-digit format, %Y prints year in a 4-digit format
$ date +%H:%M_%d.%m_%Y
converts the time in seconds from 1.1.1970 to human readable format
$ date -d @123456
ntpdate <server> sets the system date and time via NTP server; (permanent setup in /etc/ntp.conf)
# ntpdate tak.cesnet.cz
hwclock -r prints hardware date and time, -s sets the system time according to the hardware clock, -w sets the hardware time according to the system clock, --set –date=<YYMMDD hh:mm:ss> sets the hardware time to the given value
# hwclock --set --date='780321 22:06:56'
uptime displays the current time, how long the system has been running, how many users are currently logged on and the system load averages for the past 1, 5 and 15 minutes
who -b prints the last system boot time
dmesg prints the kernel messages during the system boot process (useful e.g. to find out whether the system has recognized a new device; data from /var/log/dmesg)
$ dmesg | grep usb
sysctl <parameter> prints the particular kernel parameter and its current value, -a prints all kernel parameters and their current values, -w <parameter>=<value> modifies kernel parameters at runtime; (available parameters can be found in /proc/sys, permanent setup in /etc/sysctl.conf), -p synchronizes data from /etc/sysctl.conf with the kernel
# sysctl -w net.ipv4.icmp_echo_ignore_all=1
(ignores ping requests)
# sysctl -w net.ipv4.ip_forward=1
(enables IP forwarding)
# sysctl -a | egrep "net.ipv4.(tcp_syncookies|icmp_echo_ignore_broadcasts|conf.all.accept_redirects)"
cat /etc/grub.conf (lilo.conf) prints the boot loader setup for starting the OS
cat /etc/default/grub
(implemented in Red Hat Enterprise Linux 7 - GRUB 2)
prints the boot loader setup for starting the OS, the related scripts are found in /etc/grub.d
grub-install <device> installs grub on particular device
# grub-install /dev/sda
mkinitrd <RAM_disk_image> <kernel_version> creates an initial RAM disk image containing basic modules needed for mounting "/" filesystem (only then modules inside /lib/modules/<kernel_version> can be loaded), --with=<module> adds a particular module into the initial RAM disk image, -v detailed output
# mkinitrd /boot/initrd-$(uname -r).img $(uname -r)
(recreates the initial RAM disk image; needed e.g. when ext2 FS has been converted to ext3 FS)
# mkinitrd --with=raid1 /boot/initrd-raid1-$(uname -r).img $(uname -r)
(the new initial RAM disk image with the particular module has to be added to /boot/grub/grub.conf as a new paragraph - i.e. copy the previous part from the line beginning with "title..." to "initrd..." and correct the new RAM disk image title on the last line; at the system startup it is possible to choose this new image to be used)
lsmod lists all modules loaded in the kernel (data from /proc/modules)
modinfo <modul> shows information about a module, -d short description
insmod <modul> inserts a module into the kernel (provided no other dependences are required)
rmmod <modul> removes a module from the kernel (provided no other dependences are required), -v detailed output
depmod (-a) / depmod <modul> generates a list of dependences of all / particular modules in /lib/modules/<kernel_version>/modules.dep
modprobe <modul> inserts a module into the kernel including all its dependences, -r remove a modul, -v detailed output
# modprobe usbnet
runlevel / who -r prints the previous and current system runlevel / prints the current system runlevel and its time of launch
systemctl list-units --type target
(implemented in Red Hat Enterprise Linux 7)
prints the current system runlevel (currently loaded "target units")
init / telinit <runlevel> changes the system runlevel, 0 halt, 1 single-user mode without network,
2 multi-user mode without network, 3 multi-user mode with network, 4 not used (user-definable), 5 runlevel 3 + GUI, 6 reboot; the configuration file of the init process is /etc/inittab, if the file is changed, its re-examination is launched by command "init q"
# init 5
systemctl isolate <runlevel>.target
(implemented in Red Hat Enterprise Linux 7)
changes the system runlevel (current "target unit"), runlevel0.target / poweroff.target power off, runlevel1.target / rescue.target single-user mode without network, runlevel2.target / multi-user.target multi-user mode with network, runlevel3.target / multi-user.target multi-user mode with network, runlevel4.target / multi-user.target multi-user mode with network, runlevel5.target / graphical.target multi-user mode with network + GUI, runlevel6.target / reboot.target reboot
# systemctl isolate multi-user.target
# systemctl isolate runlevel5.target
systemctl rescue
(implemented in Red Hat Enterprise Linux 7)
changes the system runlevel to single-user mode without network, mounts all local file systems and starts important system services
systemctl emergency
(implemented in Red Hat Enterprise Linux 7)
changes the system runlevel to single-user mode without network, mounts only root file system for reading and starts the most important system services (used when the system is unable to enter rescue mode)
systemctl get-default
(implemented in Red Hat Enterprise Linux 7)
prints the default system runlevel (default "target unit")
systemctl set-default <runlevel>.target
(implemented in Red Hat Enterprise Linux 7)
alters the default system runlevel (default "target unit")
# systemctl set-default graphical.target
chkconfig <service> <status> sets the service availibility on all runlevels, --list / --list <service> lists all services / particular service and their / its status (off / on) on all runlevels, --add <service> adds a new service under chkconfig management, --del <service> removes a service, --level <runlevel> <service> <status> sets the runlevel for a service
# chkconfig sshd on / off
# chkconfig –level 12 qemu off / on
$ chkconfig --list | egrep -i "rexec|rlogin|rsh"
systemctl <status> <service>
(implemented in Red Hat Enterprise Linux 7)
according to the given status (enable, disable, status) enables / disables / shows status of a service ("service unit")
# systemctl enable / disable / status httpd(.service)
# systemctl list-unit-files --type service
(lists all services and their status)
service <service> <action> according to the given action (start, stop, restart, reload, status) starts / stops / restarts / reloads configuration file / shows status of a service
# service crond start / stop / restart / reload / status
# /etc/init.d/crond start / stop / restart / reload / status
# service --status-all
(shows the status of all services)
systemctl <action> <service>
(implemented in Red Hat Enterprise Linux 7)
according to the given action (start, stop, restart, reload, status) starts / stops / restarts / reloads configuration file / shows status of a service ("service unit")
# systemctl start / stop / restart / reload / status httpd(.service)
# systemctl list-units --type service --all
(shows the status of all services)
reboot / init 6 stops all processes, saves the FS cache on the disk and reboots the OS
systemctl reboot
(implemented in Red Hat Enterprise Linux 7)
stops all processes, saves the FS cache on the disk and reboots the OS
halt / init 0 stops all processes, saves the FS cache on the disk and stops the processor (stand-by mode)
systemctl halt
(implemented in Red Hat Enterprise Linux 7)
stops all processes, saves the FS cache on the disk and stops the processor (stand-by mode)
poweroff stops all processes, saves the FS cache on the disk and brings the OS down
systemctl poweroff
(implemented in Red Hat Enterprise Linux 7)
stops all processes, saves the FS cache on the disk and brings the OS down
shutdown stops all processes, saves the FS cache on the disk and stops the processor, -h <time> brings the OS down, -r <time> reboots the OS, -c cancels a running shutdown, -k <time> false shutdown, sends out the warning messages and disable logins to users
# shutdown -h now / 22:00
(brings the OS down immediately / at the particular time)
# shutdown -r +30 "quick reboot"
(reboots in 30 min. + warning messages)
startx starts an X window system
xterm runs a terminal in an X window system, -e <command> specifies a command to be run in the xterm window
# xterm -e "tail -f /var/log/secure" &
tty prints a user's terminal name
set prints all current variables (global + local) and functions, -x when situated at the beginning of a sript, the script is run in a debug mode (same as $ bash -x skript.sh)
set -o
set - / +o <option>
prints the current setup of the shell options
changes the shell options` setup, "-" sets the option, "+" cancels the option
$ set -o vi
(sets the "vi" editor environment to the shell)
printenv / printenv <variable> prints all / particular global variables
<variable>=<value> sets a local variable (it remains defined in the shell until its termination)
$ xy=day
$ now=$(date) / now=`date`
(the variable's value can be defined by a command's output)
$ PATH="$PATH:~/scripts"
(adds "scripts” directory to the "PATH” variable)
$ PS1="[\u@\h \W]\$ "
(sets the user's prompt; the "PS1” variable can be defined this way: \u = user, \h = hostname, \W = working directory)
# for home in $(awk -F : '{print $6}' /etc/passwd); do ls -l ${home}/.ssh/id_[rd]sa 2> /dev/null | egrep -v "^-rw-------"; done
(prints files containing private keys of all users whose permissions differ from value of 600)
export
export <variable(=value)>
lists all exported variables
exports a local variable in order to be valid also for subshells within the same session; permanent local variables are defined and exported in ~/.bash_profile, global variables in /etc/profile
$ export x / export x=y
echo $<variable> prints the value of the variable
$ echo $xy
day
$ echo $now
Wed 12 Mar 10:25:00 2008
$ echo $0
(prints the name of the current shell or shell script)
$ echo $$
(prints the PID of the current shell)
$ echo $?
(prints the RC of the previous foreground process)
$ echo $!
(prints the PID of the last background process)
$ echo $SHELL
(prints a user's login shell)
$ echo $SHELL
(prints a user's login shell)
$ echo $TERM
(prints the type of the terminal; the list of terminals is available in /usr/share/terminfo)
echo ${#<variable>} prints the length of the variable (number of characters)
echo <text> prints the text, -n suppresses a new line output after the last argument (useful in scripts)
$ echo it is a new week$xy / echo "it is a new week$xy"
it is a new weekday
$ echo "${xy}long period"
daylong period
(a space is needed after the variable otherwise it has to be put in "{}")
$ echo -n 'Enter the required action: '
unset <variable> removes a variable, -f <function> function definition
$ unset x
bash / sh <file> executes a particular (even read-only) file in a subshell; the file is being searched for in the current directory and in $PATH, -x runs the script in a debug mode
source / . <file> executes a (read-only) file in the current shell; the file is being searched for in $PATH or in the given path
$ . ~/.bash_profile
(refreshes a user profile without the necessity to log off and log on)
<file_name> / <path_to_the_file> executes an executable file in a subshell; the file is being searched for in $PATH / in the given path
$ ./script
script <file> saves everything that is displayed after executing the program on STDOUT into the given file, -a appends the output into the existing file, -c <command> saves the given command`s output only, ctrl+d exits the program
xargs (<command>) reads and divides a large amount of arguments from STDIN into smaller parts in order to be acceptable for the following command that is to be executed (usually it is not possible to assign an unlimited number of arguments to a command), -0 arguments are terminated by a null character instead of by whitespace and the quotes and backslash have no special meaning (this option must also be supported by the command providing the input for "xargs"), -t prints the command line on STDERR before executing it
# find . -name core -print0 | xargs -0 -t rm
# find / -user tom | xargs -t rm -Rf
$ find . -type d | xargs chmod 750
$ find . -atime -1 -type f | xargs ls -lutr | tail -1
eval <argument> concatenates arguments and executes them as a shell command
$ user=david; eval cd ~$user
expr <expression> evaluates mathematical and other expressions
$ expr 7 + 3
$ expr "(" 6 - 3 ")" "*" 10
$ expr length ABCD
seq <specification> prints a sequence of numbers (one on each line) defined by an upper and eventually lower limit or an increment, -w equalizes width by padding with leading zeroes in front of a single digit, -s <string> uses a string to separate the numbers
$ seq 2 5
(a lower and upper limit defined)
$ seq 1 .2 3
(a lower and upper limit defined including an increment)
$ seq -w 15
(digits 01 - 15)
$ seq -s ':' 10
(digits 1 - 10 separated by ":"
$ for i in $(seq 1 100); do expr $i "*" $i; done
(prints the square of numbers 1 to 100, each on a separate line)
yes (<string>) repeats printing a string (one on each line), if not specified, prints "y"
time <command> measures the time of a command execution
$ time wget google.com
type <command> prints whether a command is a program or a shell builtin or keyword, the full path to the binary file is printed for a program, -a shows all the occurances including aliases and functions
alias
alias <your_own_command>=<command>
prints all current aliases
defines an alias for the given command; (permanent setup in ~/.bashrc)
$ alias nopaste='curl -F file=@- nopaste.com/a'
unalias <your_own_command> cancels an alias, -a removes all aliases
history <n> prints history of last n commands, -c removes history
fc (<n> / <n m>) edits last (particular) command(s) by default editor, -e <editor> selects an editor, -l prints a numbered list of last executed (particular) commands, -r reverses the order of the commands, -s executes the last (given) command from history
$ fc -l -20 | grep cat
(prints last 20 commands containing "cat")
$ fc -l 210 250
(prints a list of commands in the given range)
$ fc -s / !!
(executes the previous command)
$ fc -s 560 / !560
(executes the particular command)
apropos / man -k <keyword> searches for commands containing the given string or its part
whatis / man -f <keyword> searches for commands containing the exactly given string
man / info <command> prints a manual page for the particular command
help
help <command>
displays all shell builtins and keywords
prints a manual page for a shell builtin or keyword
clear clears the terminal screen
reset clears the terminal screen and sets its default values
exit exits a shell or logs a user off
logout exits a login shell
setenforce <mode> sets a SELinux mode if it is enabled (0 = permissive - the security policy is not applied, only eventual warning messages are being logged into /var/log/messages, 1 = enforcing - the security policy defining files' access control is used; permanent setup in /etc/selinux/config)
getenforce prints the current SELinux mode ("enforcing", "permissive", or "disabled")
sestatus prints the current SELinux status, its mode and policy being used, -v detailed output based on data from /etc/sestatus.conf
chcon <context> <file> changes a file security context within SELinux (the security context consists of 5 colon separated parts - user:role:type:sensitivity:category, 2 last of which may not be defined in the system; when copying a file its security context changes according to the new, parent directory, when moving a file its security context persists), -u <user> for a particular user (value "root" for root, "user_u" for other users and "system_u" for processes), -r <role> for a particular role (defines the purpose of the particular file, process or user; value "object_r" for files and "system_r" for processes and users), -t <type> for a particular type (defines which process types can access particular file types; "unconfined_t" means that it is not restricted by SELinux policy), --reference <source_file> sets a file the security context according to the source file, -R recursively, -v detailed output
# chcon --reference /etc/hosts.allow /etc/hosts.deny
restorecon <file> sets a file the original security context within SELinux, -R recursively, -v detailed output
# restorecon /root/*
Last modified: 2018/10/16 12:21 by Miroslav Bernát

visits: