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.
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.)
Above command makes a directory named abc inside your current directory.
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 files using file-name ( case in-sensitve find)
$ find -iname "jdbc.properties"
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
List used ports
$ netstat -lnptu | less
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