Ubuntu linux cheatsheet

E-mail Imprimir PDF

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

Restore a dump

mysql -u username -p databasename < dump.sql

It will ask you for that username password

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 to the folder’s group)

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

Get the md5 hash of a file

md5sum filename

Sharing folders

Right click over the folder to share, select ‘Sharing options’, click ‘Share this folder’ and ‘Allow other people to write in this folder’. For setting the samba user and password, open a terminal and run

sudo smbpasswd -a username

, where username is the username you’ll use when asked by Samba. The password you’ll set is the one you want to use for accessing that folder remotely. It does not need to be your system password. This way when you do changes in the folder, the changes are done by username, not by nobody.

Backups

archive and compress a whole directory

tarcvfz 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

sshyour_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

zipoutputfile.zip file1 file2 file3... fileN

Download a remote directory to current directory

scp-rv  yourlogin@yourhost:~/web/public_html .

Archive a directory in several files of 1Gb each

tarvcf - /path/to/dir | split --bytes=1024m -a 3 -d - output_prefix

And to join them and unarchive at the same time:

cat/path/to/archived_files/output_prefix* | tar xvf

Mounting internal drives

Let’s say I want to create a mount point for a secondary backup disk, so that it is always mounted without having to do it manually each time I want to use it.

Find out name of disk/partition

sudo fdisk -l

For example, /dev/sdb1 is the partition I want to mount. It can be different for you

Create mounting point

sudo mkdir /backup

Find UUID of the partition to mount

sudo vol_id /dev/sdb1

It returns both the filesystem type (ext3 in this case) and the UUID:

ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=4ae128f5-b8a5-46ca-a27b-ddc03af18171

Edit /etc/fstab file to include the new partition in the list of mounts

Add a line like UUID={UUID} /{mount_point} {fs_type} defaults 0 0. Inmy case:

UUID=4ae128f5-b8a5-46ca-a27b-ddc03af18171 /backup ext3 defaults 0 2

Note that the last ’2′ is for telling fsck that it should check this disk after it checked the first one (which is the root one and should have an ’1′ instead of ’2′). If you enter a ’0′ this partition will never be checked when starting the system; that’s probably not a good idea.

Did we do it right? Try to refresh the mounts with this:

sudo mount -a

If there are no errors, you should be able to access the new mount point with the File Browser. If you get something like mount: special device 4ae128f5-b8a5-46ca-a27b-ddc03af18171 does not exist you probably forgot to add UUID= before the actual UUID, like I did :D

Give proper permissions – normal users can’t write in the new mount because it belongs to root.

In my case:

sudo chown -R sole:sole /backup
sudo chmod -R 755 /backup

These can take a long time — specially if there are lots of files in the disk and it is large :)

Note: mostly taken from this fab tutorial

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!

Change screen resolution using command line

xrandr -s new_widthxnew_height

example: xrandr -s 1920×1200

Xorg

Restart xorg

press ctrl+alt+backspace

Net stuff

Download a file with curl

curl -o outputfile source_url

Mirror a website with wget

wget -m http://example.com

Or wget -H -r –level=2 -k -p http://examples.com to download files up to 2 levels recursively

Simulate different bandwidth speeds for testing your site (aka Bandwidth Throttling)

trickle -u 10 -d 20 firefox

Thanks to mr.doobfor this one!

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

Relocate a server location

svn switch –relocate svn://svnserver svn://svnserver/yellow_dog (taken from here)

Fire up svn server daemon

svnserve -d -r /home/svn/path_to_repositories_root

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

Clearsigna file with a non-default key

gpg –default-key [KEYID] –clearsign [FILENAME]

Última atualização ( Seg, 09 de Maio de 2011 21:18 )  

Adicionar comentário


Código de segurança
Atualizar

sideBar



Arquivo

mod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_countermod_vvisit_counter
mod_vvisit_counterHoje7
mod_vvisit_counterOntem362
mod_vvisit_counterSemana7
mod_vvisit_counterSemana Anterior2990
mod_vvisit_counterMês4071
mod_vvisit_counterMês Anterior578
mod_vvisit_counterTotal181134

We have: 4 guests, 1 bots online
Seu IP: 38.107.179.240
 , 
Agora: Mai 21, 2012 Mai
Membros : 17
Conteúdo : 155
Visualizações de Conteúdo : 37878



 

Qual distro você usa?
 




Firefox




Joomla Clube

Joomla Brasil

Info Wester

IdgNow

BrLinux.org

Joomla Brasislia

Joomla.org

F13 -Tecnologia

Dicas Linux

Olhar Digital

Joomla Facil

Linux Security

Debian.org

Viva o Linux

Ubuntu-BR