Entries Tagged 'Basic stuff' ↓
June 18th, 2009 — Basic stuff, Scripts, Unix
Although I've already shown you how to sum numbers up in bash, I only covered the bash way of doing it. I really like scripting with bash, but when it comes to calculations, there's quite a few important features missing from bash, and fixed point (thanks for the correction, Azrael Tod!) calculations is one of them. Fortunately, bc command comes as a standard in most Unix distros, and can be used for quite complex calculations.
Basic calculations with bc
bc is a very simple command. It takes standard input as an expression and then evaluates this, performing all the necessary calculations and showing you the result. Thus, to quickly sum numbers up or get a result of some other calculation, simply echo the expression and then pipe it out to the bc command:
ubuntu$ echo "1+2" | bc
3
Continue reading →
June 9th, 2009 — Basic stuff, Unix
One of the really useful features almost every Unix shell has is support for command aliases – a way to run a command or a series of Unix commands using a shorter name you get associated with such commands.
An example of a command alias in Unix shell
Here's one of the most useful aliases I have for Solaris systems:
solaris$ alias ls='/usr/local/gnu/bin/ls --color -F'
Continue reading →
May 15th, 2009 — Basic stuff, Linux, Ubuntu
SSH (Secure SHell) is possibly the best way to remotely access a Unix system – it's very secure thanks to automatic encryption of all the traffic, and it's also quite universal because you can do all sorts of things: access remote command line shell, forward graphics session output, establish network tunnels and set up port redirections. Today I'm going to show you how to get started with SSH in Ubuntu.
Installing SSH server in Ubuntu
By default, your system will have no SSH service enabled, which means you won't be able to connect to it remotely using SSH protocol (TCP port 22). This means that installing SSH server will be one of the first post-install steps on your system.
The most common SSH implementation is OpenSSH server, and that's exactly what you want to install.
Continue reading →
May 11th, 2009 — Basic stuff
show disk size in Unix is a very popular request visitors use to arrive at my Unix Tutorial pages. Since I never addressed the question of confirming the number of hard drivers available on your system or the task of finding out a disk's capacity, I'd like to document a quick and easy way of doing just that.
I hope that when someone looks for a way to show disk size, what's really expected is a command to help you confirm the capacity of a disk in gigabytes.
Using fdisk command in Linux
One of the easiest ways to learn a lot about hard drives installed on your Linux system is to use the fdisk command: Continue reading →
February 25th, 2009 — Basic stuff, Scripts, Unix
If you're ever thought of summing up more than two numbers in shell script, perhaps this basic post will be a good start for your Unix scripting experiments.
Basic construction for summing up in shell scripts
In my Basic arithmetic operations in Unix shell post last year, I've shown you how to sum up two numbers:
Continue reading →
February 13th, 2009 — Basic stuff, Linux
Hi all, today I'm going to teach you not one, but two really cool things in one post! First, I'll introduce you to advanced memory usage stats available on Linux systems through /proc/meminfo file, and then I'll explain the basics of using the watch command.
Memory usage with /proc/meminfo
As you know, quite a few Unix-like systems use the so-called pseudo file systems like /proc. It's not a real filesystem, but just a convenient representation of processes managed by your Unix OS. In Linux systems, this directory also contains quite a few files allowing you to access various information about your system. /proc/meminfo is one of such files, it gives you access to most of the memory usage stats.
Continue reading →
February 9th, 2009 — Basic stuff, Ubuntu, Unix
I've just been asked a question about changing the ownership of files from one Unix user to another, and thought it probably makes sense to have a quick post on it.
File ownership in Unix
Just to give you a quick reminder, I'd like to confirm that every single file in Unix belongs to some user and some group. There simply isn't a way to create a file without assigning ownership. I've briefly touched the topic of confirming file ownership in Unix before, so today I will simply build on that and show you how to change ownership of files.
Continue reading →
November 17th, 2008 — Basic stuff
If you remember, all files and directories in Unix filesystems have three timestamps associated with them – atime, ctime and mtime. Since questions about modifying access time (atime) and modification time (mtime) are quite frequent in my website logs, I thought I'd explain how it is done.
How to view atime, ctime and mtime
Before we go any further, I'd like to remind you that using stat command is probably the easiest way to look at all the three timestamps associated with each file:
Continue reading →
September 25th, 2008 — Basic stuff
Today is going to be a practical tip. If you're managing many Unix systems, sooner or later you come across files with special characters – they can't be deleted with rm command using standard approach and require a bit of trickery to be successfully removed.
Examples of files with special characters
Any language apart from English will probably have special characters in the alphabet, but for the purpose of today's exercise I'll give you more standard examples: files starting with dash (-) and hash (#) characters:
ubuntu$ ls -al
-rw-r--r-- 1 greys admin 0 Sep 25 05:50 #try
-rw-r--r-- 1 greys admin 0 Sep 25 05:48 -try
Continue reading →
September 19th, 2008 — Basic stuff, Scripts
When I was writing a post about using date command to confirm date and time in your Unix scripts, I made a note in my future posts list to cover the date calculations – finding out the date of yesterday or tomorrow, and so on. Today I'll show you the simplest way to calculate this.