Linux General
The grep -w
command form matches whole
words only. The -r
option searches subdirectories.
For example to find all the files under /etc
that contain the current hostname:
$ grep -rwi $(hostname) /etc
To copy all files from /source directory to /dest directory use the following commands:
# cd /source # find . -xdev | cpio -pduvlm /dest # cd /source # find . -type d -exec chmod --reference='{}' /dest/'{}' \; # find . -type d -exec chown --reference='{}' /dest/'{}' \;
The shred
command can be used to securely
erase a file by overwriting it multiple times with random bit
patterns before deleting it.
strace
is the Linux equivalent of
truss
, i.e., a diagnostic and debugging tool for
tracing system calls and signals. The simplest way of invoking it
is:
# strace command
Adding an appropriate entry to /etc/logrotate.conf makes it possible to manage personal log files, as well as system-wide ones.
tac
is the inverse of cat
,
listing a file backwards from its end. rev
reverses
each line of a file and outputs to stdout; this is not the same
effect as tac
, as it preserves the order of the lines,
but flips each one around.
The pidof
command identifies the process ID
(PID) of a running process. For example,
$ pidof cron
will return the process ID of cron daemon.
dumpe2fs
dumps to stdout very
verbose filesystem information. For example, run
# /sbin/dumpe2fs /dev/hda1
Note that, dumpe2fs
resides under the /sbin
directory.
To display all kernel parameters execute
# /sbin/sysctl -a
To make kernel parameter changes (permanently) edit /etc/sysctl.conf file.
For hardware information use
# lspci -vv
and
# lsusb -tv
To see your ethernet interface speed use a command like
# mii-tool -v eth0
Important system information can be obtained from the “files” under /proc/ directory. For example enter
$ cat /proc/meminfo
for current memory usage information; or
$ cat /proc/swaps
for a list of swap devices. As another example, the file
/proc/bus/usb/devices contains information about the
USB ports on the system. For example, Spd=12
indicates
USB 1.1 ports, while Spd=480
indicates USB 2.0
ports.
Disk information can be obtained with
# fdisk -l
To get hardware disk information try the commands:
# smartctl -a /dev/hda # hdparm -iv /dev/hda
To check service status use
# service --status-all
To restart a service (for example, xinetd) enter
# service xinetd restart