On this page I have a collections of commands I use while administrating some of our linux servers.

Conventions used:
command line code: linux code
variable to be filled in: {#text}
Misc
lock accounts cat /etc/shadow | grep -v ':!!' | awk 'BEGIN { FS = ":" } { print "passwd " $1 " -l" }' | sort
unlock accounts cat /etc/shadow | grep ':!!' | awk 'BEGIN { FS = ":" } { print "passwd " $1 " -u" }' | sort
Short commands
date.time for cp files date +format "%y%m%d.%k%M%S"
disk usage
get the ten largest files (and directories) du -a {#directory.name} | sort -n -r | head -n 10
usage per folder du -ck {#directory.name} | sort -n
du -cm {#directory.name} | sort -n
get the ten largest files larger dan 2 Mb sort by size desc sudo find / -type f -size +2000k | xargs ls -lhSr
get the ten largest files find {#directory.name} -type f 2>/dev/null | sort -k 7 -r -n | head -10

find . -printf '%s %p\n'|sort -nr|head
get the ten largest files display with full info find {#directory.name} -type f -ls 2>/dev/null | sort -k 7 -r -n | head -10
get the ten largest files display with size info find {#directory.name} -type f | xargs ls -as | sort -f +0 -r -n| head -10
Find the ten largest files ignore files ending with .pak and .tar find . -type f -name "*[^.pak|.tar]" 2>/dev/null| xargs ls -s 2>/dev/null | sort -rn | awk '{size=$1/1024; printf("%dMb %s\n", size,$2);}' | head

Find files
ignore files ending with .pak and .tar
size > 2 Mb
older then 60 days
sudo find -type f -size +2000k -name "*[^.pak|.tar]" -mtime +60 | xargs ls -lhSr

Find files and display total size on disk find . -name "*.undo" -ls | awk '{total += $7} END {print total}'
searching
Ignore errors while processing instruction 2>/dev/null

e.g.
find / -name "test" 2>/dev/null supresses any permission denied errors/
Seek and Destroy
find all files with .log. in the name more then 21 days old and delet them. sudo find ./ -name '*.log.*' -mtime +21 -exec rm {} \;
Network ports and such
check listening ports netstat -an | grep -i LISTEN
viewing
View the last 50 lines of a file and follow
(when new lines are added they will be displayed)
tail -n50 -f {#file.name}
get all lines of a file containing some tekst (regex!) and put the output in another file grep "{#search_text}" {#file.name}> {#tartget_file.name}
line count wc -l {#file.name}
Display content of file with linenumbers starting at first occurrence of the {#search_text} less -N -p {#search_text} {#file.name}
File operations
Copy file keep permissions cp -p {#file.name} {#target_file.name}
search and replace in multiple files
perl -pi -w -e 's/search/replace/g;' *.php
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop
Directory commands
Put current dir on stack so you can popd back to it pushd .
pop last pushed directory from stack popd
Example:
this command changes the current directory to:
cd c:\fdos\bin c:\fdos\bin
pushd c:\games c:\games
pushd c:\utils c:\utils
popd c:\games
popd c:\fdos\bin

The Top command
The top command displays the running processes.

use "<" and ">" to change the sort column.
type P to sort on cpu%.
type M to sort on MEM%.
type m to display the memory status info.
type 1 to display info per cpu (multi cpu/core machines).
type c to display full program info.

Getting de hardware info
dmidecode info /usr/sbin/dmidecode
HD info /sbin/fdisk -l
sys/kernel info uname -a

vi /proc/version
mem info vi /proc/meminfo
processor info vi /proc/procinfo
grep -i "processor" /proc/cpuinfo | sort -u | wc -l
processor info fysiek aantal grep -i "physical id" /proc/cpuinfo | sort -u | wc -l
sys info dmesg | less
filsystems info df -h

Tarring
list files in tar tar -tzf filename.tar.gz
create tar from file list tar cfvz filenam.tar.gz `cat doc_containg_list_of_files.txt`
create tar tar cvzf filenam.tar.gz dir_to_tar/
tar cvzf filenam.tar.gz dir_to_tar/*.png
extract tar tar -xvzf filename.tar.gz

Shut the beep up
modprobe -r pcspkr

setterm -blength 0

In /etc/inputrc add or uncomment
set bell-style none

In Xfree or Xorg
xset b off
or xset -b

The chmod command VI text manipulation
See the chmod command See VI See grep, awt and sed