In: Computer Science
In Linux Terminal
1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt
2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path)
3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB).
4. Give a commmand that searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes.
5. Give a command that searches within the directory /mp3-collection for files that have their names beginning with ’Metallica’ and whose size is greater than 10000 kilobytes (> 10 MB).
6. Give a command that searches in the same directory as above case but only for files that are greater than 10MB, but they should not have ’Metallica’ as the starting of their filenames.
1. Give a command using find to search from the root directory the file program.f and redirect any errors to the file myerrors.txt
ans:
find / -name "program.f" 2> myerrors.txt
/ - for root directory
-name Search for files with specified name( case sensitive)
program.f is the file name to search for.
2> for error redirection
myerrors.txt file in which errors will be redirected
2. Give a command for finding files having the letters index as the beginning of the file name and located in your home directory (provide the absolute path)
ans:
find /home -name "index*"
/home :searches from home directory
-name :Search for files with specified name( case sensitive)
index* :finds files starting with index in file name
3. Give a command for finding within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes (< 5MB).
ans:
find /mp3collection -name "*.mp3" -size -5000k
/mp3collection searches from directory mp3collection
-name Search for files with specified name( case sensitive)
*.mp3 Search for all files with .mp3 extension
-size -5000k option to specify files with size less than 5000 kilobytes
4. Give a commmand that searches for those files that are present in the directory /home/david and its subdirectories which end in .c and which have been accessed in the last 10 minutes.
Ans:
find /home/david -amin -10 -name "*.c"
/home/david searches from directory /home/david
-amin -10 used to specify files that have been accessed in the last 10 minutes
*.c Search for all files with .c extension
5. Give a command that searches within the directory /mp3-collection for files that have their names beginning with ’Metallica’ and whose size is greater than 10000 kilobytes (> 10 MB).
Ans:
find /mp3-collection -name "Metallica*" -and -size+10000K
/mp3-collection searches from directory /mp3-collection
Metallica* for names beginning with word Metallica
-and to specify and condition
-size+10000K for resulting the files with size greater than 10000 kilobytes
6. Give a command that searches in the same directory as above case but only for files that are greater than 10MB, but they should not have ’Metallica’ as the starting of their filenames.
Ans:
find /mp3-collection -size+10000K ! -name "Metallica*"
/mp3-collection searches from directory /mp3-collection
-size+10000K for resulting the files with size greater than 10000 kilobytes
! to specify not condition
-name Search for files with specified name( case sensitive)
Metallica* for names beginning with word Metallica