Frequently used Unix Commands

To Untar a tar file

In unix we don’t have any untar command. We just use tar commands with proper arguments For eg. i want to untar Tomcat on my unix box:

tar -zxvf apache-tomcat-6.0.35.tar.gz

Above command extracts a .tar file silently.

List Files

ls -ltra

Above command lists files sorted on timestamp, so latest modified file will be at the bottom. The arguments supplied mean as below

  • -l Shows you huge amounts of information (permissions, owners, size, and when last modified.)
  • -t Shows you the files in modification time.
  • -r Reverses the order of how the files are displayed.
  • -a Shows you all files, even files that are hidden (these files begin with a dot.)

Make Directory

mkdir abc

Above command makes a directory named abc inside your current directory.

grep command

Search for a given string in a file (case in-sensitive search).

$ grep -i "bharat" names.txt

Search for a given string in all files recursively

$ grep -r "bharat" *

find command

Find files using file-name ( case in-sensitve find)

$ find -iname "jdbc.properties"

tail command

Inspect lines at end of file

$ tail -100 jdbc.properties

Above command shows last 100 lines of jdbc.properties

Now there can be times when you want to keep looking at end of file; for eg. a log file while the logs are being written
below version of tail command can be useful in such a case

$ tail -f applogs.txt

netstat

List used ports

$ netstat -lnptu | less

File/Directory size

Following command shows size of files/directories in sorted order. This may be useful in case you want to do some cleanup.

du -sk * | sort -n

# below command gives top 20 large files in a directory

du -sm * | sort -nr | head -20

# The -h option provides "Human-readable" output i.e. you will see it in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte:

du -h /tmp

Disk Free Space

Disk free space shows important file system information.

 $ df -h
Advertisements

, , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: