> nmap -sV -n -v -P0 -p21 target_host_ip> netstat -tulpen
ethX with the appropriate interface, and aaa.bbb.ccc.nnn with the desired host ip address ) :> ifconfig ethX aaa.bbb.ccc.nnn netmask 255.255.255.0 upaaa.bbb.ccc.ddd with the ip address of the default gateway ) :> route add default gw aaa.bbb.ccc.dddrrr.sss.ttt.uuu with the address of a valid nameserver ) :> echo "nameserver rrr.sss.ttt.uuu" | tee /etc/resolv.conf > /dev/null
host1234 and the name of the superuser entered during installation is sume ( a play with words for want of a better idea as an example name: assume or superuser + me )sume :
host1234 login: sume
|
Enter the name of the superuser here, then press Enter . |
Password:
|
Enter the superuser's password here, then press Enter . Note: the typed in password will not be displayed on screen! |
sume@host1234:~$
|
The initial prompt will be similar to this. Remember: the standard linux prompt of the root user ends with # , all others have $ at the end. |
sume@host1234:~$ sudo passwd
|
Enter |
[sudo] password for sume:
|
To ensure authorization for creating a root password enter the superuser password here, then press Enter . |
[sudo] password for UNIX:
|
Enter the new password for root here, then press Enter . |
[sudo] repeat password for UNIX:
|
To avoid typing errors reenter the new password for root here, then press Enter . |
|
Note: the typed in passwords will not be displayed on screen! |
... success message ...
host_name login: user_x
|
Enter the name of the user here, then press Enter . |
Password:
|
Enter the user's password here, then press Enter . Note: the typed in password will not be displayed on screen! |
user_x@host_name:~$
|
The initial prompt will be similar to this. Remember: the standard linux prompt of the root user ends with # , all others have $ at the end. |
host_name login: root
|
Enter the user name root here, then press Enter . |
Password:
|
Enter the password of the user root here, then press Enter . Note: the typed in password will not be displayed on screen! |
root@host_name:~#
|
The prompt will be similar to this. Remember: the standard linux prompt of the root user ends with # . |
user_x@host_name:~$ exitroot@host_name:~# exit
> su user_x> whoami> uname -r> cat /proc/version> lsb_release -a or --all> lsb_release -i or --id> lsb_release -d or --description> lsb_release -r or --release> lsb_release -c or --codename> cat /etc/lsb-release> cat /etc/issue> cat /etc/motd (might link to /var/run/motd)> cat /etc/motd.tail > cat /var/run/motd (regenerated on every boot from /etc/motd.tail - if this exists, otherwise (?)) (might link to /run/motd)> cat /run/motd > cat /proc/cpuinfo> volname
> ps
|
list of running tasks under current user or with options for all users - e.g. ps -elFy |
> pstree
|
"tree" of running processes |
> top
|
active list of running tasks and some system info - quit with q |
> users
|
list of logged in users |
> w
|
list of logged in users and on which terminal |
> who
|
list of logged in users and on which terminal (not so informative as w) |
> last
|
list of recently logged in users with times etc |
> lsof
|
Lists all opened files |
> lsof | grep somepattern
|
Lists all opened files whose path/name contains the given pattern |
> du -sh /path/to/folder> du -h --max-depth=1 /path/to/folder Will produce a list of all the folders in /path/to/folder and their sizes.> du --max-depth=1 /path/to/folder | sort -nk1 will organize the list from smallest to largest. ( by Marco Ceppi: http://askubuntu.com/users/41/marco-ceppi )
> df
> df -h
|
to get the sizes in "human readable" form, e.g. get 140M instead of 143260; sizes are in KiB, MiB, GiB etc., i.e. using powers of 1024 |
> df -H
|
same as the option -h , but sizes are in KB, MB, GB etc., i.e. using powers of 1000 |
> df --total
|
output grand total of disk space used / available at end of list |
> tput colors
> echo $?
> tar xzfv somefile.tar.gz : Unpack a *.tar.gz file> gzip -dc somearchive.tar.gz | tar xfv -> bzip2 somefile1> bunzip2 somearchive.bz2> tar cfvj somearchive.tar.bz2 [somedirectory1] [somedirectory2] [somefile1] [somefile2] ...> tar xfvj somearchive.tar.bz2> zip somearchive.zip [somefile1] [somefile2] ...> zip -r somearchive.zip [somedirectory1] [somedirectory2] ...> unzip -l somearchive.zip (list archive)> unzip somearchive.zip> cat listoffiles.txt | xargs tar -czvf yourbackupname.tgz> tar -czvf yourbackupname.tgz $(cat listoffiles.txt)> find / -type d -name log\* | egrep "log(s|ging)?$" | xargs tar -czvf backup_logs_`date "+%Y%m%d-%H%M%S"`.tar.gzbackup_logs_20121210-094512.tar.gz, using the current date and time. The date command, together with all its options and arguments, needs to be bracketed in ` ` ( accent graves ). The date format used may not contain any characters which cannot be used in a linux file name!
> sed -i 's/<some_string>/<new_string>' /path_to_file/file_name> find some_path -type f -exec sed -i 's/some_string/new_string/g' {} \;-type f ) in some_path and all its subdirectories recursively, and replace all found occurrences of some_string with new_string !/icon with icon in all files in the current folder which end in .html ( note that the special character / contained in the first string /icon has to be "escaped" using \ ):> find . -maxdepth 1 -iname "*.html" -exec sed -i -e "s/\/icon/icon/g" {} \;my-example-site.com with <a href="http://my-example-site.com/">my-example-site.com</a> in all files in the current folder which end in .html ( note that some special characters have to be "escaped" using \ ):> find . -maxdepth 1 -iname "*.html" -exec sed -i -e "s/my-example-site\.com/\<a href=\"http\:\/\/my-example-site\.com\/\"\>my-example-site\.com\<\/a\>/g" {} \;
> grep "some_string" *
|
search all (non-hidden) files in current directory and output all lines found containing some_string |
> grep "some_string" .*
|
search all hidden files ( those beginning with a period ) |
> grep "some_string" * .*
|
search both visible and hidden files |
> grep -r "some_string" *
|
search also in subdirectories recursively |
> grep -i "some_string" *
|
ignore case |
> grep -l "some_string" *
|
only list the names of files containing some_string |
-l )/somedir/ * .* )-r ). and .. by adding --exclude-dir="." and --exclude-dir=".." - this is necessary because of the .* file / directory parameter!> grep -lr --exclude-dir="." --exclude-dir=".." "somestring" /somedir/* /somedir/.*
> apt-get update> apt-get upgrade> apt-get dist-upgrade -u> aptitude full-upgrade> apt-cache search linux-headers-$(uname -r)> apt-get install linux-headers-$(uname -r)> apt-get autoremove> do-release-upgrade
Prompt=lts> rm /var/lib/update-notifier/release-upgrade-available
> dpkg -l linux-* | awk '/^ii/{ print $2 }' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e [0-9] | grep -v '\(\-37\)\|\(\-39\)' | xargs apt-get --dry-run purge
#! /bin/bash
# Copyleft 2013-03-27 17:11+0100 We by me ( adapted from the above mentioned sources )
# get the current kernel version
currentKernel=`uname -r`
# set the minimum number of kernels that should be kept on the system
minNumberOfKernels=3
echo
echo "Script for removing the oldest installed kernel package(s)"
echo
echo "Currently running: $currentKernel"
echo
echo "The following kernel images exist in /boot :"
ls /boot | grep vmlinuz | cut -d'-' -f2,3
echo
# get the total number of installed kernels
numberOfKernels=`ls /boot | grep vmlinuz | wc -l`
echo "Number of installed kernels: $numberOfKernels"
echo
# if the number of installed kernels is greater than minimum number of kernels (set above), then do the following:
if [ $numberOfKernels -gt $minNumberOfKernels ]; then
# get list of installed kernels and choose the first entry
oldestKernel=`ls /boot | grep vmlinuz | cut -d'-' -f2,3 | head -1`
# get list of kernel package(s) to be removed
removeKernelPackages=`dpkg -l linux-* | awk '/^ii/ { print $2 }' | grep $oldestKernel`
# if the variable oldestKernel is not equal to the variable currentKernel then do the following:
if [ $oldestKernel != $currentKernel ]; then
echo "Do you want to remove the following old kernel package(s):"
echo ">>"
echo "$removeKernelPackages"
echo "<<"
echo
# read exactly 1 char into variable yn and continue
read -s -n 1 -p "Y/N:" yn
echo
case $yn in
# if yn has the value Y or y then do the following:
[Yy]* )
echo "Removing the kernel package(s)"
echo ">>"
echo "$removeKernelPackages"
echo "<<"
echo
echo "$removeKernelPackages" | xargs apt-get -y purge
;;
# if yn has any other value than Y or y, then give the following error message before exiting the script:
* )
echo "The kernel package(s)"
echo ">>"
echo "$removeKernelPackages"
echo "<<"
echo "were not removed!"
echo
;;
esac
# else if oldestKernel is the same as currentKernel then give the following error message before exiting script:
else
echo "The current (running) kernel package(s)"
echo ">>"
echo "$removeKernelPackages"
echo "<<"
echo "will not be removed, as this would destroy the system!"
echo
fi
# else if number of installed kernels is equal to or less than minimum number of kernels (set above) then give the following error message before exiting script:
else
echo "This script will only offer removal of kernel package(s), if the number of installed kernels is greater than $minNumberOfKernels!"
fi
> add-apt-repository> apt-get install python-software-properties> add-apt-repository ppa:PPA-PROVIDER/PPA-NAME> apt-get update> apt-get install PACKET-NAME
> add-apt-repository ppa:brandonsnider/cdrtools> apt-get update> apt-get install > mount --bind /path/to/some/dir /otherhd/path/to/some/other/dir> ln -s /path/to/some/dir /otherhd/path/to/some/other/dir
:set numberwidth=6
|
Width / columns reserved for line numbers. |
:set number
|
Switch on numbering for lines. Switch off line numbering with :set nonumber
|
:set nowrap
|
Text will not be wrapped at screen width. By default text will be wrapped. |
:set tabstop=4
|
Tabstop width. |
:set autoindent
|
Switch on auto-indenting. Switch off auto-indenting with :set noautoindent
|
| Esc | exit any of the following modes ( INSERT / REPLACE / VISUAL / COMMAND ) |
| Ins |
toggle insert / replace ( overwrite ) mode ( shows -- INSERT -- or -- REPLACE -- at bottom left )
|
| v |
enter visual mode for marking text ( shows -- VISUAL -- at bottom left )
|
| Shift V |
enter visual mode for marking whole lines ( shows -- VISUAL LINE -- at bottom left )
|
| y | yank ( copy ) marked text to clipboard |
| p | paste clipboard content after cursor |
| Shift P | paste clipboard content before cursor |
| : |
enter command mode ( shows : at bottom left )
|
:w
|
write to file ( save ) |
:wq
|
write to file ( save ) and quit vim |
:q
|
quit vim |
:q!
|
force quitting vim ( without saving ) |
:set all
|
show list of set options |
:/xyz
|
search for string "xyz" |
| n | search for next occurance of string "xyz" |
| Shift N | search for previous occurance of string "xyz" |
:%s/xyz/abc/gcI
|
search for occurances of string "xyz" and replace with string "abc" Options: % = all lines, g = global = all occurances in a line, c = ask for confirmation, I = ignore case, i = don't ignore case |
:e ~/transfer.text:wGRUB_CMDLINE_LINE="consoleblank=0 vga=0x316"> update-grub> setterm -blank 0> setterm -powersave offGRUB_HIDDEN_TIMEOUT=GRUB_TIMEOUT=8> update-grub
| Colors \ Size | 640x480 | 800x600 | 1024x768 | 1280x1024 |
|---|---|---|---|---|
| 256 | 0x301 | 0x303 | 0x305 | 0x307 |
| 32k | 0x310 | 0x313 | 0x316 | 0x319 |
| 64k | 0x311 | 0x314 | 0x317 | 0x31A |
| 16M | 0x312 | 0x315 | 0x318 | 0x31B |
GRUB_CMDLINE_LINE="consoleblank=0 vga=0x316"> update-grub
> ps aux | awk '{ print $8 " " $2 }' | grep -w Z> mount -t vboxsf share mountpoint (didn't find)> apt-get install virtualbox> shutdown -P now : -P = power off> init 0 : enter runlevel 0 (switch off) (pros / cons?)> shutdown -r now : -r = reboot / restart> ufw disable : Disable firewall> ufw enable : Enable firewall> apt-get install openssh-client openssh-serverscp :> scp [[user@]hostname.domain.tld:]file1ssh :> ssh [user@]hostname.domain.tld [command] ( using DNS of remote machine )> ssh [user@]nnn.nnn.nnn.nnn [command] ( using IP address of remote machine )> apt-get install sshfs> sshfs [user@]hostname.domain.tld:[dir] mountpoint> sshfs root@x1234567.xyzserver.net:/ /media/xyzremote ( mount root directory of remote machine: / = root directory )> sshfs root@x1234567.xyzserver.net:/var/www /media/xyzremote ( mount directory /var/www of remote machine )
> echo -e '\017'> reset> stty sane
> cat /etc/timezone> dpkg-reconfigure tzdata> service cron restart> /etc/init.d/cron stop> /etc/init.d/cron start> stop cron> start cron
ntpdate as standard, and will run it once at boot time to set up the host's time using Ubuntu's NTP server. However, a server's clock is likely to drift considerably between reboots, so it makes sense to correct the time occasionally. The easiest way to do this is to get cron to run ntpdate every day./etc/cron.daily/ntpdate containing the following line:ntpdate ntp.ubuntu.com> chmod 755 /etc/cron.daily/ntpdate> xxx> xxx
> apache2 -v> apache2ctl status | grep Version> apache2ctl status> apache2ctl -l> apache2 -l> apache2ctl -M> apache2ctl -t -D DUMP_MODULES
> a2enmod/usr/lib/apache2/modules/ and can therefore also be listed using ls :> ls /usr/lib/apache2/modules/
> a2enmod module_name
> a2enmod dav* ( Added here from description but not tested! )> service apache2 restart
> a2dismod> a2dismod module_name
> a2dismod dav* ( Added here from description but not tested! )> service apache2 restart
> apache2ctl -M> a2enmod dav> a2enmod dav_fs> service apache2 restartmy-example-site.com. On this site, WebDAV is to be activated for a subdirectory called "share".> cd /var/www/vhosts/my-example-site.com/httpdocs/> makedir share> chown -R www-data:www-data /var/www/vhosts/my-example-site.com/httpdocs/share /var/www/vhosts/my-example-site.com/conf/vhost.conf ( if the file vhost.conf doesn't exist, then it needs to be created ), and add the following lines:
<Directory /var/www/vhosts/my-example-site.com/httpdocs/share>
DAV on
</Directory>
my-example-site.com/httpdocs part needs to be replaced with the correct path!> /usr/local/psa/admin/sbin/websrvmng -a ( obsolate - use httpdmng instead )> /usr/local/psa/admin/sbin/httpdmng --reconfigure-allhttps://my-example-site.com ). If all went well, a requester for username and password will open, and after the correct entries the WebDAV-directory will be available under the chosen drive letter.
this script . > symbol has been used as an alias! Remember: the standard linux prompt of the root user ends with # , all others have $ at the end.