Archive for the ‘UNIX’ Category
All posts in UNIX category.
Every once and awhile I find myself needed to what is the space hog on my computer/server. While the command du – h in the command line works for a general overview – I really want to see the results in descending order (by space used). This command will list out everything in descending order so you can quickly see where the most space is used:
du -k -s * | sort -k1 -g -r
Ever wonder how to copy something from the command line into the Mac OS clipboard? If you want to copy/paste a files content (perhaps a log file or a conf file, etc) into the clipboard to use outside of the CLI, you can use the commands pbcopy and pbpaste. Example: I want to copy the contents of my public key to the clipboard (so I can send it to a server admin who will use it in allowing me to access their subversion repository).
All I would need to do is:
cat id_dsa.pub | pbcopy
(cat writes out the content and then it is piped (|) into the clipboard) This comes in handy!
If you do any sort of web development, it is more than likely that CPANEL and phpMyAdmin are good friends of yours…and you depend on them. Even though those are extremely handy to create/modify databases and create backups, it is extremely helpful to know how to do the same thing by using only SSH and command line utilities.
To backup (export) a database using the command line interface (CLI):
mysqldump -p --user=username --add-drop-table database > backup.sql
You will then need to provide your database password and the exported data will go into a file called “backup.sql” which is located in the directory that you are currently in. (more mysqldump documentation
To backup your files:
tar -cvzf backup.tgz directoryname
The command will create an archive of all your files so you can easily move or store one file (the archive). More tar documentation.
I ran into an issue earlier today where I could not connect to a SMB share after my upgrade to Mac OS X 10.5. After some research, I found a thread in Apple’s Discussions.
Basically…you need to not use “Connect to Server…” – you need to mount/unmount the SMB share via the command line.
Basic Mount/Unmount Process
- Create a directory (folder) where you want the mounted share to appear. I created a folder called “SMB” on my Desktop
- Type in the following command: mount_smbfs //useyourusername@localhost/remote_share /Users/useyourusername/Desktop/SMB in the terminal
- You will be prompted for your password, type it in
- You now have access to the files on the remote server in the folder you created – enjoy!
- Once you are done, unmount the server by typing in the command: umount /Users/useyourusername/Desktop/SMB
Hopefully Apple will fix this issue ASAP, but until they do, you now have a way to connect to servers via SMB.
I have been doing a lot of work recently on a remote server and have needed to use a text editor – so I decided to use the ever-so-easy nano. Problem is – the files I am working on are very long and editing them is not fun. I finally decided to look through the man pages (I am an emacs person myself) and found something that ended up saving me tons of time…”go to line number”. If you are editing a file and know you need to edit something on line 1245, you would type in:
nano +1245 master.css
and it would open the file to line 1245 so you do not need to scroll down. Thank you man pages!
A few simple commands to help make your life working with UNIX a little easier:
- If you are looking for a certain programs, use:whereis. Example. You want to find out where ipfw is located. In the command line type
whereis ipfw and whereis will spit out the location (/sbin/ipfw).
- If you need to find a program or a file and you know what it is called, use:locate. Example. I know I want to uninstall MySQL, and I want to see every file that has mysql in the file path. In the command line, type
locate MySQL and locate will spit out every file with MySQL in the file path. (Note, locate is case sensitive).
Earlier today I was asked for the command to show a file size in UNIX and so I thought I would share. There are, of course, a few ways to do this. One great little command to keep handy is:
du -h. The du (display utility) will print out the size of a file or directory. The -h will make it “human readable” (put the sizes in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte). So, next time you need file or directory sizes, use
du -h and be done with it!
While upgrading a client’s web site to XOOPS 2.0.14 I ran into some issues with the XOOPS 2.0.14 package file (a tar.gz file). Stuffit Expander would only extract a few folders, then report an error and quit. After a few attempts, and all failures, I had to chose to turn to the command line and bingo, no problems! So, if you ever have any issues with Stuffit Expander and need to uncompress a .tar.gz file, the following commands will come in handy:
- To uncompress a gz file:
- To uncompress a tar file:
tar [tar options (usually xvf)] file.tar
- To uncompress a .tar.gz file:
tar xzvf file.tar.gz
Questions? Check out the man pages for tar and gunzip.
[tags]XOOPS, gunzip, tar[/tags]
Well, after some problems downloading the 3.3GB image of Fedora Core 5 and then my PowerBook not recognizing the DVD media (no, I was not about to re-download all five install CD images and burn them to CD…this is not 1993 again with installer floppies everywhere…and I did not have any other DVD media on hand), I decided to try a different flavor of Linux: Ubuntu. A few people that I I have been talking to recently either prefer Ubuntu, or have recently tried it, like Tim. Since the install image is only 644.5MB, I decided it might be the time to try it out.
From the very beginning, I was impressed. I first had problems with my install because of a CD error, but to my delight, the Ubuntu installer gav eme an option to set up a web server with a click of a button which served all the installation log files so I could look at them and find the problem. When I got home, I burned another copy and while my Comcast connection was out (TV and internet!) I installed and configured Ubuntu with ease.
What I really like so far about Ubuntu:
- small install (one CD worth)
- Ubuntu recognized all my hardware without me having to hack anything!
- the ability to run Ubuntu from a CD (live CD)
- awesome documentation in the help menu…the “Tips and Tricks” rock, and answered most of my questions
- the “Snaptic Package Manager” which easily allows you to install packages
- after installing packages with the “Snaptic Package Manager”, the new applications are put in appropriate menus, etc!
- the great little sounds I get when clicking on buttons and icons
So far, I am extremely happy with Ubuntu and look forward to using it more and more. It is plenty fast and if all goes well, I may see how it runs on my Apple cube so I can get that back into play. As of now…this is, by far, my favorite flavor of Linux I have played with (Yellow Dog, Mandrake (Mandriva), Redhat, and Fedora FC3, FC4). If you are looking to run Linux, give Ubuntu some attention – it gets the Jappler stamp of approval!
PS. Happy 5th birthday to Mac OS X today. Five years ago, Mac OS X 10.0 was released!
[tags]Fedora Core 5 PPC, Ubuntu PPC, Snaptic Package Manager[/tags]
I have not had any recent how-tos or informational articles, but I am hoping to end that dry spell tomorrow after I install and configure Fedora 5. I have been very happy with Fedora 3 and 4, and look forward to the most recent release. Stay tuned.
PS…yeah I know that other builds, besides PPC are also out, but they are not my concern at this point.
[tags]Fedora Core 5[/tags]