Академический Документы
Профессиональный Документы
Культура Документы
Below you will find several tips and tricks I have accumulated over the years which will make your life
as a Linux sysadmin hopefully a bit easier. I hope that both experienced as well as novice Linux users
will find these tips useful.
If you type “!cd” it will append the last command which included cd. Example “cd /home/user”.
Using “Alt and .”. If you press “Alt + .” it will cycle through the last part of the command. Another
way of doing this is using the “!$” but then it will only use the last part and will not let you cycle
through the commands you have already entered. Give it a try by doing a “ls /home/username” and then
either “cd !$” or “cd Alt+.”. If you type `cd -` you will go back to you last position. Ex. /home/me to cd
/usr, cd – will let you go back to /home/me!
If you use !* instead of !$ it will complete everything after say “vi bla bla2″, so everything after vi.
Removing characters from a command. Say you have mistyped the command, ex rm blaa instead of rm
bla. Press “^a” and it will come back with “rm bla”.
If you go to directories of want to finish command you type press on the tab key to complete the
command or location. Pressing it multiple times will let you cycle through the commands/directories.
Reverse search – if you type “Ctrl + r” you can type in the first few keystrokes of a command to find it
in your history.
cp source target – copy file from source to target ex. cp test /home/me (copy test to /home/me dir)
mv source target – move or rename file
ln -s target linkname – ex. ln -s /home/me/test test2 -> link to /home/me/test and call link link2.
-s is symbolic link – removing the link doesn’t remove the original file – without -s is hardlink –
removing the link will also remove the original file!! Be careful.
script filename – lets you record commands till you press Ctrl-D or type exit.
mounting directories and servers
If you want to unmount a device which is currently in use you can find out about the processes which
are using this device by issuing a “lsof /mountpoint”. You can also issue the command lsof -n | grep
“mountpoint” to achieve the same result. If a disk refuses to be umounted issue the command umount -l
“mountpoint”.
mount -o loop iso /mountpoint – mounts the iso at mountpoint (you can check its content)
http://kerneltrap.org/node/14148
host domain (ex. host domain.com) – in newer host program shows MX records (Mail Exchanger
records)
Getting help!
Man pages – if you type “man command” it will tell you more about the command and the possible
switches. Or you can type either `–help`or `-h` behind the command to learn more about their
operators.
Related command’s in someway can be found by typing “apropos command”.
Gnome
Switching workspaces – Crtl-Alt-Right/Left of you can use your scrollmouse by pointing the mouse
pointer on the workspace switcher and scroll.
Suddenly no sound after installing/deinstalling programs? I experienced this in Ubuntu – open the
volume control and crank up all the sliders.
rehash – after you installed new software. Users who were allready logged in can use this command to
reread the available commands.
compiz – F12 shows you all the programs that you have opened in one screen. its called “scaled” now
in gutsy.
Adding more view ports – general options > desktop size (tab) > “horizontal Virtual Size”. Use slider to
add viewports.
Deskbar applet – Select text and press Alt-F3 -> deskbar applets searches for text.
Fixing problems – like no audacious window but running process. remove or move .config/audacious.
Gaim
crtl – (arrow up/down) scroll though previous posts…
uncheck http connection method when you get connection errors.
Xgl
Shift backspace restarts the current Xgl session – this is very annoying. Add the following line to
you .Xmodmap:
keycode 22 = Backspace Backspace
This fixed the problem for me.
Kernel
Both the cron the atd are daemons for executing commands/programs at certain intervals. The atd
daemon is used for single events while the cron daemon is used for repeated events (like updating the
locate database).
Usage cron.
crontab -e – edit the cronfile from the current user
crontab -l – list the crontab
Stanza
Minute Hour Day of the month Month Day of the week command
00 04 01 * * ls -> this will run every first of the month at 4 in the morning the command ls.
Usage at
atq – view all current commands in queue
at “time” – start new command ex. at 14:00 (start new at 14:00)
afther that enter the command(s) you wish to be executed end with Ctrl-D.
Powertools
find – command to find files. Examples: find . -size +1000k -exec rm -f {} \; (find and remove all files
bigger than 1000 kilobytes recursive in this directory and below)
find . -name ‘*.gz’ – find all files with the .gz extension.
find . -ctime -30 -print | xargs tar -cf backup.tar – find all files which changed in the last 30 days and
add them to backup.tar
find . -ctime -1 -type f | xargs tar -rvf backup.tar – all files changed within 24 hours backup to
backup.tar.
find /tmp/ivan/* -mtime +7 -exec /bin/rm -rf {} \; 2>/dev/null 1>&2 (find all files changes 7 days ago
and remove them -> stout to bitbucket) – better find . -mtime +7 -type f | xargs rm 2>&1 /dev/null –
outputs both stout and stdin to /dev/null
find all directories without permissions 0775 and change permissions in 0775 from current directory.
Without the ! it will search for directories with permissions 0775.
wget -H -r (-r is recursive -H means spans hosts – other wise it will only download from the host you
gave)
awk ‘{split($0,a,”/”); print a[2]}’ – split all occurences of strings with an “/” in them and print out third
array variable.
ps axu | awk ‘{print $11}’ – print all the programnames that are running..
Calculate totals from number of rows (in this case a ms exchange log file).
awk ‘{total +=$15};END {print “Total: “total”"}’ 20060707.log
scp `find . -ctime -1` host: – copy all changed file within the hour to host via scp.
Loops
while loop – ex. renaming all files with an ? in the filename to an filename with a dot in it.
remove all empty lines and lines with comments with sed (alleen tonen niet daadwerkelijk weghalen)
sed ‘/ *#/d; /^ *$/d’
for loop
for ((i=0;i<10;i++)); do
echo $i
done
instead of using:
ls >> file
pwd >> file
use curly braces to execute the commands and then direct output to the file like:
{
ls
pwd
} > file
mv `grep -l “bla” *` dir/
The -L switch tells rsync to treat your symlinks as though they were real directories.
incase it doent exist like with the gutsy live cdrom – just install apt-get install lvm2 (make sure you
configure your network).
modprobe lvm
modprobe dm-mod
it could be that your lvm volume name is different so change VolGroup00 into whatever it is…
/dev/volumename.
To change items in the different runlevels you can use these utilities:
chkconfig – Redhat systems
update-rc.d – Debian based systems
service stop apache2 – stop service/daemon apache2
service start apache2 – start apache2
service restart apache2 – restart daemon apache2
See also:
enable services
or
services debian
email
setting up vacation
Hi!
I’m on vacation from January 1st until the 1st of March 2007.
Regards,
User
step 4: finishing
vacation -I
Turning vacation off is easy just rename the .forward file to .forward.unused.
spamassassin
spamassassin -t < email.txt – test email on spam (for debugging purposes)
vsftpd
vsftpd is a very secure ftp daemon ( http://vsftpd.beasts.org ). How to allow only certain local users to
log in to ftp.
If you install it for the first time under etch it will allow for anonymous login. Change thefollowing
values:
anonymous_enable=NO # disable anonymous access
local_enable=YES # enable local user access
LDAP
making ldap listening on a certain ip adress. Change the line in /etc/defaults/slapd
SLAPD_SERVICES=”ldap://10.10.10.10:389/ ” -> example.
Samba
In case you get error 6, permission denied. Check if the user is part of the group and the proper
permissions are set on the base directory. Change to 775.
MySQL
my.cnf/ini – if you have problems with insering special characters in MySQL via php – turn off the
option “default-character-set=utf-8″.
max_allowed_packet in my.ini – set this to 32M so that the import doesn’t fail.
SSH
setting up vnc connection via ssh.
create ssh tunnel to remote machine
ssh -f -N -L 5901:localhost:5901 -X username@remotebox.example.com
vncviewer localhost:5901 (open vnc connection)
Tunnel to remote website on ibnside of network – connect to host 192.168.1.100 on port 80. IN
browser type localhost:8080.
ssh -N -f -L 8080:192.168.1.100:80 remoteip
ex. ssh – also interesting if firewall blocks certain ports on remote host.
usage of screen
All commands start with CTRL-A, then another key for the command itself. If you really want to send
a CTRL-A to your application (Like to go to the beginning of the current line in bash for example, hit
CTRL-A twice.)
DHCP
dhclient3 -1 eth0 – renew ip adrress on eth0 (change eth0 into whatever your interface is)
dhclient -r eth0 – release ip adress
ifdown eth0 – bring interface eth0 down
ifup eth0 – bring eth0 up – if it is configured as dhcp interface it will automatically restart dhcp
settings.
Hardware
The smartmontools is a program to test your harddrives. Below are some examples to test your
harddrive for possible errors:
smartctl -t short /dev/hda – short online test while your system is running.
smartctl -t long /dev/hda – longer better test of your harddrive (you can do this monthly and the above
weekly to test your harddrive integrity).
To view the results enter the following command:
smartctl -l selftest /dev/hda
Virtualbox – install guest additions to improve performance. Press Hostkey-f if you are in full screen
mode and use the menu Devices > install guest additions to download and install the latest guest
additions.
Fixes
http://en.wikibooks.org/wiki/Linux_Guide/Freezes
Kill X
Ctrl-Alt-Backspace
Alt+SysRq+K – if keyboard doesn’t respond.
If remote reboot doesn’t work due to failing harddrive you can reboot through the proc system. If you
enabled CONFIG_MAGIC_SYSRQ with the kernel compilation.
When you are ready to reboot the machine simply run the following:
This does not attempt to unmount or sync filesystems, so it should only be used when absolutely
necessary, but if your drive is already failing then that may not be a concern.
Also, instead of echoing into /proc/sys/kernel/sysrq each time you can activate the magic SysRq key at
system boot time using sysctl, where supported:
If you have tips which are not mentioned here and worth mentioning please drop me a email at kim at
daudretsch.com.
Hacks
wget -O – -q http://ip.boa.nu/ – get your external ip