468x60 Ads

Thursday, October 4, 2012

Create new empty files using "touch" command


The touch Command

The touch command is use to create new empty files.

It’s also use to change file access and modification times
touch's syntax :

#touch [option] file_name
Using touch command can create any number of files simultaneously.

Eg:
#touchfile1.txt file2.sql file3.bat

Monday, October 1, 2012

Find command in solaris 10 (Eg:Find some content inside files under some directory)


Find some content inside files and it will gives the files that content is available:

# find /usr/local/etc/ -type f-exec grep -l "00:C0:89:14:9F:6C" {} \;
/usr/local/etc/dhcplog.txt
/usr/local/etc/subnetfiles/50.200.0.0-19-server2

/usr/local/etc/ :Location that you want to dind

Use “.” To find in current directory

Eg: # find . -type f -exec grep -l "00:C0:89:14:9F:6C"{} \;

00:C0:89:14:9F:6C: The phrase that you want to find inside the file

-type type of file:
d - Directory
f - File
l - Link

# find/usr/local/etc/ -exec grep -ls 50.200.0 {} \;
/usr/local/etc/dhcpd.conf
/usr/local/etc/dhcplog.txt
/usr/local/etc/dhcpd.conf_subnet
/usr/local/etc/subnetfiles/50.200.0.0-19-server2
#


Search some files that have not been accessed for a specific time period and removing those Files

     The following command is for removes all files in /home/bacup  direc-
     tory  named  my.bac  or *.log  that have not been accessed for a week:

# find /home/bacup  \( -namemy.bac -o -name '*.log' \) \  -atime +7 -exec rm {} \;


Find all text files in the /user/local directory using the command, the -print option is used to display the results to standard out.

# find /user/local -name "*.txt"-print
/var/sadm/pkg/SUNWmozilla/save/pspool/SUNWmozilla/reloc/sfw/lib/mozilla/chrome/installed-chrome.txt
/var/sadm/pkg/SUNWlibusb/install/thirdpartylicensereadme.txt

Find files larger than 1 Gigabyte the commaand below may be used, notice unlike Linux, (Solaris 10 does not support the M(Megabyte) or G(Gigabyte) options)
c option for bytes.

#find / -size +1000000000c –print


The -exec flag may be used to apply a command to each of the files which have been found.
 ({}) represents the name of each file found.
 (\;)end of the command.

# find /usr/local/etc/ -name "*.txt" -print -exec wc -l {} \;

Find the file named readme.txt and view the content:

#find / -name "readme.txt" -exec cat {} \;