User Tools

Site Tools



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 total amount of free and used physical and swap memory in the system, as well as the buffers and caches 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 (<MM> <YYYY>) displays a calendar (the current month or a particular month of the year), -m Monday is the first day of the week, -y the whole year
$ cal 8 2005
date (<MMDDhhmmYY>)

date +<format>

date -d @<number_of_seconds>
displays or 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 since January 1st, 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
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 system time, how long the system has been running, how many users are currently logged in 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 (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"), / power off, / single-user mode without network, / multi-user mode with network, / multi-user mode with network, / multi-user mode with network, / multi-user mode with network + GUI, / reboot
# systemctl isolate
# systemctl isolate
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
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 / shutdown -h 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
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)
unset <variable> removes a variable, -f <function> function definition
$ unset x
printenv (<variable>) prints all or particular global variables
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 (<text> / $<variable>) prints the text or value of a variable, without the parameter a blank line is displayed, -n suppresses a new line output after the last argument (useful in scripts)
$ echo -n 'Enter the required action: '
eval <argument> concatenates arguments and executes them as a shell command
$ user=david; eval cd ~$user
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
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–100, each on a separate line)
yes (<string>) repeats printing "y" or a particular string (one on each line)
time <command> measures the time of a command execution
$ time wget
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=@-'
unalias <your_own_command> cancels an alias, -a removes all aliases
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
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 / fc !!
(executes the previous command)
$ fc -s 560 / fc !560
(executes the particular command)
clear clears the terminal screen
reset clears the terminal screen and sets its default values
exit / ctrl+d exits a shell (logs off a user)
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: 2019/03/21 18:08 by Miroslav Bernát