soledad penadés
repeat 4[fd 100 rt 90]

Ubuntu linux cheatsheet

Apache

htdocs folder
/var/www
apache configuration files
/etc/apache2/
vhosts definitions
/etc/apache2/sites-available
Create a link to each definition in /etc/apache2/sites-enabled: ln -s /etc/apache2/sites-enabled/mysite.lnk /etc/apache2/sites-available/mysite
Or with newer versions of Ubuntu: a2ensite mysite for enabling and a2dissite mysite for disabling
start/stop/restart apache
sudo /etc/init.d/apache2 start/restart/stop
Logs
/var/log/apache2

PHP

php ini
/etc/php5/apache2/php.ini
Sessions temp dir
/var/lib/php5
Pear and all of that stuff
/usr/share/php5

mysql

config file (my.cnf)
/etc/mysql/my.cnf
Delete tables with a certain pattern (drop tables like)
mysql –user=theuser –password=thepassword -N -e "show tables like 'whatever%'" db_name | perl -e 'while(<>){chomp; push @tables, $_;}print "drop table " . join ("," ,@tables) . "\n";' | mysql –user=theuser –password=thepassword db_name

Files

Find files which have been modified today
find . -mtime -1 -print
Find all backup files in a directory
find . -name *~ -print
Find all backup files and delete them!
find . -name "*~" -exec rm {} \;
Change permissions for all folders only
find . -type d -exec chmod g+x {} \;
Set the group id bit (so files created later in the folder belong ot the folder's group)
chmod g+s directory
Uncompress lots of zips with just one line of terminal commands
find *.zip -exec unzip {} \;
Find only files
find . -type f
Find only files … and delete them!
find . -type f -delete
Recursively find files which contain a given text
grep -lir "a given text" *
Available space in disk
df -h (in fact this return available space in each mount in the system)
Show differences between two files without taking into account whitespace (very useful when line returns and spaces/tabs are messing up normal diffs)
diff -w file1 file2

Backups

archive and compress a whole directory
tar cvfz archive.tar.gz dname
backup a database
mysqldump db_name –user=username –password=password > database_dump.sql
backup all databases
mysqldump -u username -p –all-databases >/tmp/databases.dump
All-in-one: get a remote database dump, compress it, download and uncompress in your local machine
ssh your_host "cd dumps_dir; mysqldump –user your_user –password=your_pass –host=db_host database_name | gzip > database_name.gz"
scp your_login@your_host:dumps_dir/database_name.gz ./sql/
gunzip ./sql/database_name.gz
Compress a file with zip
zip outputfile.zip file1 file2 file3… fileN
Download a remote directory to current directory
scp -rv yourlogin@yourhost:~/web/public_html .

Updates

Remove unused packages
sudo apt-get autoremove
Manually update greyed out entries in the update manager
Go to Synaptic Package Manager, order by the status column (i.e. the first one), select all the packages with a star (*) over a green background, and select "Mark for upload".
Distribution update
sudo apt-get dist-upgrade
sudo gksu "update-manager -c"
Crisis!! X server doesn't work after updating the distribution - boot in safe mode and run
sudo apt-get install –reinstall xserver-xorg
sudo dpkg -reconfigure xserver-xorg

System

Turn off
sudo shutdown
Reboot
sudo reboot
List mounted devices and disks and other info
sudo fdisk -l
Static file system information
/etc/fstab
Fcsk - boot from live CD (it won't allow you to fsck a mounted drive)
open a console with ctrl+alt+f1
then sudo fsck /dev/sdb, etc
Another option: sudo e2fsck -p -f -v /dev/sda
Force fsck on boot
sudo touch /forcefsck and reboot!

Xorg

Restart xorg
press ctrl+alt+backspace

Net stuff

Download a file with curl
curl -o outputfile source_url

Subversion

List info for a remote repository
svn info svn://repository_url (or http://repository_url, etc)
svn info also works with local resources: svn info . lists info for current directory
List files in a repository path
svn list svn://repository/path

VirtualBox

Recompiling kernel module after upgrading the kernel:
sudo aptitude install linux-headers-$(uname -r)
sudo /etc/init.d/vboxdrv setup
Some people suggest using "sudo aptitude install virtualbox-ose-modules-generic" which is "a metapackage". I haven't tested it.

PulseAudio

Stop and restart
pkill pulseaudio; pulseaudio &

PGP & co

Clearsign a file with a non-default key
gpg –default-key [KEYID] –clearsign [FILENAME]

// 8 responses to Ubuntu linux cheatsheet

Zarate
Zarate
20080820

Hi Sole!

Love your cheatsheet, i've used it 1000 times, thanks for that!

Anyway, it seems that in Ubuntu Hardy you need a different command to stop/start/restart Apache:

sudo /usr/sbin/apache2 -k stop/start/restart

If you try the commands you posted (that used to work, i know) you get something like this:

"apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName"

Cheers!

sole
sole
20080820

funny, I just updated the sheet a few days ago - and it was actually that section that I updated ;)

With your lines, I get the "apache2: bad user name ${APACHE_RUN_USER}" error.

What works is:

sudo /etc/init.d/apache2 start|stop|restart

crosvera
crosvera
20080825

you can use wget to download a file from inet.

$ wget -c http://file.from/inter.net

-c = resume, if you cancel the download, you can resume it with the same command.

saludos!

links for 2008-10-15 « LAN b4 Time
links for 2008-10-15 « LAN b4 Time
20081016

[...] Ubuntu linux cheatsheet - soledad penadés (tags: ubuntu cheatsheet linux) [...]

lobet
lobet
20081101

Sir,
i thank you for explanations about the 'find' and 'apt-get' command

have a good day.

sole
sole
20081102

Not Sir but maybe Miss in any case ;-)

It's great to see the sheet is helpful for someone else apart from me. This confirms I did well putting it here.

Feel free to leave a reply

Comments are moderated: Rude and offtopic ones are out!