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
|
|