Question

In: Computer Science

Write single linux commands for each question. 2. Find every file ends with “.py” or “.txt”...

Write single linux commands for each question.

2. Find every file ends with “.py” or “.txt” or “.cpp” from your root directory, and list the detail of each file.
3. Find every line that contains two or more space in every file in “Folder1” include subdirectory.
4. Find every line that contains two or more “<<” symbol in “Folder2” include subdirectory.
5. Find every line that contains parentheses inside parentheses in “Folder3” include subdirectory, such as print(type(6*2)).
6. Find every line that contains at least two digits in folder “Folder1”, “Folder2” and “Folder3” include subdirectory. The two digits can be two separate digit, such as “1.5” or “1 and 2”.
7. Find every line that start with “}” or ends with “{” in “Folder2” include subdirectory. Example: “int main(){” or “}”.
8. Find every line that contains any pair of repeated words in folder “Folder1”, “Folder2” and “Folder3” include subdirectory. Example: a + a, b b, c d c d. (The command should be able to find the ‘c = a + “ ” + b’)
9. List every filename contains at least two digits from folder “Folder1”, “Folder2” and “Folder3” include subdirectory.
10. List every filename contains a number that greater than 11 and less than 22 from folder “Folder1”, “Folder2” and “Folder3” include subdirectory.

Solutions

Expert Solution

2.

find . -iregex '.*\.\(py\|cpp\|txt\)$' -ls

the iregex command is used for regular expression matching ignoring the case and ls is used to display the details of the files. The regular expression for a file with some extension say .a would be " *.a ".

Please make sure that the spaces are as written in the answer when the command is executed.

3.

grep -r '* * *' /Folder1

the -r flag is used to search recursively in the directory (search the current directory and all sub directories) " * * * " is the regular expression for text that has 2 or more spaces.

4.

grep -r '*<<*<<*' /Folder2

the -r flag is used to search recursively in the directory (search the current directory and all sub directories) and " *<<*<<* " is the regular expression for text that has 2 or more << symbols.

5. 

grep -r '(*(*)*)' /Folder2

the -r flag is used to search recursively in the directory (search the current directory and all sub directories) and "(*(*)*)" is the regular expression for text that has parenthesis inside parenthesis.

6.

grep -r '*[0-9]*[0-9]*' /Folder1/ /Folder2/ /Folder3/

The multiple folders to search in are specified this way and all other stuff is same as above.

7.

grep -r '(^{*)|(*}$)' /Folder2

The regular expression for this problem consists of ^ and $ which are the start and end symbols respectively. Rest is same as above.

9.

find / -iregex '*[0-9]*[0-9]*\.*' /Folder1/ /Folder2/ /Folder3/

The explanations are same as part 2. the regular expression is for two digits and I have added a \.* at the end of the regular expression so that the two numbers are in the file name and not in the extension.

10.

find / -iregex '*\(1*[2-9]*\|21\)*\.*' /Folder1/ /Folder2/ /Folder3/

The ecplanation is same as part 2 and part 9.


Related Solutions

Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
[In Python] Write a program that takes a .txt file as input. This .txt file contains...
[In Python] Write a program that takes a .txt file as input. This .txt file contains 10,000 points (i.e 10,000 lines) with three co-ordinates (x,y,z) each. From this input, use relevant libraries and compute the convex hull. Now, using all the points of the newly constructed convex hull, find the 50 points that are furthest away from each other, hence giving us an evenly distributed set of points.
Linux Question: Describe how you created above file and its contents in VI. a) Bash/VI commands:...
Linux Question: Describe how you created above file and its contents in VI. a) Bash/VI commands: 20pts; b) Non-brute-force solution: 10pts). Note: Brute-force solution means that entering characters one by one Install JDK 1.8 by the following command: $ sudo dnf –y install java-1.8.0-openjdk-devel.x86_64 Use VI to create a file “YourFirstNameHomework.java” (e.g., “MollyHomework.java”) and add the following contents into it. (grading details: file name format:10 pts, a screenshot of the file content in the VI environment: 10pts, paragraphs: 10pts, empty...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device,...
Linux Ubuntu 1. Use the appropriate commands to locate the device file used by the device, mount the filesystem to a directory of your choice, and check the filesystem for errors. 2. Finally, add a line to /etc/fstab to ensure that the filesystem can be easily mounted in the future (this line should not automount the filesystem at boot time). You have to document all your steps and provide the screenshot of your work process.
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Write a php program that writes numbers to a file. The file type should be .txt...
Write a php program that writes numbers to a file. The file type should be .txt and the file name should be numbers.tx. The numbers.txt should contain 10 random integers between 1 to 100 after the file is written.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT