1. Find only directories not files from a given directory(ls -lS | grep '^d')
For example I have below files and directories in directory /debashis and I want to sort out the directories only not files
or@hulalala[/yah/debashis]#ls -lrt
total 80
-rwxrwxrwx 1 khataid staff 466 Apr 07 13:53 hhhh.sh
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
oracle@devcrpdb1[/temp/debashis]#ls -lS | grep '^d'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
2. Find only files not directory inside a directory (ls -LS | grep -v '^d')
or@hulalala[/yah/debashis]#ls -lS |grep -v '^d'
total 80
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
-rwxrwxrwx 1 khataid staff 466 Apr 07 13:53 hhhh.sh
3.Find directory of specific month for example here Jul month
or@hulalala[/yah/debashis]#ls -lS | grep '^d' | grep 'Jul'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 2 oracle oinstall 256 Jul 09 11:41 hara
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
if for specific date
or@hulalala[/yah/debashis]#ls -lS | grep '^d' | grep 'Jul 01'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
4. Find files of specific month for example Jun in above list of files
or@hulalala[/yah/debashis]# ls -lS | grep -v '^d' | grep 'Jun'
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwx------ 1 khataid staff 1235 Jun 29 09:55 another.sh
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
-rwxrwxrwx 1 khataid staff 544 Jun 23 07:54 englishUser.sql
or@hulalala[/yah/debashis]# ls -lS | grep -v '^d' | grep 'Jun 03'
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
Please Note: Whe we are giving grep 'Jun 03' it will also includes 2014 and 2015 files as well so before list out the files for the current month please check out whether there is any files for 2014 or 2013 files are prsent for that you have to encounter the below commands..
ls -lS | grep -v '^d' | grep 'Jun 03 2014' ---> it will show files of 03rd Jun 2014 same for every month.
5. Moving all the files of a particular date to another directory
From below snap I will move all the files of Jul 09 to directory hara
Command I used is
for i in $(ls -lS | grep -v '^d' | grep 'Jul 09');
do
mv $i /temp/debashis/hara
done
and if you see there are no files of Jul 09 inside /temp/debashis but same files are present in /temp/debashis/hara docrectory
For example I have below files and directories in directory /debashis and I want to sort out the directories only not files
or@hulalala[/yah/debashis]#ls -lrt
total 80
-rwxrwxrwx 1 khataid staff 466 Apr 07 13:53 hhhh.sh
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
oracle@devcrpdb1[/temp/debashis]#ls -lS | grep '^d'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
2. Find only files not directory inside a directory (ls -LS | grep -v '^d')
or@hulalala[/yah/debashis]#ls -lS |grep -v '^d'
total 80
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
-rwxrwxrwx 1 khataid staff 466 Apr 07 13:53 hhhh.sh
3.Find directory of specific month for example here Jul month
or@hulalala[/yah/debashis]#ls -lS | grep '^d' | grep 'Jul'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 2 oracle oinstall 256 Jul 09 11:41 hara
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
if for specific date
or@hulalala[/yah/debashis]#ls -lS | grep '^d' | grep 'Jul 01'
drwxrwxrwx 2 khataid staff 256 Jul 01 09:25 anotherdir
drwxrwxrwx 2 oracle oinstall 256 Jul 01 09:38 anotherdirrrr
drwxrwxrwx 3 oracle oinstall 256 Jul 01 09:38 practice
4. Find files of specific month for example Jun in above list of files
or@hulalala[/yah/debashis]# ls -lS | grep -v '^d' | grep 'Jun'
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
-rwx------ 1 khataid staff 1235 Jun 29 09:55 another.sh
-rwxr-xr-x 1 oracle oinstall 995 Jun 11 04:17 DEV_ora_26542272.trc
-rwxrwxrwx 1 khataid staff 544 Jun 23 07:54 englishUser.sql
or@hulalala[/yah/debashis]# ls -lS | grep -v '^d' | grep 'Jun 03'
-rwxrwxrwx 1 oracle oinstall 10240 Jun 03 08:41 debashis.tar
Please Note: Whe we are giving grep 'Jun 03' it will also includes 2014 and 2015 files as well so before list out the files for the current month please check out whether there is any files for 2014 or 2013 files are prsent for that you have to encounter the below commands..
ls -lS | grep -v '^d' | grep 'Jun 03 2014' ---> it will show files of 03rd Jun 2014 same for every month.
5. Moving all the files of a particular date to another directory
From below snap I will move all the files of Jul 09 to directory hara
Command I used is
for i in $(ls -lS | grep -v '^d' | grep 'Jul 09');
do
mv $i /temp/debashis/hara
done
and if you see there are no files of Jul 09 inside /temp/debashis but same files are present in /temp/debashis/hara docrectory
No comments:
Post a Comment