linux

Finding files in Linux/Mac Terminal

Finding files is a little different to MS DOS!

find <startlocation> <type> <filename> <exec>

The exec is a simple way of performing functions on the results. If you leave it off, the find doesn’t really do anything.

So, the simplest thing to do is find a file, so the exec becomes the output:

find / -name wkhtmltopdf* -exec ls -ls {} \;

That will find all files starting with wkhtmltopdf starting from / and the function to run on it is ls -ls {} \;

The {} will be replaced with the search result, so, in essence, ls -ls filename; will show you the details about the file which is what I want, as I am looking for all copies of the wkhtmltopdf toolkit on the server.

You can obviously change the exec to delete the files, or copy/move them, or interrogate further…

Get MAC address from IP address

Had a routing issue the other day, and I was remotely trying to forward a port to a device. I didn’t know the MAC address of the device, and my Home Hub was insisting on that information for the forward destination. I knew the IP address, so there is a simple Windows command to get the MAC address from the IP address:

arp -a <ip_address>

I.e.

arp -a 192.168.1.70

Easy. This command works in Windows as well as Linux! Well theres a thing… It also works in Mac, but you drop the -a parameter:

arp 192.168.1.70

Getting wkhtmltopdf working on Linux

I’ve had a few troubles getting this running, and thought I would document it here.

First of all get the static binaries from the wkhtmltopdf site

And then install the following packages: (either through yum or aptitude)

  • libXrender
  • libXext
  • xz
  • openssl-devel
  • glibc
  • glibc-common
  • ld-linux.so.2
  • urw-fonts
  • libfontconfig.so.1
  • libz.so.1
  • libXext.so.6
  • libstdc++.so.6

Now, I have done this before, in Ubuntu and not hd to install the .so.x files but Centos 6 required that I did so… Annoying, and head scratching…

 

Read the last x lines of a log file

If like me you need to check out the PHP error log, but its bloody massive, you might want to take the last few lines of it.

tail -x log_file > new_log

That will take the last x number of lines from log_file and save into new_log

tail -10000 /var/log/httpd/error_log > ~/short_error_log

The above example will take the last 10,000 lines of the Apache error log, and save it into a new file ‘short_error_log’ in your home folder.

Compress files and folders in tar (Linux)

GZIP and TAR are two different utilities bound by the same cause. Compressing files and making file catalogs.

To compress a file, simply gzip it:

$> gzip database_dump.sql

That will compress the database_dump.sql file, and rename it to database_dump.sql.gz. Easy, and to uncompress it:

$> gunzip database_dump.sql.gz

That will restore the uncompressed version and rename to file back to .sql

But, what if you want to do more than one, or a folder. GZIP is not the tool, however it is used.

You need to TAR the files (which creates one file with the specified files in) and then gzip it:

$> tar -cvzpf compressed_file.tgz foldername

That will compress all files in the foldername folder into a file specified, and it will GZIP it for you.

If you want to just compress a few files, then instead of using the foldername have a list of the files separated by space

$> tar -cvzpf compressed_files.tgz file1 file2 file3

Easy, so to unTar them:

$> tar -zxvf compressed_file.tgz

The above will extract the files to the current folder, if you want them somewhere else:

$> tar -C /foldername -zxvf compressed_file.tgz

The above will extract the files to the /foldername folder.

Hope that helps a little.

 

Hamster – time tracking on Linux

This application is awesome. I love it. Its a really easy to use but comprehensive time tracker. If you’re always flicking between tasks and you can never keep up with what you have been up to in the day, this is the app you need. It runs on Linux so Windows users, you’ll have to find something else unless you can work out some sort of Python craziness runtime configuration.

And I just found out that you can add it to the panels in gnome now too (for quick access), which has prompted me to quickly blog about it so I don’t lose it (I’m about to switch to Mac)

 

 

http://projecthamster.wordpress.com/

 

Installing Skype on Centos 6

Taken from http://linuxinternetworks.com/applications/how-to-install-skype-on-centos6-rhel6/

Run update and install wget

yum update
yum install wget

Install the dependencies and download the skype for enterprise linux

yum install libXi.so.6 libXss.so.1 libasound.so.2 libXv.so.1 libSM.so.6 libXrender.so.
wget http://download.skype.com/linux/skype-2.2.0.35-fedora.i586.rpm
yum localinstall --nogpgcheck ./skype-*.rpm

Sometimes skype will not start, the only solution to start the skype is replacing the /usr/bin/skype with the download static skype:

wget http://download.skype.com/linux/skype_static-2.2.0.35.tar.bz2
tar xvf skype_static-x.x.x.x.tar.bz2
cp skype_static-2.2.0.35/skype /usr/bin/skype
cp: overwrite '/usr/bin/skype' ? Y

Now its clear. You can access the skype from Applicaions -> Internet -> Skype or type skype in your terminal.

How to transfer files over SSH/SCP

I often forget the syntax for getting files over a SSH connection.

scp user@address:/path/to/file /path/of/new/file

For example:

scp root@domain.com:/tmp/mysql/test.sql .

Will transfer test.sql to the current folder (.) Also, if you need to change the port, just use the -P option

scp -P 9000 user@address:/path/to/file .

If you want to transfer a file TO another server:

scp /path/of/file user@address:/path/to/new/location

 

How to install MySQL Server on Centos

To install MySQL on Centos is a little different from Ubuntu – as I found out. Obviously APT is replaced with yum on this flavour of Linux, but not only that, yum doesn’t appear to set it up for you after installing it (with root account, etc).

Step 1, Install MySQL

> yum install mysql-server mysql

This will download the files and install them in the correct folders, as apptitude would. Step 2 shows you how to prepare the MySQL service.

Step 2, Configure the service

Tell the system to start the MySQL Daemon upon startup:

chkconfig --levels 235 mysqld on
service mysqld start

Now MySQL is installed and running, but the root account will have no password, so we need to ensure there is a strong one. (Or not if you are a crazy one) – You will get some message when the service starts for the first time related to security measures, I would suggest you do read it.

Step 3, Set up Root user

> mysql -u root
> SET PASSWORD FOR 'root'@'%' = PASSWORD(<password>);

Replace <password> with your desired password.

Obviously change the root user details based on your particular set up. I.e. where the root account can connect from, which servers, ips, etc.