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
start/stop/restart apache
sudo /etc/init.d/apache2 start/restart/stop
Logs
/var/log/apache2

PHP

php ini
/etc/php5/apache2/php.ini
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)

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

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

// 5 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!

Feel free to leave a reply

Comments are moderated: Rude and offtopic ones are out!