Search Results for: cat

mtime – file modification timestamp in Unix

mtime is one of the three timestamps in Unix that are maintained for each file in most of the filesystems.

Purpose of mtime

The real purpose of the mtime timestamp is to track the last time of changing the contents of a file. Various commands will allow you to access this information later. For example, ls command allows showing list of files along with their last modification times (it's also possible to get ls to confirm the last access time (atime timestamp)for any file).

mtime example

Here's how you can see mtime in real life. Let's create a file named example.txt and get a full ls listing on it:

greys@ubuntu:~$ date
Fri Sep 28 10:25:40 IST 2012
greys@ubuntu:~$ > example.txt
greys@ubuntu:~$ ls -l example.txt
-rw-r--r-- 1 greys greys 0 2012-09-28 10:25 example.txt

As you can see, the last modification of the "example.txt" file is 10:25am.

Now let's wait a minute:

greys@ubuntu:~$ sleep 60

…confirm the file's mtime is still the same:

greys@ubuntu:~$ ls -l example.txt
-rw-r--r-- 1 greys greys 0 2012-09-28 10:25 example.txt

… and now make the change by adding a line "change" to our file:

greys@ubuntu:~$ echo "change" >> example.txt

And if we check the file's mtime timestamp, it will be updated – in my case 10:27am:

greys@ubuntu:~$ ls -l example.txt
-rw-r--r-- 1 greys greys 7 2012-09-28 10:27 example.txt

More info on mtime

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

cat – concatenate files and print to the standard output

cat is a simple yet very useful Unix command. It takes a name of one or more text files, and then shows their contents to the standard output as one stream of data.

cat command example

greys@ubuntu:~$ cat /etc/kernel-img.conf
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
postinst_hook = /sbin/update-grub
postrm_hook   = /sbin/update-grub

for two files, it looks like this:

greys@ubuntu:~$ cat /etc/issue
Ubuntu 7.04 \n \l
\
greys@ubuntu:~$ cat /etc/issue /etc/kernel-img.conf
Ubuntu 7.04 \n \l
\
do_symlinks = yes
relative_links = yes
do_bootloader = no
do_bootfloppy = no
do_initrd = yes
link_in_boot = no
postinst_hook = /sbin/update-grub
postrm_hook   = /sbin/update-grub

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

locate – quickly find files in Linux

Today I'd like to show you one more option you have when searching for files in Linux. If you have a locate tool installed, you'll be able to find any file almost instantly.

How does locate command work?

locate uses a pretty simple principle – instead of going through your filesystem directory tree every time you need a certain file found, it consults a database which stores locations of most files in your system. The locate database (locatedb) is updated nightly with a separate command. The update occurs during night hours when peak usage of your system is very unlikely, but this means that using such a database through the day will provide instant results.

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

How To Find a Location of a Directory in Unix

Very quick tip for you today, I just see that many of visitors of this block are curious how they can find a directory in Unix – and so here's a command to help you do just that.

Finding directories in Unix

There's nothing better than to employ the find command. As you might remember, among many things, this wonderful tool allows you to search files by their type. Since nearly everything in Unix is a file, this means you can find directories.

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

tee: Replicate Standard Output

Now and then I come across a situation when I need to run a script or a Unix command and would like to not only see the output of it on the screen, but also save this output to some log file. Redirecting the standard output using standard Unix stream redirection isn't always useful because your output will either be shown to you, or sent to the file – but not both at the same time

tee command

That's where the tee command becomes really useful. You pipe your output to this command, and let it take care of the rest.

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Puppet 3.0.0 is here

As some of you may have noticed already, Puppet configuration management system has just been upgraded to 3.0.0 release.

Being a major milestone, this upgrade brings the following major improvements:

  • performance is much better for catalog compilation
  • improved and expanded OS support – lots of Windows improvements, great new functionality for Solaris (zones, packages and services are finally supported now)
  • pluginsync is now enabled by default
  • new version of Ruby is supported (Ruby 1.9) and Ruby DSL was completely rewritten
  • dynamic scoping is no longer supported (yep, this breaks backwards compatibility with 2.7.x branch of Puppet)
If you're new to Puppet, please visit the PuppetLabs website for more info and for free download.

I have read and reviewed a couple of great books on Puppet, so check the reviews out:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Using Dropbox with Unix

Although last week saw some pretty exciting developments in the cloud storage (Google Drive announcement and SkyDrive free 25Gb space), the truth is that Dropbox is still the king of the cloud storage hill – it's hands down the easiest to use and integrate.

I've been a Dropbox user for a few years now, but have started using it actively only in the last 12 months or so. It's been an invaluable tool for me thanks to its integration with 1Password, the password tool of my choice. Dropbox also helps with lots of day-to-day tasks and thats why I decided it's time to share some of the tips.

Having used Dropbox extensively on Windows systems (XP on laptop and Win7 on desktops), I've recently moved on to using Dropbox with my Mac OSX desktop and Linux hosting.

So here are the top tips for using Dropbox with Unix – each one does wonders for me and so I hope you like them as well.

Important: If you're not a Dropbox user yet, please use this link to sign up – it means I'll get a small bonus (extra 500MB to my free account) for referring you.

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Passwordless SSH with encrypted homedir in Ubuntu

Quite recently I came across a very interesting issue: while configuring passwordless SSH (it's public key based, so depending on you have it configured it may not be completely passwordless) access to some of my VPS servers, I found that the same keypair just wouldn't work on one of the servers.

Not only that, but the behaviour was quite bizzare: upon my first attempt to connect the public key would get rejected and a regular password would be requested by the ssh session. But once I successfully logged in with my password, any subsequent ssh connections would happily authenticate by my public key and would let me in without a problem.

Those of you using home dir encrypiton in Ubuntu are probably smiling right now! :) But becase I have never consciously configured or used this feature, it took me a good few hours to troubleshoot the issue and come up with the fix.

[Read more...]

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Welcome to 2012!

It's been so unbelievably long since my last post on this blog that I decided to start this year with a non-technical welcome.

I have great plans for UnixTutorial in 2012, and would welcome any opportunity to share knowledge and experience with all of the readers and new visitors
of this blog.

Here's just a few of the things I plan to do:

  • UnixTutorial members area – long time coming, this area of the website will finally make a proper debut in the next few months. I'll be announcing the next round of email subscriptions shortly, so don't miss out if you're still interested
  • A series of UnixTutorial eBooks – eventually a balanced collection of free and paid material in PDF and Kindle formats (polls to decide which topis are in demand will follow shortly)
  • Broader coverage of Unix topics – this year I expect to write a lot more about Mac OS and AIX systems
  • New WordPress theme and quite likely a mobile copy of the website (let me know what devices you have, I own  iPhone and iPad so will do initial testing)
  • Completion and expansion of the Basic Unix Commands and Advanced Unix Commands sections
  • More Unix book reviews and recommendations
  • Reviews of latest Unix-like OS releases
  • Even more Questions and Answers

If you expect to see even more – now would be a really good time to let me know by leaving a comment. Thanks and stay tuned!

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

Upgrading Ubuntu with do-release-upgrade

There comes a time (a couple of times a year, actually) when you may want to upgrade your Ubuntu distro (read here for instructions on confirming your version of Linux: Find Out Linux Version)

Once that's done, you can use do-release-upgrade for a hassle free upgrade.

IMPORTANT: are you can see, I've used a really old Ubuntu server with 8.10, hence your procedure for upgrading more recent Ubuntu versions may be slightly different. For example, later upgrades will warn you if you're doing a release upgrade over ssh.

What do-release-upgrade is and when you should use it

do-release-script is a Python script which automates the process of updating multiple packages. It relies upon Ubuntu's core package management functionality.

Apart from downloading and installing updated versions of packages found on your system, this command attempts to take care of all the necessary Ubuntu-release related file changes.

Step 1: Run do-release-upgrade

Once you type the do-release-upgrade command name and press Enter, you should see how vital information about packages currently installed is being collected:

# do-release-upgrade
Checking for a new ubuntu release Done
Upgrade tool signature Done
Upgrade tool Done
downloading
extracting 'jaunty.tar.gz'
authenticate 'jaunty.tar.gz' against 'jaunty.tar.gz.gpg'
Reading cache
Checking package manager
Reading package lists: Done
Reading state information: Done
Updating repository information
Done http://archive.ubuntu.com jaunty Release.gpg
Done http://archive.ubuntu.com jaunty-updates Release.gpg
Done http://security.ubuntu.com jaunty-security Release.gpg
Done http://us.archive.ubuntu.com jaunty-backports Release.gpg
Done http://security.ubuntu.com jaunty-security Release

Checking package manager
Reading package lists: Done
jaunty-security/multiverse
Packages: 98  2
Reading state information: Done
Reading state information: Done
Reading state information: Done
Calculating the changes

 

2. Confirming what upgrading will do

This is your last change to change your mind. All the necessary information about your current Ubuntu release is collected, and now you're presented with the exact upgrade details: how many packages will be removed, how many new ones will be installed, how many will be upgraded. You also are given details about the required amount of data to be downloaded should you decide to proceed with the upgrade;

Do you want to start the upgrade?

1 package is going to be removed. 23 new packages are going to be installed. 420 packages are going to be upgraded.

You have to download a total of 248M. This download will take about 7 minutes with your connection.

Fetching and installing the upgrade can take several hours. Once the download has finished, the process cannot be cancelled.

Continue [yN]  Details [d]

Ready? Press y for yes!

3. Downloading all the packages

Just like with apt-get, you will now see the progress of downloading all the updated packages for your Ubuntu OS. At the bottom of the screen you will see the overall completeness of the download (22% in my example), the current download speed (598kB/s in my case) and the ETA:

Done http://archive.ubuntu.com jaunty-updates/main libbz2-1.0 1.0.5-1ubuntu1.1
Done http://archive.ubuntu.com jaunty/main libdb4.7 4.7.25-6ubuntu1
Done http://archive.ubuntu.com jaunty/main libncursesw5 5.7+20090207-1ubuntu1
Done http://archive.ubuntu.com jaunty-updates/main libssl-dev 0.9.8g-15ubuntu3.6
Done http://archive.ubuntu.com jaunty-updates/main libssl0.9.8 0.9.8g-15ubuntu3.6
Done http://archive.ubuntu.com jaunty/main python2.6 2.6.2-0ubuntu1
[23%] 598kB/s 5min17s

4. Upgrade

Once package are downloaded, they will get installed once by one, with package-specific questions asked for software like postfix or apache.

5. Reboot

To finalize the distro upgrade, you will need to do a reboot. Once completed, you should have a shine next release available.

Recommended books:

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS