diff --git "a/os_interaction/data/7/bootstrap.json" "b/os_interaction/data/7/bootstrap.json" new file mode 100644--- /dev/null +++ "b/os_interaction/data/7/bootstrap.json" @@ -0,0 +1,1498 @@ +[ + { + "description": "The problem is related to process management in the Linux operating system. You will need to find the total number of active processes running in the user's Linux (ubuntu) operating system. \n\nYou are required to write a bash script that counts all the active processes and displays the count as an integer value.\n\nWe will initialize the environment by creating an additional 5 processes that will run for 60 seconds each in the background.", + "explanation": "To solve this problem, you will need to count all the active processes using the 'ps' command by combining it with other utilities like 'grep', 'awk', or 'wc'. A hint is to use the 'ps -A' or 'ps -e' option with 'ps' command to list all the processes running in the system.", + "create": { + "init": "\n#!/bin/bash\n\nfor i in {1..5}\ndo\n (sleep 60) &\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\nps -A | wc -l" + } + }, + { + "description": "In this problem, your task is to find the total count of processes that are currently running on the student's Linux (Ubuntu) operating system having 'bash' in their command name or path. The answer must be an integer.", + "explanation": "To solve this problem, you can use the 'ps' command to get the list of processes and 'grep' command to filter out the desired processes containing 'bash' in their command name or path. Here are a few hints on how to construct your command:\n\n1. Use 'ps -ef' to display the processes for all users.\n2. You need to use 'grep' command to find the processes containing 'bash' in their command name/path.\n3. Count the number of lines which indicates the number of matched processes.\n4. You may want to combine these steps in a pipeline for the easy retrieval of the desired result.", + "create": { + "init": "\n#!/bin/bash\n# This is a simple initialization script that does nothing, but you can add any necessary setup steps if needed.\necho \"Initialization completed.\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "ps -ef | grep -i 'bash' | grep -v 'grep' | wc -l" + } + }, + { + "description": "As a student, you are required to calculate the total size of all files with a specific file extension in a given directory and its subdirectories. You have to use Linux (Ubuntu) operating system commands to achieve this. The file extension and directory path will be given to you as input arguments.", + "explanation": "1. First, navigate to the given directory using the 'cd' command.\n2. Then, use the 'find' command to search for all files with the specified file extension.\n3. Use the 'wc' and 'stat' commands to calculate the sizes of the individual files.\n4. Finally, use the 'awk' command to sum up the sizes of all files.", + "create": { + "init": "\nmkdir -p problem_dir/sub1/sub2\necho \"This is a test file\" > problem_dir/testfile1.txt\necho \"This is another test file\" > problem_dir/sub1/testfile2.txt\necho \"This is the third test file\" > problem_dir/sub1/sub2/testfile3.txt\necho \"This is a PDF file\" > problem_dir/sub1/sub2/testfile4.pdf" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "cd problem_dir\nfind . -type f -iname \"*.txt\" -exec stat -c\"%s\" {} \\; | awk '{total=total+$1} END {print total}'" + } + }, + { + "description": "Design a problem that challenges students to count the number of lines containing the word \"error\" in all files with the extension \".log\" in the current directory (excluding subdirectories). Count only lines where \"error\" appears and is not part of another word. For example, \"errors\" should not be counted. The output should be an integer.", + "explanation": "To solve this problem, students need to use various Linux commands to filter and count lines containing the word \"error\" in the specified files. They can use commands like grep, find, wc, and xargs to achieve this.\n\nHint: Students may want to combine the grep and find commands with xargs to filter the appropriate files and lines.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the necessary log files for the experiment\necho \"Error on line 1\" > file1.log\necho \"Correct on line 2\" >> file1.log\necho \"error on line 3\" >> file1.log\necho \"errors on line 4\" >> file1.log\n\necho \"Log message without error\" > file2.log\necho \"Another error on line 2\" >> file2.log\necho \"Error in caps ERROR\" >> file2.log\n\necho \"No errors here\" > file3.log\necho \"error error\" >> file3.log\n\n# Create a non-log file for control\necho \"error non-log file\" > notlogfile.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# The following command can be used to get the standard answer\nfind . -maxdepth 1 -name '*.log' -print0 | xargs -0 grep -iw '\\' | wc -l" + } + }, + { + "description": "You are using a Linux operating system (Ubuntu), and your task is to find out the total number of processes that are using a specific user's UID.\n\nIn this exercise, you'll use standard Linux command-line utilities like 'ps', 'grep', and 'wc' to achieve this. Additionally, you will execute an initialization script that simulates an environment with a specific number of processes running as that specific user.\n\nYour answer should be an integer representing the total number of processes running as that user.", + "explanation": "To solve this problem, you have to first run the initialization script which will create a user and spawn a certain number of processes owned by that user. Next, you will use the 'ps' command to list out the processes along with their user IDs and filter the results with 'grep' to find only the processes running as our specific user. Lastly, you will count the number of lines using 'wc' to get the total number of processes running as that user.", + "create": { + "init": "\n#!/bin/bash\nUSERNAME=\"temp_student\"\nuseradd $USERNAME\nCOUNT=5\n\nfor i in $(seq 1 $COUNT); do\n sudo -u $USERNAME sleep 1000 &\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nps -eo user:30,command | grep \"^temp_student\" | wc -l" + } + }, + { + "description": "You are given a Linux file system with two directories named \"dir1\" and \"dir2\". Both directories contain a set of text files. Your task is to write a bash script to count the total number of lines in all the text files that reside in both \"dir1\" and \"dir2\". Please only consider the files with '.txt' extension.", + "explanation": "To solve this problem, you can use `find` command to locate '.txt' files in the given directories, and then use `wc` command with '-l' option to count the total number of lines in those files. Finally, sum the count of lines from both the directories.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p dir1 dir2\n\necho \"Hello world\" > dir1/file1.txt\necho -e \"This is a test\\nAdding more content\" > dir1/file2.txt\necho \"Another hello world\" > dir2/file3.txt\necho -e \"This is another test\\nAdding even more content\" > dir2/file4.txt\n\necho \"Initialization done.\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncount_dir1=$(find dir1 -iname \"*.txt\" -exec wc -l {} + | awk '{s+=$1} END {print s}')\ncount_dir2=$(find dir2 -iname \"*.txt\" -exec wc -l {} + | awk '{s+=$1} END {print s}')\n\ntotal_count=$((count_dir1 + count_dir2))\necho \"$total_count\"" + } + }, + { + "description": "You are given a task to monitor system usage in a Linux (Ubuntu) operating system. You are required to calculate the percentage of the available memory (in integers) that has been used on the system. To do this, you will first execute an initialization script to deploy the environment on each student's Linux system, and then execute a piece of code to produce an integer as the standard answer. Your task is to devise a problem, bash scripts for initialization, and an example script to calculate the used memory percentage.\n\nPlease keep in mind that the question description must be related to the Linux operating system and the output must only contain integers.", + "explanation": "To solve the problem, students should extract the total and free memory values from the 'free' command and calculate the used memory percentage with integers. An example bash script would parse this information and calculate the result.\n\nStudents might also want to explore the 'free' command and how to manipulate text output using tools like 'grep' and 'awk'.", + "create": { + "init": "\n#!/bin/bash\n# This script does not require any specific environment setup.\n# It simply demonstrates how to run the 'free' command, which is included in the Ubuntu system.\n# You can add more code here if required.\necho \"Environment initialized.\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n# Get 'free' command output, filter memory lines with 'grep' and extract total memory and free memory\ntotal_mem=$(free -m | grep Mem | awk '{print $2}')\nfree_mem=$(free -m | grep Mem | awk '{print $4}')\n\n# Calculate used memory percentage (integer)\nused_mem_percentage=$(( (total_mem - free_mem) * 100 / total_mem ))\n\n# Display the used memory percentage (integer) as output\necho \"${used_mem_percentage}\"" + } + }, + { + "description": "Your task is to calculate the total size of all files in a given directory, including files in its subdirectories, and return the total size in bytes. The given directory is `/home/user/experiment` which contains multiple subdirectories and files of different sizes.\n\nNOTE: You should not use any pre-built tools or commands to return the total directory size directly (e.g., `du`). You are required to find the size of each file individually and calculate the total sum. The answer must be an integer.", + "explanation": "To solve this problem, you can use the `find` command to list all the files recursively in the given directory. Then you can use `-exec` with `wc` or `stat` command to get the size of each file individually and parse the output to get the size in bytes. Finally, sum the sizes and output the result.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p /home/user/experiment/dir1/dir2\nmkdir -p /home/user/experiment/dir1/dir3\nmkdir -p /home/user/experiment/dir4\necho \"Hello World\" > /home/user/experiment/dir1/file1.txt\necho \"I am a programmer\" > /home/user/experiment/dir1/file2.txt\necho \"This is a script\" > /home/user/experiment/dir1/dir2/file3.txt\necho \"Linux is fun\" > /home/user/experiment/dir1/dir3/file4.txt\necho \"Operating systems are interesting\" > /home/user/experiment/dir4/file5.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind /home/user/experiment -type f -exec stat -c \"%s\" {} \\; | awk '{total+=$1} END {print total}'" + } + }, + { + "description": "In this problem, the students should calculate the total number of files and directories (recursive) in a given directory. The directory will be created and populated with files and directories by the initialization script. During the initialization, a specific environment variable `TARGET_DIR` will be set pointing to the created directory, which should be used by the students in their command.\n\nYou need to find the total number of files and directories (recursive) in the directory pointed by `TARGET_DIR`. Use the command line to achieve this and submit your answer as an integer. ", + "explanation": "To solve this problem, you can use the 'find' command to search for files and directories in the given directory. The 'wc' command can be used to count lines, which represent the number of files and directories found.\n\nHere is a hint on how you could structure your command using `find` and `wc`:\n\n```bash\nfind $TARGET_DIR -type f -o -type d | wc -l\n```\n\nThe above command searches for files and directories in the given target directory and counts the number of resulting lines.", + "create": { + "init": "\n#!/bin/bash\n# Create the target directory\nexport TARGET_DIR=$HOME/TA_problem\nmkdir -p $TARGET_DIR\n\n# Create sub-directories and files\nmkdir -p $TARGET_DIR/dir1\ntouch $TARGET_DIR/dir1/file1.txt\nmkdir -p $TARGET_DIR/dir1/dir2\ntouch $TARGET_DIR/dir1/dir2/file2.txt\ntouch $TARGET_DIR/dir1/dir2/file3.txt\nmkdir -p $TARGET_DIR/dir3\ntouch $TARGET_DIR/dir3/file4.txt\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find $TARGET_DIR -type f -o -type d | wc -l" + } + }, + { + "description": "In this experiment, you will be asked to find the number of lines for each type of file in a directory specified during the initialization step. You are required to find the count of lines for the following types of files: .txt, .csv, and .log. Your answer should be in the format of `TXT_COUNT CSV_COUNT LOG_COUNT`, separated by spaces.\n\nTo make it more challenging, you need to find the line count by only using a single command. You are allowed to use pipes to pass the output of one command to another if needed.\n\nMake sure not to count empty lines or lines that only contain whitespaces (spaces or tabs).", + "explanation": "To solve this problem, you can use the `find` command to search for files with specified extensions (.txt, .csv, and .log), then use the `grep` command to filter out empty lines or lines containing only whitespaces, and finally use the `wc` command to count the number of lines.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p experiment && cd experiment\necho -e \"Ubuntu\\nDebian\\nArch\\n\" > distros.txt\necho -e \"John,Doe,30\\nJane,Doe,28\\n\" > sample.csv\necho -e \"2022-01-01 14:34:21 [INFO] Server Started.\\n\" > server.log" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find . \\( -iname '*.txt' -o -iname '*.csv' -o -iname '*.log' \\) -exec cat {} + | grep -v '^$' | grep -v '^[[:space:]]*$' | wc -l" + } + }, + { + "description": "In this problem, you are required to count the total number of lines and the total number of words in all '*.txt' files in your current working directory. The output should be an integer value which calculates the sum of the total number of lines and the total number of words as a single integer.\n\nNote: Make sure to consider only '*.txt' files in the current working directory and ignore files in subdirectories.", + "explanation": "To solve this problem, you can use the `wc` command with the `-l` option to count the total number of lines and the `-w` option to count the total number of words in the '*.txt' files. To find and pass the '*.txt' files to the `wc` command, you can use the `find` command with the `-maxdepth` option.", + "create": { + "init": "\n#!/bin/bash\n\n# Create sample txt files for testing\necho \"This is a sample text file.\" > file1.txt\necho \"This txt file will be used as an example to test your code.\" > file2.txt\necho \"Please make sure to only count lines and words in '*.txt' files.\" > file3.txt\n\n# Create a sample subdirectory with a txt file\nmkdir subdir\necho \"This txt file should not be included in the count.\" > subdir/file4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Count total lines and words in all '*.txt' files in the current working directory\nfind . -maxdepth 1 -iname \"*.txt\" -exec wc -lw {} + | awk 'END {print $1 + $2}'" + } + }, + { + "description": "You have been given a task to analyze the file permissions of all the files in a specific directory. You need to calculate the sum of the octal file permissions of each file in the directory. Assume that there are no subdirectories, only regular files in the given directory.\n\nYour task is as follows:\n\n1. Create a directory called 'task_directory'.\n2. Create several files in 'task_directory' with random file permissions.\n3. Calculate the sum of the octal file permissions for all the files in 'task_directory'.", + "explanation": "Here's a step-by-step breakdown to solve the problem:\n\n1. Navigate to 'task_directory' using the `cd` command.\n2. Use the `stat` command (with the appropriate flags) to get the octal permissions of each file in the directory.\n3. Extract only the integer part of the file permissions using `cut` or `awk` command.\n4. Add all the permissions together using a loop or `paste` with the appropriate flags.\n\nYou can also use `find` command to get the list of files in the directory and calculate the sum directly, without navigating into the directory.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir task_directory\ncd task_directory\n\necho \"Simple text\" >file1.txt\necho \"Another example\" >file2.txt\necho \"Third file\" >file3.txt\n\nchmod 654 file1.txt\nchmod 711 file2.txt\nchmod 600 file3.txt\n\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\ncd task_directory\n\n# Get octal file permissions, extract the integer part, add them up\nsum=0\nfor file in *\ndo\n octal=$(stat -c '%a' \"$file\")\n sum=$((sum + octal))\ndone\n\n# Print the sum\necho $sum" + } + }, + { + "description": "In this problem, you are required to determine the total number of files and directories present in a given directory, as well as the total size (in kilobytes) of those files and directories within that given directory. The answer should be a single integer representing the summation of the total number of files, directories, and their total combined size in kilobytes. \n\nFor example, if there are 10 files and 5 directories, and the total combined size of those files and directories is 500 KB, the output would be 515.", + "explanation": "To solve this problem, you will need to use basic Linux commands such as `find`, `stat`, and `awk` to get the total number of files and directories and the combined size of those files and directories. You can then add these two values to get the final answer.\n\nFirst, use the `find` command to list all files and directories within the given directory. Then, use `stat` to get the size of each file and directory in bytes. After that, use `awk` to sum up the sizes and convert them to kilobytes. Finally, add the total number of files and directories to the total size in kilobytes.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p test_directory\ncd test_directory\necho \"Sample text file 1\" > file1.txt\necho \"Sample text file 2\" > file2.txt\nmkdir folder1\necho \"Sample text file 3\" > folder1/file3.txt\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncd test_directory\ntotal_files=$(find . -type f -or -type d | wc -l)\ntotal_size=$(find . -type f -exec stat -c\"%s\" {} \\; | awk '{sum+=$1} END {print int(sum/1024)}')\nresult=$((total_files + total_size))\necho \"$result\"" + } + }, + { + "description": "You are given a folder named \"log_folder\" containing log files from a server. These log files are named in the format \"log_YYYY-MM-DD.txt\" (for example, \"log_2022-10-01.txt\"). Your task is to find out the number of log files in the \"log_folder\" that were created exactly 30 days or more ago from the current date.", + "explanation": "To solve this problem, you'll have to perform the following steps:\n1. Find the current date and subtract 30 days to get the threshold date.\n2. Use a loop to iterate through all the files in \"log_folder.\"\n3. In each iteration, compare the date in the file name with the threshold date.\n4. If the date in the file name is less than or equal to the threshold date, increment the counter.\n5. Finally, print the counter as the output.\n\nHint: You can use \"date\" command to find the current date, and GNU 'date' '-d' argument to modify dates.", + "create": { + "init": "\nmkdir -p log_folder\ntouch log_folder/log_2022-05-01.txt\ntouch log_folder/log_2022-06-10.txt\ntouch log_folder/log_2022-07-05.txt\ntouch log_folder/log_2022-07-15.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nthreshold_date=$(date -d \"-30 days\" +'%Y-%m-%d')\ncounter=0\n\nfor file in log_folder/*.txt; do\n file_date=$(basename \"$file\" | awk -F_ -vOFS='-' '{print $2}' | awk -F. -vOFS='-' '{print $1}')\n if [[ \"$file_date\" < \"$threshold_date\" || \"$file_date\" == \"$threshold_date\" ]]; then\n counter=$((counter + 1))\n fi\ndone\n\necho $counter" + } + }, + { + "description": "As a Linux user, you are asked to calculate the total line count of all the \".txt\" files in a given directory, including its subdirectories. Note that you should only count the lines in the text files that contain at least one occurrence of a specified keyword.\n\nYou need to perform the following tasks:\n\n1. Write a Bash script to generate the directory structure with sample \".txt\" files.\n2. Write a Bash script to calculate the total line count as described.", + "explanation": "To solve this problem, you need to have a good understanding of the find command in Linux. You will use the find command to search for all \".txt\" files in the specified directory, including its subdirectories. Then, use grep to find lines containing the specified keyword and wc to count the number of lines.", + "create": { + "init": "\n#!/bin/bash\n\n# Set up the directory structure\nmkdir -p experiment\ncd experiment\necho \"Creating directories and .txt files\"\nmkdir -p folder1 folder2 folder3\necho \"This is a keyword test\" > folder1/file1.txt\necho \"This is not a keyword test\" > folder1/file2.txt\necho \"Another line\" >> folder1/file2.txt\necho \"Keyword\" > folder2/file3.txt\necho \"Testing keyword again\" > folder3/file4.txt\necho \"Keyword\" >> folder3/file4.txt\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Enter the created 'experiment' directory\ncd experiment\n\n# Check for the keyword\nkeyword=\"keyword\"\n\n# Find all the .txt files, filter for lines containing the keyword, and count the total number\nfind . -type f -name \"*.txt\" -exec grep -i -H \"$keyword\" {} \\; | wc -l" + } + }, + { + "description": "You have been given the responsibility to manage a list of files with specific naming conventions in your Linux operating system. To do this effectively, you need to perform the following tasks:\n\n1. Create a directory named \"file_analysis\" in the home directory.\n2. Inside the \"file_analysis\" directory, generate 100 text files named \"file-number.txt,\" where the number is replaced with their corresponding index in the range ", + "explanation": "To solve this problem, follow these steps:\n\n1. Create a directory using the `mkdir` command.\n2. Use a loop to create the files and write the index values.\n3. Use `grep`, `awk` or `sed` to filter odd indexed files and a loop to read the contents.\n4. Perform the arithmetic operation to calculate the sum.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the file_analysis folder in the home directory\nmkdir ~/file_analysis\n\n# Create 100 files within the file_analysis folder\nfor i in {1..100}; do\n echo $i > ~/file_analysis/file-$i.txt\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Initialize the sum\nsum=0\n\n# Calculate the sum of odd indexed files\nfor i in {1..100..2}; do\n num=$(cat ~/file_analysis/file-$i.txt)\n sum=$((sum + num))\ndone\n\n# Output the sum as a single integer\necho $sum" + } + }, + { + "description": "In this task, you need to find the total number of files and directories in a given directory, excluding the directory itself and hidden files or directories (files or directories that start with a dot, `.`). To complete this task, you will be provided with an initialization script that sets up the directory, and your goal is to return an integer value representing the total number of non-hidden files and directories within that directory.", + "explanation": "To solve this problem, you can use various Linux commands and utilities such as `ls`, `grep`, and `wc`. You can use `ls` to list all the files and directories in the specified directory, and then use `grep` to filter out the hidden files or directories. Finally, you can use `wc` to count the remaining lines to get the total number of non-hidden files and directories.", + "create": { + "init": "\n#!/bin/bash\nmkdir experiment_directory\ntouch experiment_directory/file1.txt\ntouch experiment_directory/file2.txt\ntouch experiment_directory/.hidden_file.txt\nmkdir experiment_directory/dir1\nmkdir experiment_directory/dir2\nmkdir experiment_directory/.hidden_dir" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nls -l experiment_directory | grep -v \"^d\\| \\.\" | wc -l" + } + }, + { + "description": "As a student, you must calculate the total number of bytes used by all the \".txt\" files in a given directory. This directory is created and filled with files using an initialization script. To solve this problem, you need to use the Linux command line tools in your Ubuntu operating system. After calculating the total number of bytes, submit your answer as an integer value.", + "explanation": "To solve this problem, you should:\n\n1. Use the `find` command to filter and find all the \".txt\" files in the directory.\n2. Use the `xargs` command to pass the list of files to another command (in this case, `du` command).\n3. Use the `du` command with the `-b` flag to get the byte size of each file.\n4. Use the `awk` command to sum the sizes of each file.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir problem_directory\ncd problem_directory\n\necho \"Hello, World!\" > file1.txt\necho \"Linux is awesome!\" > file2.txt\necho \"This is a test file.\" > file3.txt\necho \"Have a productive day!\" > file4.txt\necho \"Random string 12345\" > file5.txt\n\ntouch not_included1.pdf\ntouch not_included2.doc\n\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find problem_directory -type f -name \"*.txt\" | xargs du -b | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a Linux system administrator, you need to monitor the system regularly to ensure it runs smoothly. You have been given a task to collect information on the total generated system load in your Linux (Ubuntu) operating system. The total generated system load is based on three main factors: the number of running processes, the amount of used memory, and the percentage of used disk space.\n\nFor this task, you are to write a shell command that combines the three factors as outlined below:\n\n1. Compute the number of running processes. This excludes kernel threads and system processes.\n2. Calculate the percentage of used memory (excluding buffers/cache).\n3. Calculate the percentage of used disk space on the root (/) partition.\n\nLastly, return the sum of the three factors as a single integer.", + "explanation": "To solve the problem, you can use multiple shell commands to collect the required data and then combine the output into a single value. The following commands can be used to get the individual factors:\n\n1. Use `ps -e -o user | grep -v \"root\" | wc -l` to obtain the number of running processes.\n2. Use `free | grep Mem | awk '{print int(($3-$7)/$2 * 100)}'` to calculate the used memory percentage.\n3. Use `df -h | grep \"/$\" | awk '{print int($5)}'` to get the used disk space percentage on the root partition.\n\nCombine these commands to calculate the final total system load as an integer.", + "create": { + "init": "\n#!/bin/bash\n# No initial setup required for this problem, as it uses default system tools." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nrunning_processes=$(ps -e -o user | grep -v \"root\" | wc -l)\nused_memory_percent=$(free | grep Mem | awk '{print int(($3-$7)/$2 * 100)}')\nused_disk_space_percent=$(df -h | grep \"/$\" | awk '{print int($5)}')\n\ntotal_system_load=$((running_processes + used_memory_percent + used_disk_space_percent))\necho $total_system_load" + } + }, + { + "description": "You have been provided with a directory named \"sample_files\" containing text files. These text files represent server logs, with each line representing an entry. Your task is to count the total number of unique IP addresses present across all the log files in the \"sample_files\" directory.\n\nNote: The log files follow the format, `", + "explanation": "To solve this problem, you can use a combination of command-line tools like grep, sed, and awk to extract the IP addresses from the log files. Then, count the unique IP addresses using the sort and uniq commands.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p sample_files\ncd sample_files\n\ncat < server_log1.txt\n[2022-01-01 12:56:47] 192.168.1.0 Something happened\n[2022-01-02 14:34:12] 192.168.1.1 Another thing happened\n[2022-01-03 10:20:38] 192.168.1.0 What just happened\nEOF\n\ncat < server_log2.txt\n[2022-01-04 15:14:59] 192.168.1.2 Nothing happened\n[2022-01-05 08:23:07] 192.168.1.1 Something happened again\nEOF" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncd sample_files\ngrep -oP '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}' *.txt | sort | uniq | wc -l" + } + }, + { + "description": "You are given a directory named \"logs\" containing multiple log files. Each file represents logs generated per day. The filename format is \"log_YYYY-MM-DD.txt\". Your task is to count the occurrences of the word \"error\" (case insensitive) in the log files and sum the errors in all log files.\n\nTo complete this task, perform the following steps:\n\n1. Create a directory named \"logs\".\n2. Create log files for the past 7 days inside the \"logs\" directory. The content of each log file should have random \"error\"/\"Error\" entries along with other content.\n3. Use Linux command(s) to calculate the total count of \"error\" (case insensitive) occurrences in all the log files inside the \"logs\" directory.\n\nYour final answer should be the total count of \"error\" occurrences as an integer.", + "explanation": "To solve this problem, you can use the `grep` command to search for the keyword \"error\" in the log files. You can use the `-i` flag to perform a case-insensitive search, and the `-o` flag to print each match individually. Then, use `wc -l` to count the number of matches. Finally, sum the count of matches for all log files.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p logs\nfor i in {1..7}\ndo\n filename=\"log_$(date -d \"-$i days\" +\"%Y-%m-%d\").txt\"\n FILE_PATH=logs/$filename\n touch $FILE_PATH\n for j in {1..30}\n do\n if [ $((RANDOM % 5)) -eq 0 ]\n then\n echo \"Error: something went wrong\" >> $FILE_PATH\n else\n echo \"Debug: this is a debug message\" >> $FILE_PATH\n fi\n done\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ntotal_errors=0\n\nfor file in logs/*.txt\ndo\n count=$(grep -i -o \"error\" $file | wc -l)\n total_errors=$((total_errors + count))\ndone\n\necho $total_errors" + } + }, + { + "description": "As a student, you are given a Linux directory named \"student_data\" containing multiple text files which represent various students' data. Each file contains a student's ID number, a space, and their test scores in three subjects (Math, Science, and English) separated by spaces.\n\nThe format of the content inside the file is as follows:\n\n```\nID_Number Math_Score Science_Score English_Score\n```\n\nPlease provide the sum of the average scores of each subject rounded down to the nearest integer for all students in the \"student_data\" directory.", + "explanation": "To solve the problem, you will first navigate to the \"student_data\" directory and then iterate over each file, reading the scores for each subject. You will store the scores in an array and calculate the sum of the average scores for each subject. Use 'awk' to process the text inside the files and extract the scores for each student. Then calculate the sum of the average scores for each subject and output it as an integer.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir student_data\necho \"1001 84 90 91\" > student_data/student1.txt\necho \"1002 76 89 98\" > student_data/student2.txt\necho \"1003 88 74 80\" > student_data/student3.txt\necho \"1004 92 88 89\" > student_data/student4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\ncd student_data\n\nsum_math_scores=0\nsum_science_scores=0\nsum_english_scores=0\ntotal_students=0\n\nfor file in *.txt; do\n math_score=$(awk '{print $2}' \"$file\")\n science_score=$(awk '{print $3}' \"$file\")\n english_score=$(awk '{print $4}' \"$file\")\n \n sum_math_scores=$((sum_math_scores + math_score))\n sum_science_scores=$((sum_science_scores + science_score))\n sum_english_scores=$((sum_english_scores + english_score))\n total_students=$((total_students + 1))\ndone\n\navg_math_score=$((sum_math_scores / total_students))\navg_science_score=$((sum_science_scores / total_students))\navg_english_score=$((sum_english_scores / total_students))\n\nsum_avg_scores=$((avg_math_score + avg_science_score + avg_english_score))\necho $sum_avg_scores" + } + }, + { + "description": "In this problem, you are asked to calculate the total size (in kilobytes) of all regular files in a given directory in your Ubuntu operating system. The directory will be named 'test_directory' and will be located in the home folder. The directory will contain multiple regular files and subdirectories. You only have to calculate the size of regular files in the \"test_directory\" and ignore the files inside subdirectories.\n\nTo summarize, you must perform the following tasks:\n\n1. Navigate to the 'test_directory' located in your home folder.\n2. Calculate the total size (in kilobytes) of all regular files in the 'test_directory' (ignoring the files inside subdirectories).", + "explanation": "To solve this problem, you can use the 'find' command to list all regular files in the 'test_directory'. Then, use the 'wc' and 'du' commands to count the number of files and calculate the total size (in kilobytes) of all regular files.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p ~/test_directory/subdir\necho \"This is a test file.\" > ~/test_directory/file1.txt\necho \"This is another test file.\" > ~/test_directory/file2.txt\necho \"This is a file inside a subdirectory.\" > ~/test_directory/subdir/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find ~/test_directory -type f -maxdepth 1 -print0 | xargs -0 du -ck | awk 'END{print $1}'" + } + }, + { + "description": "You are given a directory called \"reports\". Inside the directory \"reports\", there are many text files, each containing one line with an integer value. You need to calculate the sum of all integer values from all these text files, and output the result as an integer.\n\nIn summary, your task is to:\n\n1. Enter the \"reports\" directory.\n2. Read all the text files inside the \"reports\" directory.\n3. Calculate the sum of integer values inside each text file.\n4. Output the final sum as an integer.", + "explanation": "To solve this problem, you will use various Linux commands such as cd, find, and xargs. You will change your current directory to \"reports\", then use the find command to list all text files (*.txt) inside the directory. Next, you'll use xargs command along with cat command to read the integer values inside each text file. Finally, you'll use awk command to sum up the values and print the result.", + "create": { + "init": "\n#!/bin/bash\n\n# Remove any previously created 'reports' directory just in case\nrm -rf reports\n\n# Create a 'reports' directory, enter it, and create text files with integer values\nmkdir reports\ncd reports\n\necho 15 > report1.txt\necho 10 > report2.txt\necho 5 > report3.txt\necho 20 > report4.txt\necho 50 > report5.txt\necho -10 > report6.txt\n\n# Move back to the parent directory\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Change the current directory to 'reports'\ncd reports\n\n# List all the text files in the reports directory\n# Read the integer values from the text files\n# Sum up all the values and print the result\nfind . -type f -name '*.txt' | xargs cat | awk '{sum+=$1} END{print sum}'\n\n# Output: 90" + } + }, + { + "description": "You are given a directory named 'logs' in your Linux operating system, which contains multiple log files for various days. Each log file has a specific naming format such as \"YYYY-MM-DD.log\". Your task is to count the total number of log files for a particular month provided to you in the format 'YYYY-MM' and return the count as an integer.\n\nFollow these steps:\n\n1. In your Linux (ubuntu) operating system, run the initialization bash script to create the \"logs\" directory with sample log files.\n2. Write a bash script that takes the 'YYYY-MM' as input, counts the total number of log files for that particular month, and returns the count as an integer.", + "explanation": "To solve the problem, you can use Linux commands such as 'find', 'grep', and 'wc' to filter out the log files for the specific month and count them.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p logs\n\nfor month in {1..12}; do\n for day in {1..31}; do\n touch \"logs/2021-$(printf '%02d' $month)-$(printf '%02d' $day).log\"\n done\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Function to count log files for the given month\nfunction count_log_files () {\n input_month=$1\n find logs -type f -name \"*$input_month*.log\" | grep -E \"^logs/[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}\\.log$\" | wc -l\n}\n\n# Set input_month as '2021-01' for demonstration \ninput_month=\"2021-01\"\n\n# Call the function\ncount_log_files $input_month" + } + }, + { + "description": "The objective of this problem is to make you familiar with the Linux file system and various commands to interact with it. As a student, you need to count the number of files and directories inside a given directory and calculate the sum of their sizes in bytes using shell commands. The output should be the sum of the sizes (in bytes) of all files and directories inside the given directory 'test_directory'.\n\nThe task consists of the following steps:\n\n1. Create a directory called 'test_directory'.\n2. Inside 'test_directory', create 'n' subdirectories, where 'n' is a random number between 3 and 7.\n3. Inside each subdirectory, create 'm' files, where 'm' is a random number between 4 and 10. Each file should contain random alphanumeric strings.\n4. Calculate the sum of the sizes of all files and directories inside 'test_directory' using shell commands.", + "explanation": "1. First, create the 'test_directory' and then generate the random number of subdirectories and files.\n2. You may use commands such as 'find', 'wc', and 'du' for finding file sizes and counting them.\n3. To calculate the sizes of all files and directories, combine the results of the find command using '|', and then sum up the sizes using 'awk'.", + "create": { + "init": "\n#!/bin/bash\nmkdir test_directory\ncd test_directory\nnumber_of_dirs=$((RANDOM % 5 + 3))\nfor ((d = 1; d <= number_of_dirs; d++))\ndo\n mkdir \"subdir_$d\"\n cd \"subdir_$d\"\n number_of_files=$((RANDOM % 7 + 4))\n for ((f = 1; f <= number_of_files; f++))\n do\n touch \"file_$f\"\n echo \"$(cat /dev/urandom | tr -cd '[:alnum:]' | head -c $((RANDOM % 20 + 10)))\" > \"file_$f\"\n done\n cd ..\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind test_directory -type f -exec du -b {} + | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a student, you are tasked to retrieve the number of lines of code in Python files within a specific directory and all its subdirectories. The directory has been provided to you by the initialization script and contains numerous Python files with the extension `.py`.\n\nYour task is to find the total number of lines of code across all the Python files contained in the provided directory and all its subdirectories.\n\n_Note: Ignore any empty lines. Only count lines with actual code._", + "explanation": "To solve this problem, you will need to use some Linux command-line utilities such as `find`, `grep`, `wc`, and `xargs`. You first need to find all the `.py` files within the specified directory and its subdirectories. Then, you'll use `grep` to ignore empty lines while counting the lines of code.\n\nHere's a rough breakdown of the steps:\n1. Use the `find` command to search for .py files in the directory.\n2. Use the `xargs` command to process the files found in step 1.\n3. Use `grep` to exclude empty lines.\n4. Finally, use `wc` to count the lines of code in each file and sum them up.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p question_directory/subdir1\nmkdir -p question_directory/subdir2\n\ntouch question_directory/file1.py\ntouch question_directory/file2.py\ntouch question_directory/subdir1/file3.py\ntouch question_directory/subdir1/file4.py\ntouch question_directory/subdir2/file5.py\n\necho -e \"import os\\n\\n#print('Hello world')\\n\" > question_directory/file1.py\necho -e \"def add(x, y):\\n return x + y\" > question_directory/file2.py\necho -e \"# This is an empty python file\" > question_directory/subdir1/file3.py\necho -e \"import sys\\n\\nif __name__ == '__main__':\\n print(sys.argv)\" > question_directory/subdir1/file4.py\necho -e \"def multiply(x, y):\\n\\n return x * y\\n\" > question_directory/subdir2/file5.py" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find question_directory -type f -name \"*.py\" | xargs grep -vE '^$|^#' | wc -l" + } + }, + { + "description": "This problem is designed to test your ability to navigate and manipulate files and directories using Linux command line tools. You have been supplied with an Ubuntu operating system.\n\nThere is an initialization bash script that will set up the required environment and files. Your task is to determine the total number of occurrences of a specific word across all '.txt' files in a specific directory.\n\nYou need to perform the following steps:\n\n1. Execute the initialization bash script to set up the required environment.\n2. Navigate to the 'target_directory', which will be created during initialization.\n3. Execute a command that will help you count the total occurrences of the word 'linux' (case insensitive) in all the '.txt' files inside the 'target_directory'.\n4. The output of the command should be a single integer - the total number of occurrences of the word 'linux'.", + "explanation": "To solve the problem:\n\n1. First, execute the initialization script to set up the environment required.\n2. Once the environment is set up, navigate to the 'target_directory'.\n3. Use the 'grep' command to search for the word 'linux' in all '.txt' files, combined with 'wc -l' to count occurrences.", + "create": { + "init": "\n#!/bin/bash\n\n# Create target_directory and files for the problem\nmkdir -p target_directory\necho 'This linux is a popular operating linux system.' > target_directory/file1.txt\necho 'Linux is basically everywhere, especially in servers.' > target_directory/file2.txt\necho 'Linux is reliable and linux secure.' > target_directory/file3.txt\necho 'Linux distributions like Ubuntu, Arch, and Fedora are popular.' > target_directory/file4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Change the working directory to target_directory\ncd target_directory\n\n# Run the grep command to search for the word 'linux' (case insensitive) and count occurrences using wc -l\ngrep -i -o -r 'linux' . --include='*.txt' | wc -l" + } + }, + { + "description": "You are given a directory named `example_files` containing text files with random alphabetic strings and integers in each line. Your task is to calculate the total sum of integers in all the files in the `example_files` directory. Note that you should not consider any number that contains both integers and alphabetic characters. \n\nFor example, if a file contains:\n\n```\nabc\n3\n4hj\n5\n```\n\nOnly consider `3` and `5`. The sum for this file would be `8`.", + "explanation": "To solve the problem, you can use a combination of shell commands:\n\n1. Use the `find` command to get all the files in the `example_files` directory.\n2. Use a loop to read through each file content with the `cat` command.\n3. Use `grep` to filter lines containing only integers.\n4. Calculate the sum using the 'awk' command.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p example_files\n\n# Create sample files with random strings and integers\necho \"abc\" > example_files/file1.txt\necho \"3\" >> example_files/file1.txt\necho \"4hj\" >> example_files/file1.txt\necho \"5\" >> example_files/file1.txt\n\necho \"5\" > example_files/file2.txt\necho \"2\" >> example_files/file2.txt\necho \"9\" >> example_files/file2.txt\necho \"3\" >> example_files/file2.txt\n\necho \"xyz\" > example_files/file3.txt\necho \"12gh\" >> example_files/file3.txt\necho \"34\" >> example_files/file3.txt\necho \"56\" >> example_files/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nsum=0\n# Step 1: Find the files in the directory\nfiles=$(find example_files -type f)\n\n# Step 2-4: Loop through the files, filter lines with only integers and calculate the sum\nfor file in $files\ndo\n file_sum=$(cat \"$file\" | grep -E '^[0-9]+$' | awk '{s+=$1}END{print s}')\n sum=$((sum + file_sum))\ndone\n\n# The output must contain only integers\necho $sum" + } + }, + { + "description": "As a student, you are given a task to determine the number of directories, subdirectories and files in a specific directory. You need to write a shell script that will return the exact number of directories, subdirectories and files, excluding the parent directory and the current directory. The final answer should be a single integer (the sum of all directories, subdirectories, and files).\n\nTo ensure that everyone is working with the same directory structure, an initialization script has been provided. Execute this script to create the necessary directory structure and files for the problem.\n\nNote: The problem should be solved using the Linux operating system.", + "explanation": "To solve this problem, you can use the 'find' command to search for all directories, subdirectories, and files in the current directory. The 'find' command allows you to search for files and directories based on various criteria, such as their type or name.\n\nUse the '-type d' option to find directories, and '-type f' option to find files. Then, count the total number of returned items with the help of 'wc -l'.\n\nA hint for your script: You can use command substitution with the '$()' notation to calculate the sum of directories, subdirectories, and files. Make sure to add an integer as the final answer.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the necessary directory structure and files\nmkdir -p problem_directory/dir{1..3}\nmkdir -p problem_directory/dir1/subdir{1..2}\nmkdir -p problem_directory/dir2/subdir{3..4}\nmkdir -p problem_directory/dir2/subdir3/nestedsubdir{1..2}\ntouch problem_directory/dir1/file_{a..c}.txt\ntouch problem_directory/dir2/file_{d..f}.txt\ntouch problem_directory/dir3/file_{g..i}.txt\ntouch problem_directory/dir2/subdir4/file_{x..z}\n\ncd problem_directory" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Count directories, subdirectories, and files\ndir_count=$(find . -type d | wc -l)\nfile_count=$(find . -type f | wc -l)\n\n# Subtract 1 to exclude the parent directory\ndir_count=$((dir_count - 1))\n\n# Calculate the total items\ntotal_items=$((dir_count + file_count))\n\n# Print the final integer output\necho $total_items" + } + }, + { + "description": "As a student, you are required to find the total number of lines containing the word \"Linux\" in all text files (*.txt) within a specific directory and its subdirectories. You are given the path to the directory as an input. Your answer should only contain an integer, representing the total number of lines containing the word \"Linux\".", + "explanation": "To solve this problem, you should be familiar with the Linux commands, such as 'grep', 'find', and 'wc'. \n\n1. Use the 'find' command to search for all the text files (*.txt) in the given directory and its subdirectories.\n2. Use 'grep' with the '-c' flag, which returns the number of lines containing the match, to find the lines containing the word \"Linux\".\n3. Use 'wc' with the '-l' flag to count the total number of lines from the output of the previous commands.", + "create": { + "init": "\n#!/bin/bash\n\n# Create a directory named \"linux_problem\" if it doesn't exist\nmkdir -p linux_problem\n\n# Change the current directory to \"linux_problem\"\ncd linux_problem\n\n# Create text files with random content and the word \"Linux\" included\necho \"This is a file about Linux\" > file1.txt\necho \"Another line about Linux\" >> file1.txt\necho \"Linux is an open-source operating system\" > file2.txt\necho \"This line does not have the word\" > file3.txt\necho -e \"A file with multiple lines\\nLinux is everywhere\\nEven here: Linux\" > file4.txt\n\n# Create a subdirectory named \"subdir\"\nmkdir -p subdir\n\n# Create text files in the subdirectory\necho \"More about Linux in subdir\" > subdir/file5.txt\necho \"We have two lines of Linux here\\nLinux is cool\" > subdir/file6.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Change the current directory to \"linux_problem\"\ncd linux_problem\n\n# Find all the text files in the current directory and its subdirectories,\n# then use 'grep' to count lines with the word \"Linux\", and finally use 'wc'\n# to count the total number of lines from the output\nfind . -name \"*.txt\" -exec grep -c \"Linux\" {} \\; | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a student, your task is to find out how many hidden directories are in your home directory and your current working directory. Note that a hidden directory starts with a dot ('.').", + "explanation": "To solve this problem, the student needs to use the `ls` command with the `-a` flag to list all files and directories, including hidden ones, then use `grep` with a regular expression to find the hidden directories, and finally use `wc` to count them.", + "create": { + "init": "\n#!/bin/bash\ncd ~\nmkdir -p .hidden-dir1 .hidden-dir2 visible-dir1\ncd visible-dir1\nmkdir -p .hidden-dir3 visible-dir2" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nnum_hidden_home=$(ls -a ~ | grep -E '^\\.+' | grep -vE '^\\.+$' | wc -l)\nnum_hidden_cwd=$(ls -a | grep -E '^\\.+' | grep -vE '^\\.+$' | wc -l)\necho $((num_hidden_home + num_hidden_cwd))" + } + }, + { + "description": "You've been given a server's log file named `server.log` containing timestamps of user login activities throughout the day in 24-hour format (e.g. \"23:40\"). Your task is to find the total number of logins that happened during the peak hours of 9:00 PM to 11:59 PM. \n\nCreate a script to count the number of logins during that time frame. The result should be printed, and contain only the integer representing the total number of logins during the peak hours.", + "explanation": "To solve this problem, you need to:\n\n1. Analyze the log file `server.log` using `grep` and regular expressions.\n2. Filter only the logins that occur between 9:00 PM and 11:59 PM.\n3. Count the total number of logins during the specified time frame.\n\nHint: You can leverage `grep` to search and filter lines containing timestamps within the desired time range.", + "create": { + "init": "\ncat << EOF > server.log\n9:15 Login Success\n9:30 Login Success\n13:00 Login Success\n23:20 Login Success\n23:40 Login Success\n1:59 Login Success\nEOF" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "cat server.log | grep -E '^(21|22|23):..' | wc -l" + } + }, + { + "description": "As a student, you are requested to find the total number of files and directories inside a specific directory, including its subdirectories. The output should be an integer representing the total count without any extra information. The given directory will be named \"project_directory\".", + "explanation": "You are supposed to use standard Linux commands available in an Ubuntu operating system. You will require 'find' command to search for all files and directories inside the given directory and its subdirectories. Then, you will pipe the output to the 'wc' command with the \"-l\" flag to count the number of lines, which reflects the total count of the files and directories. You will also need to hide any possible error message from the output.", + "create": { + "init": "\n#!/bin/bash\n\n# Create a directory with a specific structure\nmkdir -p project_directory/subdir1/subdir1_1\nmkdir -p project_directory/subdir1/subdir1_2\nmkdir -p project_directory/subdir2/subdir2_1\nmkdir -p project_directory/subdir3\n\n# Add some files\ntouch project_directory/file1.txt\ntouch project_directory/subdir1/file2.txt\ntouch project_directory/subdir1/subdir1_1/file3.txt\ntouch project_directory/subdir1/subdir1_2/file4.txt\ntouch project_directory/subdir2/file5.txt\ntouch project_directory/subdir2/subdir2_1/file6.txt\ntouch project_directory/subdir3/file7.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find project_directory -type f -o -type d 2>/dev/null | wc -l" + } + }, + { + "description": "In this problem, you need to find the number of non-empty lines in a log file, which contains records of various system activities. First, you will initialize a log file named `system_logs.txt` with random content, then you will write a program in the Linux (Ubuntu) operating system to count the number of non-empty lines. The result should be an integer.", + "explanation": "1. Create a log file named `system_logs.txt` with random content.\n2. Use a Linux command to calculate the number of non-empty lines in `system_logs.txt`.\n3. Print the output as an integer, which shows the number of non-empty lines in the log file.", + "create": { + "init": "\n# Randomly generate a log file system_logs.txt\ncat /dev/urandom | tr -dc 'a-zA-Z0-9!@#$%^&*()_+-=[]{}|;:\",.<>/?\\` ~\\n' | head -c 5000 > system_logs.txt\n# Add some empty lines to system_logs.txt\nfor i in {1..20}; do\n if (( $i % 3 == 0 )); then\n sed -i \"${i}s/$/\\n/\" system_logs.txt\n fi\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Find the number of non-empty lines in system_logs.txt and print the result\ngrep -c -v \"^$\" system_logs.txt" + } + }, + { + "description": "As a student, you are given a directory that contains several subdirectories. Each subdirectory contains a few text files. Your task is to find the total number of lines in all text files combined, and submit it as the answer. It is crucial to ensure you only count the lines from text files (.txt) and ignore other file types. Use the built-in Linux commands to achieve this.", + "explanation": "To solve this problem, you can use the 'find' command to search for .txt files within the given directory and its subdirectories. Then, use 'wc -l' to count the total lines of the found .txt files, and 'awk' to sum up the line counts for each file. Finally, display the total sum as an integer output.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p ~/student_directory/dir1\nmkdir -p ~/student_directory/dir2\necho \"Line 1\" > ~/student_directory/dir1/file1.txt\necho \"Line 1\" > ~/student_directory/dir1/file2.txt\necho \"Line 1\" > ~/student_directory/dir1/not_text_file.sh\necho \"Line 1\" > ~/student_directory/dir2/file3.txt\necho \"Line 1\" > ~/student_directory/dir2/file4.txt\necho \"Line 1\" > ~/student_directory/dir2/file5.txt\nchmod -R 755 ~/student_directory" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find ~/student_directory -type f -name \"*.txt\" -exec wc -l {} \\; | awk '{ total += $1 } END { print total }'" + } + }, + { + "description": "You are given a folder named 'files' containing several text files. You have to find the total sum of all the integers present across all the text files. Integers can be positive or negative and may be more than one per line. The integers are separated by whitespace or special characters. ", + "explanation": "To solve this problem, you can follow these steps:\n1. Go to the 'files' folder.\n2. Use a loop to read the content of each file.\n3. Extract integers from the content using Regular Expressions (you can use 'grep' command to do this).\n4. Add all extracted integers in every file and calculate the overall sum.", + "create": { + "init": "\n#!/bin/bash\nmkdir files\necho \"5, 3 2\" > files/file1.txt\necho \"One million, Two thousand = 100^-1 -88\" > files/file2.txt\necho \"Bubble Sort is O(n^2) -17 -6\" > files/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncd files\nsum=0\n# Read all files in folder\nfor file in $(ls) ; \ndo\n # Extract integers from each file and add them to the sum\n for number in $(grep -o -E '[-+]?[0-9]+' $file) ; \n do\n sum=$(($sum + $number))\n done\ndone\n# Print the total sum of integers\necho $sum" + } + }, + { + "description": "As a student, you are tasked with determining the number of directories and subdirectories in a given directory tree, specifically in the `/var/log` directory on an Ubuntu Linux operating system. Your task must be performed entirely through the command line using provided Linux tools.\n\nYou are required to write a shell script that will count the number of directories, both direct and nested, in the `/var/log` directory and output the total number in the form of an integer.", + "explanation": "In order to solve this problem, you can use the `find` command, which is a powerful tool for searching files and directories in Linux. You can use various flags and expressions with `find` to filter the search based on criteria like name, type and time.\n\nTo count the number of directories in `/var/log`, you can use the following command:\n\n```bash\nfind /var/log -type d | wc -l\n```\n\nHere, the `find` command searches for items in the `/var/log` directory which are of type `d` (directories). The output of the find command is then piped ('|') to the `wc -l` command, which counts the number of lines in the output - and therefore, the number of directories.", + "create": { + "init": "\n#!/bin/bash\necho \"Initialization successful. Proceed with the task.\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind /var/log -type d | wc -l" + } + }, + { + "description": "As a Linux system administrator, you need to monitor the disk usage of the `/home` directory because it is very important to ensure that the system runs smoothly. You have to determine the total number of files with the `.log` extension that are larger than 500 KB in size within the `/home` directory and its subdirectories.\n\nTo solve this problem, you need to do the following:\n\n1. Execute an initialization bash script to create the required environment for the problem in each student's Linux (Ubuntu) operating system.\n2. Write a script that will output a single integer - the total number of `.log` files larger than 500 KB in the `/home` directory and its subdirectories.", + "explanation": "To solve this problem, you can use `find` command to search for the files with the `.log` extension larger than 500 KB in the `/home` directory and its subdirectories. You can then pass the results through `wc -l` command to count the number of files. ", + "create": { + "init": "\n#!/bin/bash\nmkdir -p /home/testdir{1..3}\ntouch /home/testdir1/file{1..3}.log\ntouch /home/testdir2/file{4..6}.log\ntouch /home/testdir3/file{7..9}.log\n\ntruncate -s 300KB /home/testdir1/file1.log\ntruncate -s 600KB /home/testdir1/file2.log\ntruncate -s 550KB /home/testdir1/file3.log\ntruncate -s 400KB /home/testdir2/file4.log\ntruncate -s 200KB /home/testdir2/file5.log\ntruncate -s 700KB /home/testdir2/file6.log\ntruncate -s 800KB /home/testdir3/file7.log\ntruncate -s 500KB /home/testdir3/file8.log\ntruncate -s 250KB /home/testdir3/file9.log" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find /home -type f -name \"*.log\" -size +500k | wc -l" + } + }, + { + "description": "As a student, you are asked to find the total number of lines of code in all the \".c\" and \".h\" files in a given directory (including its subdirectories). The question will test your ability to navigate the Linux file system, use basic commands to filter and manipulate the data.\n\nTo complete the task, you should provide the total number of lines of code in the given folder containing \".c\" and \".h\" files.", + "explanation": "To solve the problem, you will need to use some Linux commands like find, xargs, and wc. You can use the 'find' command to find all the \".c\" and \".h\" files in the given directory and use 'wc' to count the total number of lines in these files. Remember that you should include all subdirectories when searching for files.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p test_directory\ncd test_directory\nmkdir -p subdir1 subdir2 subdir2/subsubdir\necho \"int main() {}\" > program1.c\necho \"void func() {}\" > subdir1/program2.c\necho \"struct example {};\" > subdir2/program3.h\necho \"int hello() {}\" > subdir2/subsubdir/program4.c\necho \"#include \" > includes.h" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind . -type f \\( -iname \\*.c -o -iname \\*.h \\) -print0 | xargs -0 wc -l | awk '{total_lines += $1} END {print total_lines}'" + } + }, + { + "description": "A company stores their employee information in the form of text files in a folder called 'employees'. Each employee has a file named {employee_id}.txt, and each file contains numbered tasks assigned to the respective employee. The tasks are labeled as either 'urgent' or 'normal', and the label is followed by a colon and a positive integer denoting the time it takes to complete the task (in minutes).\n\nThe folder 'employees' contains the following six files: 101.txt, 102.txt, 103.txt, 104.txt, 105.txt, and 106.txt. Your task is to find the total amount of time, in minutes, needed to complete all urgent tasks assigned to all employees. The final result should be a single integer, which is the sum of urgent task times.\n\nExample of task list in an employee's file:\n```\nurgent:30\nnormal:10\nurgent:20\nnormal:15\n```", + "explanation": "To solve the problem, you need to perform the following steps:\n\n1. List all files in the 'employees' folder.\n2. Extract all urgent tasks by using 'grep' and filtering for lines that start with 'urgent:'.\n3. Extract the time values from the urgent tasks by using 'cut' or 'awk'.\n4. Calculate the sum of all extracted integers.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir employees\necho -e \"urgent:30\\nnormal:10\\nurgent:20\\nnormal:15\" > employees/101.txt\necho -e \"normal:20\\nurgent:40\\nnormal:10\\nurgent:15\" > employees/102.txt\necho -e \"normal:25\\nnormal:15\\nurgent:35\\nnormal:10\" > employees/103.txt\necho -e \"urgent:10\\nurgent:20\\nnormal:30\\nnormal:15\" > employees/104.txt\necho -e \"normal:35\\nnormal:20\\nurgent:25\\nurgent:15\" > employees/105.txt\necho -e \"normal:10\\nnormal:15\\nurgent:20\\nnormal:30\" > employees/106.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Calculate the sum of all urgent task times\ntotal_time=0\nfor file in employees/*.txt; do\n while read -r task; do\n time=$(echo $task | cut -d ':' -f 2)\n total_time=$((total_time + time))\n done < <(grep '^urgent:' \"${file}\")\ndone\n\necho $total_time" + } + }, + { + "description": "As a student, you are required to find the total number of regular files and directories inside a given folder (including sub-directories). The folder will be located in the home directory, named \"exp_folder\". You should write a bash script to count the number of regular files and directories separately and then output the sum of them.", + "explanation": "To solve this problem, you can use the `find` command to search for specific types of files or directories within the folder structure. By utilizing the type flag (`-type`) with `f` for regular files and `d` for directories, you can count each type individually. Afterwards, you will need to add both counts and output the final result.", + "create": { + "init": "\n#!/bin/bash\n\n# Create exp_folder in the home directory\nmkdir ~/exp_folder\n\n# Create subdirectories and files for the problem\nmkdir ~/exp_folder/dir1\nmkdir ~/exp_folder/dir2\ntouch ~/exp_folder/file1.txt\ntouch ~/exp_folder/file2.txt\ntouch ~/exp_folder/dir1/file3.txt\ntouch ~/exp_folder/dir1/file4.txt\ntouch ~/exp_folder/dir2/file5.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Find the number of regular files and directories within exp_folder\nfile_count=$(find ~/exp_folder -type f | wc -l)\ndir_count=$(find ~/exp_folder -type d | wc -l)\n\n# Calculate and print the total count\ntotal_count=$((file_count + dir_count))\necho $total_count" + } + }, + { + "description": "As a student, you need to determine the total occupied storage space by all the `.txt` files in a given directory to understand how much storage the text files are consuming. You will be given a directory named \"files_directory\" with several files of various extensions. Your task is to calculate the total size in kilobytes (KB) of all `.txt` files in the \"files_directory\" directory and return the result as an integer.", + "explanation": "To solve this problem, you will use the `find` command to locate all `.txt` files within the \"files_directory\" directory. Then, you can pipe the result to the `du` command and use its `-c` (total) parameter to sum the sizes of all located files. Finally, you may extract the integer value and display it. Remember to configure the `du` command to display the number in kilobytes.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p ~/files_directory\necho 'Hello, world!' > ~/files_directory/file1.txt\necho 'This is a test' > ~/files_directory/file2.txt\necho -e '1\\n2\\n3\\n4' > ~/files_directory/file3.txt\necho 'Linux operating system' > ~/files_directory/file4.txt\necho 'Sample files' > ~/files_directory/file5.txt\ntouch ~/files_directory/file6.html\ntouch ~/files_directory/file7.xml\ntouch ~/files_directory/file8.jpg" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind ~/files_directory -iname '*.txt' -exec du -ckB1 {} + | grep 'total' | cut -f1" + } + }, + { + "description": "You need to calculate the number of files and directories in the current user's home directory (excluding hidden files and directories) and multiply that by the number of non-empty text files (*.txt) within the current user's home directory.\n\nNote: You can assume that there are only ASCII characters in text files (*.txt).\n\nTo solve the problem, follow these steps:\n\n1. Calculate the number of (non-hidden) files and directories in the current user's home directory.\n2. Calculate the non-empty text files (*.txt) only in the current user's home directory.\n3. Multiply the result of step 1 with step 2.\n4. Output the final result.", + "explanation": "To solve this problem, you need to use a combination of the following Linux commands:\n\n1. `ls`: list directory contents\n2. `grep`: searches for a pattern in a file\n3. `wc`: prints the number of lines, words, and bytes in a file\n4. `find`: search for files in a directory based on the given expressions", + "create": { + "init": "\n#!/bin/bash\n\ncd ~\nmkdir -p \"test\"\ntouch \"example1.txt\" \"example2.txt\" \"example3.txt\"\necho \"abc\" > \"example1.txt\"\necho \"def\" > \"example3.txt\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\ncd ~\nnum_files_dirs=$(ls -l | grep -v '^d\\|^\\.' | wc -l)\nnum_non_empty_txt_files=$(find . -maxdepth 1 -name \"*.txt\" -type f -size +1c -printf '.' | wc -c)\n\nresult=$((num_files_dirs * num_non_empty_txt_files))\necho $result" + } + }, + { + "description": "As a student, you have been given the task of finding the total number of lines, within a specified set of text files, that contain a specific word. You will write a script using Linux (Ubuntu) shell commands to achieve this task. The specific word and the text files will be provided through an initialization script.", + "explanation": "To solve this problem, you'll need to use the following Linux shell commands:\n1. `grep`: To search for the pattern (specific word) in files.\n2. `wc`: To count the number of lines containing the pattern.", + "create": { + "init": "\n#!/bin/bash\n\n# Create three text files with some sample content\necho \"This is a test file.\nLinux is an open-source operating system.\nUbuntu Linux is widely used.\" > file1.txt\n\necho \"The world is beautiful.\nLinux operating system is efficient.\nLet's learn more about Ubuntu Linux.\" > file2.txt\n\necho \"Ubuntu is based on Debian Linux.\nWe love the Linux operating system.\nHave fun learning Linux.\" > file3.txt\n\n# Specify the word to search\necho \"Linux\" > search-word.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Read the word to search from the file\nsearch_word=$(cat search-word.txt)\n\n# Use grep to search for the word in the files,\n# count occurrences in each file,\n# sum the occurrences using awk\n# and display the result.\n\ngrep -c \"$search_word\" file{1..3}.txt | awk -F: '{sum += $2} END {print sum}'" + } + }, + { + "description": "As a student, you are requested to find out the total number of lines containing a specific word in all the \".txt\" files within a given directory. You will be given the word \"Linux\" and a directory named \"files-dir\" containing some \".txt\" files with random content. The output should be a single integer representing the total count of lines containing the word \"Linux\" in all the \".txt\" files.", + "explanation": "To solve this problem, you could use the following steps:\n\n1. Traverse through all the \".txt\" files in the \"files-dir\" directory.\n2. For each file, check the lines containing the word \"Linux\".\n3. Calculate the total count of lines containing the word \"Linux\" and output the result.\n\nHint: You might find commands like 'find', 'grep', and 'wc' helpful in solving this problem.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p files-dir\necho \"This is a Linux operating system.\" > files-dir/file1.txt\necho \"I like Linux a lot!\" >> files-dir/file1.txt\necho \"Hello, world!\" > files-dir/file2.txt\necho \"Linux is my favorite operating system.\" > files-dir/file3.txt\necho \"Linux is fun!\" > files-dir/file4.txt\necho \"I am using Ubuntu, which is based on Linux.\" >> files-dir/file4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind files-dir -name \"*.txt\" -exec grep -c 'Linux' {} \\; | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "The objective of this problem is to calculate the total number of occurrences of a specific word in the files inside a given directory. You will need to navigate through the Linux operating system, use shell commands and produce a single integer as output.\n\nHere is the detailed question description:\n\n1. You are given a directory named \"assignment\" in your home directory (`~/assignment/`).\n2. Inside the \"assignment\" directory, there are multiple files - both text and non-text.\n3. Your task is to find the total number of occurrences of the word \"Linux\" (case insensitive) in all the text files within this directory.", + "explanation": "You can solve the problem using the following steps:\n\n1. Navigate to the `~/assignment/` directory.\n2. Identify the text files (`.txt` extension) in the directory.\n3. Use commands like `grep`, `wc`, and a loop to iterate through the text files and count the occurrences of the word \"Linux.\"\n ", + "create": { + "init": "\nmkdir -p ~/assignment\necho \"This is a file about Linux.\" > ~/assignment/file1.txt\necho \"Linux is an open-source operating system.\" >> ~/assignment/file1.txt\necho \"Many developers use Linux for their work.\" > ~/assignment/file2.txt\ntouch ~/assignment/some_binary_file.bin\necho \"Linux can be configured to meet diverse requirements.\" > ~/assignment/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\ncd ~/assignment\ntotal_count=0\n\nfor file in *.txt; do\n count=$(grep -io \"Linux\" \"$file\" | wc -l)\n total_count=$((total_count + count))\ndone\n\necho $total_count" + } + }, + { + "description": "You are required to solve the following problem related to the Linux operating system. You need to calculate the total size (in bytes) of all the files with extension \".txt\" inside the \"example\" directory and its subdirectories. The answer should be an integer representing the sum of the sizes of all .txt files.", + "explanation": "To solve the problem, you will have to use several Linux shell commands such as `find`, `wc`, and `du`. You will find all the txt files and calculate their size, then sum up the sizes to get the answer. Here are some hints:\n\n1. Use the `find` command to locate all the \".txt\" files inside the \"example\" directory and its subdirectories.\n2. Use the `du` command to calculate the size of each file in bytes.\n3. Sum up the sizes by using a loop or an apposite command.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p example/sub1/subsub1\nmkdir -p example/sub2\n\necho \"Hello, this is a test file!\" > example/sub1/test1.txt\necho \"Another test file with some text.\" > example/sub1/subsub1/test2.txt\necho \"One more test file here!\" > example/sub1/subsub1/test3.txt\necho \"Final test file for you.\" > example/sub2/test4.txt\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Find all .txt files and calculate their size in bytes, then sum the sizes\nfind example/ -iname \"*.txt\" -exec du -b {} \\; | awk '{s+=$1} END {print s}'" + } + }, + { + "description": "As a student, you are to find the total number of lines in all the \".txt\" files that contains the word \"Linux\" in a specific directory (called \"experiment\") and its subdirectories. Create this directory with some \".txt\" files, and ensure that some of the files contain the word \"Linux\". Your final output should be the integer representing the total number of lines containing \"Linux\" in all .txt files.", + "explanation": "To solve this problem, the student should use the commands `find`, `grep`, `wc`, and pipes. The `find` command will help in locating all the .txt files in the specified directory, the `grep` command will filter out the lines containing \"Linux\" in the located files, and finally, the `wc` command will get the count of the resulting lines.\n\nHints:\n- Use 'grep -c' to count the occurrences of a string in a file.\n- Use 'find' to locate all .txt files in the specified directory.\n- Pipe the results together to get the final output.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p experiment/sub1\nmkdir -p experiment/sub2\n\necho -e \"Ubuntu\\nLinux\\nArch Linux\\nFedora\" > experiment/sub1/file1.txt\necho -e \"Debian\\nLinux Mint\" > experiment/sub1/file2.txt\necho -e \"Elementary OS\\nLinux\\nKali Linux\" > experiment/sub2/file3.txt\necho -e \"CentOS\\nRed Hat\\nPop!_OS\" > experiment/sub2/file4.txt\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind experiment -type f -name \"*.txt\" -exec grep -c \"Linux\" {} \\; | awk '{sum+=$1} END {print sum}'" + } + }, + { + "description": "In this problem, you will write a bash script that reads a text file containing a list of file names, one name per line. The text file will be placed in a newly created directory. The script should fetch the total number of lines containing a specified file extension (e.g., \".txt\"). You may assume that file names are alphanumeric, and the file extension will have a period followed by 3 lowercase letters.\n\nHere is a brief description of the tasks:\n\n1. Create a new directory named \"files_list\".\n2. Create a text file named \"file_names.txt\" inside the \"files_list\" directory containing a list of file names, one name per line.\n3. Read the \"file_names.txt\" file, and count the lines containing a specified file extension provided as an argument (e.g., \".txt\").\n4. Output the count as an integer.", + "explanation": "To solve this problem, you may follow these steps:\n\n1. Use `mkdir` to create the \"files_list\" directory.\n2. Use `touch` to create \"file_names.txt\" inside \"files_list\".\n3. Use `echo` or a text editor to add file names with different extensions to the \"file_names.txt\" file.\n4. Use `grep` with the specified extension as a pattern (e.g., `\".txt\"`) to count the lines containing that extension in \"file_names.txt\".\n5. Use `wc` to get the total number of lines and output it as an integer.", + "create": { + "init": "\nmkdir files_list\ntouch files_list/file_names.txt\necho \"file1.txt\" > files_list/file_names.txt\necho \"file2.log\" >> files_list/file_names.txt\necho \"file3.txt\" >> files_list/file_names.txt\necho \"file4.pdf\" >> files_list/file_names.txt\necho \"file5.txt\" >> files_list/file_names.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "grep \"\\.txt\" files_list/file_names.txt | wc -l" + } + }, + { + "description": "As a student, you are given a directory with multiple subdirectories. Each subdirectory contains a variable number of files. You are asked to find out the total number of files in all these subdirectories. To make it more interesting, you need to accomplish this by utilizing Linux commands in a shell script.", + "explanation": "You can solve this problem using the `find` command in the Linux operating system. The `find` command is used to search and locate the list of files and directories based on conditions you specify. In this scenario, you need to count files in different subdirectories.", + "create": { + "init": "\n#!/bin/bash\n# Initialize directory structure\nmkdir -p test_directory/subdirectory_{1..5}\n# Create sample files\nfor i in {1..5}; do\n touch test_directory/subdirectory_$i/file_{1..$i}.txt\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n# Run the find command to locate files and pipe the output to wc -l command to count the files\nfind test_directory -type f | wc -l" + } + }, + { + "description": "As a student, you are required to find the total amount of the specific file types in a given directory and subdirectories. You need to calculate the sum of the total file sizes (in bytes) for each of the following file extensions: '.txt', '.jpg', and '.png'. You'll be using the Linux operating system to accomplish these tasks.\n\nFor this, you'll perform the following steps:\n\n1. Traverse all the files in the given directory and its subdirectories.\n2. Calculate the total file sizes (in bytes) for each of the mentioned three file types.\n3. Your output should be an integer, which is the sum of the total bytes for the files with '.txt', '.jpg', and '.png' extensions.", + "explanation": "To solve this problem, you can use the 'find' command in Linux to traverse through the files in the given directory and its subdirectories. You can use '-type f' flag to filter only the files and '-iname' flag to filter files based on extensions. After filtering, you can use the 'stat' command to get file sizes in bytes and then use 'awk' to calculate the sum of sizes for each file type. ", + "create": { + "init": "\n#!/bin/bash\nmkdir -p problem_folder/sub_dir1/sub_sub_dir1\nmkdir -p problem_folder/sub_dir1/sub_sub_dir2\nmkdir -p problem_folder/sub_dir2\necho \"Hello, World!\" > problem_folder/file1.txt\necho \"Some text\" > problem_folder/sub_dir1/file2.txt\necho \"Other text\" > problem_folder/sub_dir1/sub_sub_dir1/file3.txt\nsleep 0.1\ntouch problem_folder/sub_dir1/sub_sub_dir1/image1.jpg\ntouch problem_folder/sub_dir1/sub_sub_dir1/image2.png\ntouch problem_folder/sub_dir1/sub_sub_dir2/image3.jpg\ntouch problem_folder/sub_dir1/sub_sub_dir2/image4.jpg\ntouch problem_folder/sub_dir2/image5.png" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind problem_folder/ -type f \\( \\\n \\( -iname '*.txt' -exec stat -c\"%s\" {} \\; \\) -o \\\n \\( -iname '*.jpg' -exec stat -c\"%s\" {} \\; \\) -o \\\n \\( -iname '*.png' -exec stat -c\"%s\" {} \\; \\) \\) \\\n | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a student, you are asked to create a directory structure under your home directory and determine the total number of created directories as your answer. The created directory structure is outlined as follows:\n\n1. Create a main directory named \"StudentFiles\" in your home directory.\n2. Inside \"StudentFiles,\" create three sub-directories named \"ClassA\", \"ClassB\", and \"ClassC\".\n3. In each of the sub-directories, create three more sub-directories named \"Project1\", \"Project2\", and \"Project3\".\n\nSubmit your answer as the total number of directories created, including the main directory.", + "explanation": "To solve this problem, you can first create the main directory and the three sub-directories (ClassA, ClassB, and ClassC) under the \"StudentFiles\" main directory. Next, you can create three sub-directories (Project1, Project2, and Project3) within each class directory. After creating all the directories, use the `find` command to count the total number of directories created.\n\nHint: You can use `mkdir -p` to create nested directories in a single command.", + "create": { + "init": "\n#!/bin/bash\nHOME_DIR=~\n\n# Remove existing directory if it exists\nrm -rf \"${HOME_DIR}/StudentFiles\"\n\n# Create main directory in the home directory\nmkdir \"${HOME_DIR}/StudentFiles\"" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n# Create the directory structure\nmkdir -p ~/StudentFiles/Class{A,B,C}/{Project1,Project2,Project3}\n\n# Count the number of directories created (including main StudentFiles directory)\nfind ~/StudentFiles -type d | wc -l" + } + }, + { + "description": "As a student, you are given a directory named `log_files` containing log files from multiple servers. The log files are named as \"server1.log\", \"server2.log\", etc. Each log file contains a list of errors observed on that server.\n\nThe error messages have a specific format: a timestamp followed by an error code and error message, separated by colons. For example:\n\n```\n2022-02-28T10:30:23Z:ERR0001:Permission denied.\n2022-02-28T10:31:42Z:ERR0003:Failed to connect to the database.\n```\n\nYour task is to calculate the total number of errors with the error code 'ERR0003' found in all log files present in the `log_files` directory. \n\nThe answer must be an integer representing the total count of the 'ERR0003' error code in all log files.", + "explanation": "To solve this problem, you can use grep to search for the specific error code in all the log files within the `log_files` directory. Then, pipe the output to the \"wc -l\" command to count the total number of occurrences of that error code.", + "create": { + "init": "\n#!/bin/bash\nmkdir log_files\n\necho \"2022-02-28T10:30:23Z:ERR0001:Permission denied.\" > log_files/server1.log\necho \"2022-02-28T10:31:42Z:ERR0003:Failed to connect to the database.\" >> log_files/server1.log\n\necho \"2022-02-28T10:40:12Z:ERR0002:Invalid input.\" > log_files/server2.log\necho \"2022-02-28T10:45:19Z:ERR0003:Failed to connect to the database.\" >> log_files/server2.log\necho \"2022-02-28T10:50:28Z:ERR0003:Failed to connect to the database.\" >> log_files/server2.log" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "grep -r \"ERR0003\" log_files | wc -l" + } + }, + { + "description": "As a student, you are given a directory containing multiple subdirectories. Each subdirectory contains an unknown number of text files. Your task is to find out the total number of lines across all the text files in all the subdirectories. To achieve this, you will have to write a Linux command that will output this total number of lines.", + "explanation": "To solve this problem, you should use the `find` command to search for text files and `wc` command with `-l` flag to count the lines in these files. You can accomplish this task by combining these commands using a pipeline. Here's the breakdown of the steps to follow:\n\n1. Use the `find` command to find all text files in the given directory and its subdirectories.\n2. Use the `-exec` flag to pass the found file to the `wc` command with `-l` flag.\n3. Calculate the total number of lines and output the result.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p /tmp/experiment/{dir1,dir2,dir3}\necho \"Hello, world!\" > /tmp/experiment/dir1/file1.txt\necho \"Line 1\" > /tmp/experiment/dir1/file2.txt\necho \"Line 2\" >> /tmp/experiment/dir1/file2.txt\necho \"First line\" > /tmp/experiment/dir2/file3.txt\necho \"Second line\" >> /tmp/experiment/dir2/file3.txt\necho \"Third line\" >> /tmp/experiment/dir2/file3.txt\necho \"Greetings\" > /tmp/experiment/dir3/file4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find /tmp/experiment/ -type f -name \"*.txt\" -exec wc -l {} + | awk '{ total += $1 } END { print total }'" + } + }, + { + "description": "As a student learning Linux operating systems, you are tasked to create a simple directory structure with given rules and then count the total number of directories created. \n\nUsing the command line in your Ubuntu operating system, follow these steps:\n\n1. Create a parent directory named 'parentDir'.\n2. Inside 'parentDir', create 3 directories named 'level1_A', 'level1_B', and 'level1_C'.\n3. Inside each of the level 1 directories, create 2 subdirectories named 'level2_1' and 'level2_2'.\n4. Once the directory structure is created, find and submit the total count of directories created (including the parent directory).", + "explanation": "To solve this problem, you can use 'mkdir' to create the directories and 'find' to count the total number of directories created. Perform the following tasks in the command line:\n\n1. Create the directory structure by using the 'mkdir -p' command, which allows you to create multiple sub-directories in a single command.\n2. Navigate into the 'parentDir' directory.\n3. Use the 'find' command along with 'wc -l' to count the total number of directories within the 'parentDir' directory.", + "create": { + "init": "\n# There is no required initialization code for this problem, as students must create the directory structure themselves." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Create directories\nmkdir -p parentDir/level1_{A,B,C}/{level2_1,level2_2}\n\n# Navigate into the parent directory\ncd parentDir\n\n# Count the total number of directories\nfind . -type d | wc -l" + } + }, + { + "description": "As a Linux student, you are tasked to count the total number of characters, words, lines, and folders in a specific directory. The directory will contain various subdirectories, and you are required to go through every subdirectory to count all the text files' characters, words, lines, and total folders.\n\nYou need to use shell commands to get the results efficiently. You are required to provide a single integer, which represents the computed total as follows:\n\nTotal = characters + words + lines + folders\n\nKeep in mind that you only need to count text files (files with the .txt extension).", + "explanation": "To solve the problem, you can use a combination of shell commands such as \"find\", \"wc\", and \"xargs\". First, find all the '.txt' files in the specified directory, and then use the 'wc' command to calculate the number of characters, words, and lines. Next, use the 'find' command to count the number of folders within the specified directory. Finally, sum up all the outputs to get the Total.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p test_directory/subdir{1..3}\necho \"This is a sample text\" > test_directory/subdir1/sample1.txt\necho \"Another sample text\" > test_directory/subdir2/sample2.txt\necho \"Yet another sample text\" > test_directory/subdir3/sample3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncd test_directory\ncharacters=$(find . -name \"*.txt\" -exec wc -m {} + | awk '{s+=$1} END {print s}')\nwords=$(find . -name \"*.txt\" -exec wc -w {} + | awk '{s+=$1} END {print s}')\nlines=$(find . -name \"*.txt\" -exec wc -l {} + | awk '{s+=$1} END {print s}')\nfolders=$(find . -type d | wc -l)\n\ntotal=$((characters + words + lines + folders))\necho $total" + } + }, + { + "description": "As an expert in the Linux operating system, you have been given a directory with multiple subdirectories and files of various types and sizes. Your task is to calculate the total size of all files within the main directory and its subdirectories that have a \".txt\" extension. The answer should be in bytes. You must submit a single integer value as the answer.\n\nYou will be provided with a test environment. The following items should be noted:\n\n1. The subdirectories do not have a specific depth and may contain more nested subdirectories.\n2. Some file and directory names might have spaces.\n3. You should consider only regular files (not symbolic links, devices, or other special files).", + "explanation": "To solve this problem, you need to traverse the directory and its subdirectories while searching for files with a \".txt\" extension. You can use 'find', 'stat', and 'awk' commands to achieve this. Here's a breakdown of the solution:\n\n1. Use the 'find' command to search for all \".txt\" files in the directory and its subdirectories.\n2. Use the 'stat' command to obtain the size (in bytes) of each found \".txt\" file.\n3. Use 'awk' to sum up all the sizes of the \".txt\" files.", + "create": { + "init": "\n#!/bin/bash\n\n# Create test directory structure\nmkdir -p test_environment/dir1/dir1-1\nmkdir -p test_environment/dir1/dir2-1\nmkdir -p test_environment/dir2\n\n# Create test files\ntouch test_environment/file1.txt\ntruncate -s 10 test_environment/file1.txt\n\ntouch test_environment/file2.txt\ntruncate -s 20 test_environment/file2.txt\n\ntouch test_environment/dir1/dir1-1/file3.txt\ntruncate -s 30 test_environment/dir1/dir1-1/file3.txt\n\ntouch test_environment/dir1/dir2-1/file4.txt\ntruncate -s 40 test_environment/dir1/dir2-1/file4.txt\n\n# Initialize student's working directory\ncp -r test_environment student_directory\n\n# Go to student's working directory\ncd student_directory" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Find and sum the size of all \".txt\" files\nfind . -type f -iname \"*.txt\" -exec stat -c \"%s\" {} \\; | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a student, you need to find out the total number of unique file types (based on their extensions) in a given directory and its subdirectories in your Linux (ubuntu) operating system. The answer should be an integer representing the total count of unique file types.\n\nPlease note:\n\n1. Only consider files with extensions and ignore files without extensions.\n2. File extensions are case-insensitive (e.g., .txt and .TXT are the same type).\n3. Do not include directories in the count.", + "explanation": "To solve this problem, you can use a combination of `find`, `grep`, and `sort` commands:\n\n1. Use `find` command to search for files in the given directory and its subdirectories.\n2. Use `grep` command to filter out only the file extensions.\n3. Convert the file extensions to lowercase using `tr` command.\n4. Use `sort` and `uniq` commands to get the unique file extensions.\n5. Use `wc` command to count the total number of unique file types.\n\nTo make the problem more complex, you can create a directory with multiple nested subdirectories and various files using an initialization script.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p problem_directory/subdir1/subdir2\nmkdir -p problem_directory/subdir3\ntouch problem_directory/file1.txt\ntouch problem_directory/subdir1/file2.TXT\ntouch problem_directory/subdir1/file3.pdf\ntouch problem_directory/subdir1/subdir2/file4.PDF\ntouch problem_directory/subdir1/subdir2/file5.doc\ntouch problem_directory/subdir3/file6.docx\ntouch problem_directory/subdir3/file7_no_extension" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind problem_directory -type f | grep -Eo '\\.\\w+$' | tr '[:upper:]' '[:lower:]' | sort | uniq | wc -l" + } + }, + { + "description": "You are given a Linux (Ubuntu) operating system. Your task is to find the total number of subdirectories present in the `/usr` directory and its immediate child directories (i.e., up to one level deep). The output should be a single integer representing this count.", + "explanation": "To solve this problem, you will need to navigate and explore the Linux file system using shell commands. You may use the following commands to help you with this task:\n\n- `cd`: Change the current working directory.\n- `ls`: List the contents of a directory.\n- `find`: Search for files and directories in a directory hierarchy.\n\nHints:\n1. Use the `find` command with the appropriate flags to search for subdirectories.\n2. Consider using pipes and filtering commands like `awk`, `grep`, and `wc` to process the output.", + "create": { + "init": "\n#!/bin/bash\n# No specific initialization is required for this problem as we are exploring an existing Ubuntu directory." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind /usr -maxdepth 2 -type d | wc -l" + } + }, + { + "description": "As a Linux user, you are required to find the total number of lines that contain a specific word or string across multiple files in a given directory (excluding subdirectories). You will use the word \"linux\" to search within the files. Your answer should be provided as an integer count of the number of lines containing the target word.", + "explanation": "To solve this problem, you should use the following tools and concepts:\n\n1. Use the `grep` command to search for the target word in multiple files.\n2. Use `grep` with the `-c` option to count the matching lines.\n3. Use the `find` command to search for files in the given directory.\n4. Combine the `find` and `grep` commands using the `xargs` command to process the output of one command as input to another command, especially when there are whitespace or special characters in filenames.\n5. Pipe the output of the `grep` commands into the `awk` command to sum the individual counts.\n\nSteps to follow:\n\n1. Use `find` to list all the files in the current directory.\n2. Use `xargs` to pass the list of found files to `grep -c`.\n3. Use `grep -c` to count the lines containing the word \"linux\" in each file.\n4. Pipe the output of the `grep` counts into an `awk` command that will sum the counts and print the total.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p problem_directory\ncd problem_directory\n\necho \"This is a file with the word linux in it.\" > file1.txt\necho \"Another line with the word linux.\" >> file1.txt\n\necho \"This is another file that has linux in its content.\" > file2.txt\necho \"Yet another line mentioning linux.\" >> file2.txt\n\necho \"This file has nothing to do with linux.\" > file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find ./problem_directory -maxdepth 1 -type f -name \"*.txt\" | xargs grep -c \"linux\" | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "You are given a directory named \"files\" containing a variable number of text files. Each text file contains a single line of comma-separated integers. Your task is to compute the sum of all integers in each file, and then find the highest sum among all the files in the directory.\n\nFirst, execute an initialization bash script to deploy the environment required for the problem. After executing the script, you will find a directory named \"files\" containing multiple text files in your current directory.\n\nYour job is to interact with the shell to calculate the sum of integers in each file and find the highest sum. When you think you have an answer, submit the highest sum as an integer.", + "explanation": "To solve this problem, you can follow these steps:\n\n1. Navigate to the \"files\" directory.\n2. Read the content of each file and calculate the sum.\n3. Store the maximum sum as you iterate through the files.\n4. Display the highest sum as the final output.", + "create": { + "init": "\n#!/bin/bash\nmkdir files\ntouch files/file1.txt files/file2.txt files/file3.txt\necho \"5,10,15,20\" > files/file1.txt\necho \"2,4,6,8\" > files/file2.txt\necho \"10,20,30,40\" > files/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\ncd files\nmax_sum=0\nfor file in *\ndo\n sum=$(awk -F ',' '{for (i=1; i<=NF; ++i) total+=$i} END {print total}' $file)\n if [ $sum -gt $max_sum ]\n then\n max_sum=$sum\n fi\ndone\n\necho $max_sum" + } + }, + { + "description": "As a student, your task is to find the total number of non-empty directories inside the '/etc' directory. Your goal is to return that number as an integer.\n\nPlease follow these steps to find the answer:\n\n1. List all items in the '/etc' directory.\n2. Identify each item as a file or directory.\n3. Discard any files and focus only on the directories.\n4. Make sure to exclude empty directories from your count.\n5. Count the remaining non-empty directories, and return the sum as an integer.", + "explanation": "To solve the problem, you need to perform several operations. First, you'll be listing the directory contents using the 'ls' command. Next, you'll identify each item as a file or directory using the 'find' command, specifying the '-type' option. Then, you'll filter out empty directories and count the non-empty ones using the 'grep' and 'wc' commands.", + "create": { + "init": "\n# You may not need any init script in this case, as the files and directories\n# in the \"/etc\" directory should be unchanged and consistent on all Ubuntu distributions." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# The example script returns the total number of non-empty directories in the \"/etc\" directory.\n\nfind /etc -mindepth 1 -maxdepth 1 -type d -not -empty | wc -l" + } + }, + { + "description": "As a Linux system administrator, you are tasked with demonstrating your ability to iterate through directories and calculate the total number of files of a specific type.\n\nAssuming you are given a specific file extension (e.g., \".txt\"), count the total number of files with that extension under the \"/home/user/documents\" directory and all its subdirectories. Note that the \"/home/user/documents\" directory could be arbitrarily nested with subdirectories containing no limit to the number of files or other directories.\n\nThe output should be a single integer (the total count of files with the given extension).", + "explanation": "To solve this problem, you can use the 'find' command to search for the files with the given extension within the targeted directory and its subdirectories. Next, pipe the search output to the 'wc' command to count the number of lines in the search output, ultimately calculating the total number of files.\n\nYou can use this command pattern to perform the task:\n\n```bash\nfind /path/to/directory -type f -iname \"*.extension\" | wc -l\n```", + "create": { + "init": "\n#!/bin/bash\n\n# Create directory structure and files for testing purposes\nmkdir -p /home/user/documents/sub1/sub1_1\nmkdir -p /home/user/documents/sub1/sub1_2\nmkdir -p /home/user/documents/sub2/sub2_1\ntouch /home/user/documents/file1.txt\ntouch /home/user/documents/sub1/file2.txt\ntouch /home/user/documents/sub1/sub1_1/file3.txt\ntouch /home/user/documents/sub1/sub1_1/file4.txt\ntouch /home/user/documents/sub1/sub1_2/file5.doc\ntouch /home/user/documents/sub1/sub1_2/file6.txt\ntouch /home/user/documents/sub2/sub2_1/file7.txt\ntouch /home/user/documents/sub2/sub2_1/file8.pdf" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find /home/user/documents -type f -iname \"*.txt\" | wc -l" + } + }, + { + "description": "As a student, you are required to calculate the total number of lines in all the '.txt' files in a given directory and its sub-directories. You need to ensure you only count '.txt' files and ignore any other file types or directories. Once you have the answer, submit your result as an integer.", + "explanation": "To solve this problem, you can use the 'find' command to locate all '.txt' files in the given directory and its sub-directories. Then, you can use the 'wc -l' command to count the total number of lines in all these '.txt' files. Make sure to only count the lines from the '.txt' files and ignore other file types.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p ~/txt_problem\ncd ~/txt_problem\necho -e \"1\\n2\\n3\" > file1.txt\necho -e \"4\\n5\" > file2.txt\nmkdir sub_directory\ncd sub_directory\necho -e \"6\\n7\\n8\\n9\" > sub_file1.txt\necho -e \"10\" > sub_file2.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\ncd ~/txt_problem\nfind . -type f -name \"*.txt\" -exec wc -l {} + | awk '{total += $1} END{print total}'" + } + }, + { + "description": "As a student, you will explore and analyze the Linux (Ubuntu) operating system's file system. Your goal is to write a bash script that counts the number of files and directories in a given path, ignoring hidden files and directories. After counting, return the sum of file and directory counts as an integer.", + "explanation": "To solve this problem, you can use various Linux command-line utilities like \"find\" to search for files and directories in a given path. You can exclude hidden files and directories by applying filters like \"grep\" with a regex pattern. After retrieving the total counts, you can use arithmetic operations in bash to sum the counts and output the result.", + "create": { + "init": "\n#!/bin/bash\n\n# Create sample directory structure and files\nmkdir -p ~/linux_problem/sample_dir/{dir1,dir2,\".hidden\"}\ntouch ~/linux_problem/sample_dir/{file1,file2,dir1/file3,dir2/file4,\".hiddenfile\"}\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Change to sample directory\ncd ~/linux_problem/sample_dir\n\n# Count the number of non-hidden files\nFILE_COUNT=$(find . -type f | grep -v '/\\.' | wc -l)\n\n# Count the number of non-hidden directories\nDIR_COUNT=$(find . -type d | grep -v '/\\.' | sed '1d' | wc -l)\n\n# Sum the counts and print the result\nSUM=$((FILE_COUNT + DIR_COUNT))\necho $SUM" + } + }, + { + "description": "As a student, your goal is to find the total number of occurrences of a given word within a set of text files in different directories. You are provided with a directory containing multiple text files, as well as subdirectories containing text files. The word to be searched is \"Linux\". Your answer should be the total number of occurrences of the word \"Linux\" across all the text files in the entire directory structure (including subdirectories). Make sure you only count exact matches and that the word is treated as case-sensitive.", + "explanation": "In order to solve this problem, you have to use various Linux commands, which might include find, grep, and wc. First, you need to search for all text files within the directory and its subdirectories. Then, you can use grep to search for the word \"Linux\" in each file. Lastly, you can count the number of occurrences of the word \"Linux\" within each file by using wc and sum up the counts from all the files.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p problem_directory/subdirectory1\nmkdir -p problem_directory/subdirectory2\n\necho \"Welcome to this Linux course!\" > problem_directory/file1.txt\necho \"We're going to learn about the Linux operating system today.\" > problem_directory/file2.txt\necho \"Linux is a great alternative to other operating systems.\" > problem_directory/subdirectory1/file3.txt\necho \"Ubuntu is a popular distribution of Linux.\" > problem_directory/subdirectory1/file4.txt\necho \"With Linux, you can take control of your computer.\" > problem_directory/subdirectory2/file5.txt\necho \"Linux is used for servers, desktops, and more.\" > problem_directory/subdirectory2/file6.txt\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find problem_directory -type f -name \"*.txt\" -exec grep -o -w \"Linux\" {} + | wc -l" + } + }, + { + "description": "As a Linux (Ubuntu) user, your task is to create a script that counts the total storage used by all regular files within the \"/var/log\" directory, in kilobytes. Your output should be an integer representing the total storage used by all these files in kilobytes.", + "explanation": "To solve this problem, first, use the find command to filter the regular files in the \"/var/log\" directory. Then, use du command to calculate the storage used by each of these files. Finally, sum up the storage values for all the files.\n\nHint: You can use pipes and xargs with the find and du commands, to make your script more elegant and efficient. To get the sum of values in a column, you can use awk.", + "create": { + "init": "\n#!/bin/bash\n# This script doesn't need any initialization because the /var/log directory exists in all Linux distributions as a default." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind /var/log -type f -exec du -k {} + | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a Linux student, you are tasked with calculating the total size of all `.txt` files within a specified directory and its subdirectories. The answer should be in kilobytes (KB) and rounded down to the nearest integer value. Assume that all directories and files have read permissions.", + "explanation": "To solve this problem, you can use the `find` command to locate all `.txt` files within the specified directory and its subdirectories. You can then use a combination of commands, such as `stat`, `awk`, and `bash`, to calculate the total size of all these files and convert the result to kilobytes.", + "create": { + "init": "\nmkdir -p test_directory/subdir1\nmkdir -p test_directory/subdir2\necho \"Example file 1\" > test_directory/file1.txt\necho \"Example file 2\" > test_directory/subdir1/file2.txt\necho \"Example file 3\" > test_directory/subdir2/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find test_directory -type f -name \"*.txt\" -exec stat -c%s '{}' \\; | awk '{total += $1} END {print int(total/1024)}'" + } + }, + { + "description": "In this problem, you are required to find the total number of files and directories in a given directory and its subdirectories. The given directory will be initialized by the provided script and will contain a mixture of files and directories (including hidden files and directories). Your task is to write a bash script that prints the total count of all files and directories present inside the given directory, including its subdirectories.", + "explanation": "To solve this problem, you can use the `find` command in Linux to search for files and directories. You can use various options and flags provided by the `find` command to search for specific types of files and directories.\n\nHint: Use the find command with -type flag to specify whether to look for files or directories, and remember to consider hidden files and directories as well.", + "create": { + "init": "\n#!/bin/bash\n\n# Initialize a directory named \"testDir\" in the user's home directory (~)\nmkdir -p ~/testDir\n\n# Create a few subdirectories and files, including hidden ones\nmkdir -p ~/testDir/subDir1\nmkdir -p ~/testDir/subDir2\nmkdir -p ~/testDir/subDir2/subSubDir1\nmkdir -p ~/testDir/.hiddenDir\n\ntouch ~/testDir/file1.txt\ntouch ~/testDir/subDir1/file2.txt\ntouch ~/testDir/subDir2/file3.txt\ntouch ~/testDir/subDir2/file4.txt\ntouch ~/testDir/subDir2/subSubDir1/file5.txt\ntouch ~/testDir/.hiddenFile\ntouch ~/testDir/subDir1/.hiddenFile2\n" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Count the total number of files and directories in ~/testDir and its subdirectories\nfind ~/testDir -type f -o -type d | wc -l" + } + }, + { + "description": "As a Linux system administrator, you are required to find out the total number of files within a given directory including all its subdirectories. The directory structure will be provided in the initialization bash script. You need to write a bash script that counts the total number of files and returns the answer as an integer.", + "explanation": "To solve this problem, you can use the 'find' command to search and list all the regular files under the given directory recursively. Then, you can pipe the output to the 'wc' command which counts the number of lines, words, or characters, with the `-l` flag to count the number of lines (i.e., the number of files in this case).", + "create": { + "init": "\n#!/bin/bash\n\n# Create a main directory\nmkdir -p main_directory\n\n# Create subdirectories and files\nmkdir -p main_directory/subdir1\ntouch main_directory/subdir1/file1\ntouch main_directory/subdir1/file2\n\nmkdir -p main_directory/subdir2\ntouch main_directory/subdir2/file3\ntouch main_directory/subdir2/file4\n\nmkdir -p main_directory/subdir1/subsubdir\ntouch main_directory/subdir1/subsubdir/file5" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find main_directory -type f | wc -l" + } + }, + { + "description": "As a student, you are tasked to calculate the total size of files with a specific extension in a given directory and its subdirectories. You need to find the sum of these file sizes in bytes. The files extension and the directory path will be provided to you as input.\n\nNote: You should only consider regular files, not symbolic links.", + "explanation": "To solve this problem, you can use the `find` command to list all the files with the specified extension inside the given directory and its subdirectories. Then, `stat` command can be utilized to retrieve the size of each file in bytes. After that, you can use command substitution and the `awk` utility to sum up all the sizes.", + "create": { + "init": "\n# Create a temporary directory with some files to test\nmkdir -p /tmp/my-task/test-dir/sub-dir\necho \"Sample text content.\" > /tmp/my-task/test-dir/file1.txt\necho \"Another sample text content.\" > /tmp/my-task/test-dir/sub-dir/file2.txt\necho \"Yet another sample text content.\" > /tmp/my-task/test-dir/sub-dir/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Find the total size of all .txt files in the /tmp/my-task/test-dir directory\nfind /tmp/my-task/test-dir -type f -name \"*.txt\" -exec stat -c%s {} \\; | awk '{sum += $1} END {print sum}'" + } + }, + { + "description": "As a student, you are required to calculate the total size of all regular files within a specific directory, in bytes. The directory will be created by the initialization script and it will contain several files and subdirectories; however, you should only consider regular files present in the main directory, and ignore files inside subdirectories.\n\nCreate a bash script to calculate the sum of sizes of the regular files in the given directory, 'sample_directory'. The script should output a single integer representing the total size.", + "explanation": "To solve this problem, the students are expected to use various Linux commands like 'ls', 'awk', 'find', etc., in their script. One way to approach this would be by using the 'find' command to list only the regular files present in the main directory and then using 'stat' to obtain the size of each file. The file sizes can then be summed up using 'awk' and printed as a single integer.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the environment\nmkdir -p sample_directory/sub_directory\necho \"This is a file with some data.\" > sample_directory/file1.txt\necho \"This is another file with data.\" > sample_directory/file2.txt\necho \"A third file contains even more data.\" > sample_directory/file3.txt\n\n# Add files to subdirectory\necho \"This file is inside the subdirectory and should be ignored.\" > sample_directory/sub_directory/ignore.txt\necho \"This file is also inside the subdirectory and should be ignored.\" > sample_directory/sub_directory/extra.txt\nchmod -R 755 sample_directory" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\nfind sample_directory -maxdepth 1 -type f -exec stat --format=\"%s\" {} \\; | awk '{s+=$1} END {print s}'" + } + }, + { + "description": "In this task, you are required to calculate the total number of lines of code (LOC) written in Python (.py) files in a given directory and its subdirectories. The directory will be provided through the initialization script and will contain several Python files and subdirectories with Python files. Note that the directory and file structure may change with each new experiment. Your task is to interact with the Linux shell and find the total LOC in all Python files within the directory and its subdirectories.", + "explanation": "To solve this problem, you must use the `find` command to search for all `.py` files in the given directory and its subdirectories. Then, use the `wc` command with the `-l` option to count lines for each file. Finally, sum the total number of lines in all files.\n\nHint: Use the `find` command with the `exec` option to execute the `wc` command on each file, then pipe the output to `awk` or any other text processing utility to sum the individual line count values.", + "create": { + "init": "\n#!/bin/bash\n\n# Create a directory called \"codebase\" and change to it\nmkdir codebase && cd codebase\n\n# Create subdirectories with different Python files\nmkdir -p projectA/module && mkdir -p projectB/module && mkdir -p projectC/module\n\n# Create some Python files with different lines of code\necho \"print('Hello World')\" > script1.py\necho \"def main():\\n print('This is Project A')\" > projectA/main.py\necho \"import os\\n\\nprint(os.getcwd())\\nprint('Inside projectB')\" > projectB/module/moduleB.py\necho \"import math\\n\\ndef sqr(x):\\n return math.sqrt(x)\\n\\nprint(sqr(9))\" > projectC/module/moduleC.py\n\n# Change back to the parent directory\ncd .." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find codebase -iname \"*.py\" -exec wc -l {} \\; | awk '{ sum += $1 } END { print sum }'" + } + }, + { + "description": "As a student, your task is to determine the total number of files and directories under the `/etc` directory in your Linux operating system (Ubuntu). Your answer should be a single integer, representing the sum of the total number of files and directories.\n\nNote: Do *not* include the `/etc` directory itself in your count. Only count the files and directories directly under the `/etc` directory.", + "explanation": "To solve this problem, you need to use the `find` command to search for files and directories within the `/etc` directory. You should use appropriate options for the `find` command to ensure you are only counting files and directories directly under the `/etc` directory. Finally, you can use `wc -l` to count the number of lines returned by the `find` command, which in this case will translate to the number of files and directories.", + "create": { + "init": "\n# There is no need for any initialization script for this problem" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find /etc -maxdepth 1 -mindepth 1 -type f -o -type d | wc -l" + } + }, + { + "description": "As a student, you are asked to create a simple system analytics tool that will demonstrate your knowledge of the Linux operating system. You are to find the sum of the total number of processes and the number of logged-in users on the system. The answer must be an integer.\n\nTo help you achieve this, you can start by identifying the number of processes currently running on the system, and then find the number of users currently logged into the system. Following that, add the two numbers to get the final result.", + "explanation": "In order to determine the number of processes and the number of logged-in users on the system, you can use the 'ps' and 'who' commands respectively. The 'ps' command displays information about active processes, and the 'who' command displays which users are currently logged in.\n\nHints:\n1. Use 'ps -e' to display all of the active processes on the system.\n2. Use 'who' to display the logged-in users list.\n3. Use 'wc -l' to count the number of lines in the output, which will give you the number of processes or users.\n4. Perform arithmetic operations using expr or other arithmetic expressions in shell to sum up the process count and logged-in users count.", + "create": { + "init": "\n#!/bin/bash\n\n# No initialization script is needed as the solution will be calculated based on the current state of the user's system." + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Count all running processes\nprocess_count=$(ps -e | wc -l)\n\n# Count all logged-in users\nlogged_in_users=$(who | wc -l)\n\n# Add the process count and the logged-in users count\ntotal_count=$((process_count + logged_in_users))\n\n# Output the total count\necho $total_count" + } + }, + { + "description": "You have just joined a Linux system administration team, and one of the tasks assigned to you is to analyze and store log files generated by various applications. You should do the following:\n\n1. Write an initialization script that will create a directory named \"log_files\" and will generate 10 log files (log1.log to log10.log) within this directory. Each log file should contain between 5-10 lines with randomly generated timestamps followed by a log message (e.g., \"2022-03-02 15:30:45 Connection established\").\n2. Write a code snippet that, when executed, calculates the total number of lines across all log files in the \"log_files\" directory. Return this number (an integer) as the final output.", + "explanation": "You can solve the problem by:\n1. Using a loop to create the log files and generate random timestamps with log messages in them.\n2. Utilizing the `wc` utility to count the lines in all log files and `awk` to sum up the results.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the \"log_files\" directory\nmkdir -p log_files\n\n# Fill each log file with 5-10 random log lines\nfor i in {1..10}; do\n log_file=\"log_files/log${i}.log\"\n touch $log_file\n\n # Generate a random number of log lines (5-10)\n num_lines=$(( RANDOM % 6 + 5 ))\n\n j=0\n while [ $j -lt $num_lines ]; do\n # Generate random timestamp within a fixed range\n TIMESTAMP=$(date -d \"$((RANDOM % 1 + 1970))-$((RANDOM % 12 + 1))-$((RANDOM % 28 + 1)) $((RANDOM % 24)):$((RANDOM % 60)):$((RANDOM % 60))\" '+%Y-%m-%d %H:%M:%S' 2>/dev/null)\n\n # Add log line\n echo \"$TIMESTAMP Log message $j\" >> $log_file\n j=$((j+1))\n done\ndone" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Count the total number of lines across all log files and output the result\nfind log_files -name '*.log' -exec wc -l {} \\; | awk '{ total += $1 } END {print total}'" + } + }, + { + "description": "For this problem, you need to determine the total number of lines, words, and characters in all text files within a specific directory and its subdirectories in the Linux operating system. You will perform this task using the 'find' and 'wc' commands in the shell.\n\nGiven a directory path \"/home/user/project\", determine the total number of:\n\n1. Lines (L)\n2. Words (W)\n3. Characters (C)\n\nin all text files (*.txt) within the given directory and its subdirectories. Your final answer should be in the format: L + W + C.", + "explanation": "To solve this problem, you can use the 'find' command to search for all text files within the given directory and its subdirectories. Then, use the 'wc' command to count the lines, words, and characters in these files.\n\nFor counting the lines, words, and characters, you can use the following 'wc' command options: '-l' for lines, '-w' for words, and '-m' for characters.", + "create": { + "init": "\n#!/bin/bash\n\n# Create folders and files\n\nmkdir -p /home/user/project/level0/subfolder\nmkdir -p /home/user/project/level1/subfolder1\nmkdir -p /home/user/project/level1/subfolder2\n\necho \"Hello\nWorld!\" > /home/user/project/level0/subfolder/file1.txt\necho \"Welcome to the Linux world!\" > /home/user/project/level1/subfolder1/file2.txt\necho \"Linux is an open-source operating system.\" > /home/user/project/level1/subfolder2/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find /home/user/project -iname '*.txt' -exec wc -lwm {} + | awk '{L += $1; W += $2; M += $3} END {print L + W + M}'" + } + }, + { + "description": "As a student using the Linux operating system (Ubuntu), your task is to count the total number of files and directories in a given directory tree (including the root directory). The given directory contains a mix of files and directories, including hidden ones (those starting with a period, .).\n\nYour challenge is to create and execute a bash script that will calculate the total file count and then output that count as a single integer. You should ignore symbolic links, sockets, and other file types in your count.", + "explanation": "To solve this problem, you can make use of the `find` command in Linux. The `find` command searches for files and directories based on specific conditions. You can use the `-type` option to search for a particular file type (like `-type d` for directories or `-type f` for files). To include hidden files/folders in your search, you can use the `-not -path` option with the appropriate pattern. To count the number of files and directories, you can pass the results from the `find` command to the `wc` command using a pipe (`|`), and use the `-l` option to count the number of lines.", + "create": { + "init": "\n#!/bin/bash\n\n# Create the directory structure and files for the example\nmkdir -p ~/example_directory/{dir1,dir2,dir3,dir4}\nmkdir -p ~/example_directory/dir1/{.hidden_dir1,subdir1,subdir2}\ntouch ~/example_directory/{file1.txt,.hidden_file1}\ntouch ~/example_directory/dir1/{file2.txt,.hidden_file2}\ntouch ~/example_directory/dir1/subdir1/{file3.txt,.hidden_file3}" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# Find and count the total number of files and directories in the given directory tree.\nfind ~/example_directory -type d -o -type f -not -path \"*/\\.*\" | wc -l" + } + }, + { + "description": "As a student, you have been given a directory called \"logs\" containing multiple files. Each file contains lines representing status messages and logged events. You need to analyze these log files and answer the following question:\n\nHow many times the keyword \"ERROR\" appears across all the files in the \"logs\" directory?\n\nIn order to accomplish this task, you must create a single command line solution that processes the log files and returns the total count of occurrences of the keyword \"ERROR\" in the \"logs\" directory. Remember, the output must only contain a single integer representing the count of occurrences.", + "explanation": "To solve this problem, you can use a combination of shell commands:\n\n1. Use 'grep' with the '-o' option, which will print only the matching part of the lines, and search for the keyword \"ERROR\".\n2. Pipe the output to 'wc -l' to count the number of lines, which will represent the total number of occurrences of the keyword \"ERROR\".", + "create": { + "init": "\nmkdir logs\necho \"INFO: Service started\" > logs/log1.txt\necho \"ERROR: Connection failed\" >> logs/log1.txt\necho \"ERROR: File not found\" >> logs/log1.txt\necho \"WARNING: High CPU usage\" >> logs/log1.txt\n\necho \"ERROR: Disk full\" > logs/log2.txt\necho \"INFO: Configuration updated\" >> logs/log2.txt\necho \"INFO: Service restarted\" >> logs/log2.txt\necho \"ERROR: Database connection lost\" >> logs/log2.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "grep -o 'ERROR' logs/* | wc -l" + } + }, + { + "description": "In this problem, you need to find the total number of lines containing the word \"Linux\" in all the \".txt\" files inside a given directory and its subdirectories.\n\nHere's the problem detail:\n\n1. A new directory named \"Linux_files\" will be created in your home directory.\n2. The \"Linux_files\" directory will contain multiple \".txt\" files and subdirectories.\n3. Some of the subdirectories inside \"Linux_files\" will also contain \".txt\" files.\n4. Some of the \".txt\" files will contain the word \"Linux\" in one or more lines.\n5. Your task is to find the total number of lines containing the word \"Linux\" in all the \".txt\" files inside the \"Linux_files\" directory and its subdirectories.\n\nSubmit your answer as an integer.", + "explanation": "To solve this problem, you can use the 'grep' command along with '-r' and '-c' options. The '-r' option is used for a recursive search to include subdirectories, and the '-c' option is used for counting occurrences.\n\nUse the following command to search for \"Linux\" word recursively and count the occurrences:\n\ngrep -r -c 'Linux' Linux_files/*.txt\n\nThen, use 'awk' to sum these numbers and get the total count.", + "create": { + "init": "\n#!/bin/bash\nmkdir ~/Linux_files\ncd ~/Linux_files\necho -e \"Hello\\nLinux operating system\\nHow's the weather?\\nLinux is great!\" > file1.txt\necho -e \"This is a test line\\nI love Linux\\nLet's use Linux more often!\" > file2.txt\nmkdir subdirectory1\ncd subdirectory1\necho -e \"Linux should be your first choice.\\nGive Linux a try!\" > file3.txt\ncd ..\nmkdir subdirectory2\ncd subdirectory2\necho -e \"I just made a switch to Linux\\nBest decision ever!\" > file4.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "grep -r -c 'Linux' ~/Linux_files/*.txt | awk -F: '{sum+=$2} END {print sum}'" + } + }, + { + "description": "As a student, your task is to find the total number of files and directories in a given directory, excluding its subdirectories. Use the Linux command line to accomplish this task and submit your answer as an integer.", + "explanation": "To solve this problem, you need to use a combination of commands and tools like 'find', 'wc', and pipes. First, you can use the 'find' command with the 'maxdepth' option to search for files and directories within the given directory without going into subdirectories. Then pipe the results into 'wc' with the '-l' option to count the total number of lines in the output. Finally, subtract 2 from the total number of lines, as the 'find' command will also return the given directory and the current directory. The final result will be an integer representing the total number of files and directories in the given directory, excluding its subdirectories.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p ~/TA_problem_directory\ncd ~/TA_problem_directory\nmkdir -p subdir1 subdir2\ntouch file1.txt file2.txt file3.txt subdir1/file4.txt subdir2/file5.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "find ~/TA_problem_directory -maxdepth 1 | wc -l | awk '{print $1-2}'" + } + }, + { + "description": "As a student, you have been assigned a task to analyze the files in a directory and provide useful statistics. Your goal is to determine the total number of lines contained in all the \".txt\" files in the \"/home/student/files\" directory and its subdirectories.\n\nPlease provide your answer in the form of an integer, representing the sum of lines present in all \".txt\" files.", + "explanation": "To solve this problem, you may use the \"find\" command to list all the \".txt\" files in the given directory and its subdirectories. Then, you can use the \"wc\" command with the \"-l\" (lines) option to count the number of lines in each file. Finally, sum up the number of lines in all the files to get the desired result.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p /home/student/files\necho \"This is a test file.\" > /home/student/files/file1.txt\necho \"This file contains\\nMultiple lines.\" > /home/student/files/file2.txt\nmkdir -p /home/student/files/subdir\necho \"This is another test file\\nInside a subdirectory.\" > /home/student/files/subdir/file3.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nfind /home/student/files -type f -name \"*.txt\" -exec wc -l {} + | awk '{SUM += $1} END {print SUM}'" + } + }, + { + "description": "You are given a directory named 'log_files' which contains multiple log files. Each log file is named in the format 'log_server_X_YYYY-MM-DD.txt' where X is an integer server ID (between 1 and 100) and YYYY-MM-DD is the date. The content of each log file contains different integers, one integer per line. Your task is to find the sum of the integers present on the log files whose server ID is a prime number and was created within the last 7 days.\n\nWrite a bash script to calculate the required sum of integers and output the result.", + "explanation": "To solve this problem, you can follow these steps:\n\n1. Figure out when the \"last 7 days\" were, using date command.\n2. Write a small snippet to check if a number (server id) is prime.\n3. Use a for loop to iterate through the log_files in the directory.\n4. Use grep and awk to extract the server ID and date from the file name.\n5. Check if the extracted server ID is prime and if the file is created within the last 7 days; if so, read the content and sum up all the integers in the log file.\n6. Print the final calculated sum.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p log_files\necho \"5\" > log_files/log_server_2_$(date --date=\"5 days ago\" +%Y-%m-%d).txt\necho \"5\" > log_files/log_server_4_$(date --date=\"5 days ago\" +%Y-%m-%d).txt\necho \"3\" > log_files/log_server_3_$(date --date=\"2 days ago\" +%Y-%m-%d).txt\necho \"7\" > log_files/log_server_5_$(date --date=\"1 days ago\" +%Y-%m-%d).txt\necho \"1\" > log_files/log_server_1_$(date --date=\"9 days ago\" +%Y-%m-%d).txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nis_prime() {\n number=$1\n if ((number <= 1)); then\n return 1\n elif ((number == 2)); then\n return 0\n else\n for ((i = 2; i * i <= number; i++)); do\n if ((number % i == 0)); then\n return 1\n fi\n done\n return 0\n fi\n}\n\nlimit_date=$(date --date=\"7 days ago\" +%Y-%m-%d)\ntotal_sum=0\n\nfor file in log_files/*.txt; do\n server_id=$(echo \"${file#*_}\" | awk -F_ '{print $2}')\n file_date=$(echo \"${file}\" | awk -F_ '{print $(NF-1)}')\n\n is_prime ${server_id}\n result=$?\n\n # Check if server id is prime (result equals to 0) and if file date is within the last 7 days.\n if [[ ${result} -eq 0 && ${file_date} > ${limit_date} ]]; then\n sum=$(awk '{s+=$1} END {print s}' \"${file}\")\n total_sum=$((total_sum + sum ))\n fi\ndone\n\necho ${total_sum}" + } + }, + { + "description": "As a Linux user, you have to analyze the log files to keep track of the activities within a system. In this scenario, you have a log file named \"system_logs.log\" which records specific activities on your Linux (Ubuntu) operating system. The log file contains multiple lines of data with a timestamp, event type (error or_success), user ID, and action message.\n\nHere's an example of a log entry: \n`2022-11-15 18:03:23 error 28 Directory_not_found`\n\nThe user ID is an integer (between 1 and 50), and the number of error events varies.\n\nYour task is to create a script that counts the total number of error events in the log file for a specific user ID, provided as an input argument.\n\nThe output should be a single integer representing the total number of error events.", + "explanation": "To solve this problem, you can use a combination of Linux commands, including `grep`, `awk`, and `wc`. First, filter the log file for lines containing the \"error\" event type. Next, further filter the result to match the user ID provided as an argument. Finally, count the number of lines to determine the total number of error events for the specific user ID.", + "create": { + "init": "\n# This initialization script creates a log file and adds sample log entries.\ncat > system_logs.log << EOF\n2022-09-14 15:21:11 error 15 Invalid_file_name\n2022-09-12 11:30:09 success 45 Operation_finished\n2022-09-17 23:37:43 error 28 Directory_not_found\n2022-09-3 15:25:42 success 01 Backup_complete\n2022-09-22 09:43:33 error 15 File_read_error\nEOF" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\n# The provided argument is the user ID to search for.\nUSER_ID=$1\n\n# Filter the log file for error events and the specific user ID, then count the number of lines.\ngrep \"error\" system_logs.log | grep \" $USER_ID \" | wc -l" + } + }, + { + "description": "As a Linux user, you are required to find the total number of unique characters in a given log file. The file does not have any newline characters. The purpose of this problem is to identify your understanding of file management and text processing using command line.\n\n**Instructions:**\n\n1. In your Linux (Ubuntu) operating system initialize a file called `logfile.txt`.\n\n2. Count and print the number of unique characters in the `logfile.txt` file. The result must be an integer.", + "explanation": "To solve this problem, you will need to use several Linux command line utilities to manipulate the text in the `logfile.txt` file. Here are some hints to help you:\n\n1. Use `fold` command to remove newline characters (if any) in the file\n2. Use `grep`, `tr` or `sed` command to eliminate duplicates\n3. Use `wc` command to count characters", + "create": { + "init": "\n#!/bin/bash\n# Initialization script to create logfile.txt with random strings\n\n# Generating a random characters string of length 1000\nrandom_string=$(cat /dev/urandom | tr -dc \"[:alnum:]\" | head -c 1000)\n\n# Creating and initializing logfile.txt with random string content\necho $random_string > logfile.txt" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "# Removing newline (if any) and counting unique characters in logfile.txt\ncat logfile.txt | fold -w1 | grep -o . | sort | uniq | wc -l" + } + }, + { + "description": "As a student, your task is to determine how many lines of code (LOC) are written in the C programming language within a given directory structure. This directory structure contains multiple subdirectories and files with different programming languages.\n\nYou need to count the number of lines in all .c files present in the given directory and its subdirectories; your answer must be an integer.\n\nNote: You are only allowed to use the Linux command line and its utilities; you cannot use any other scripts or software to perform this task.", + "explanation": "To solve this problem, the student can use a combination of basic command-line utilities like `find`, `grep`, `wc`, and pipes.\n\n1. Utilize the `find` command to list all .c files in the given directories and subdirectories.\n2. Use `grep` with the '-c' option to count the number of lines of code (LOC) in each .c file.\n3. Then, use pipes to combine these output results and sum them up with a small AWK script.\n4. Finally, the output will show the total number of LOC in the .c files in the given directory, including subdirectories.", + "create": { + "init": "\n#!/bin/bash\n\nmkdir -p code_directory/subdir1\nmkdir -p code_directory/subdir2\n\necho \"#include \" > code_directory/main.c\necho \"int main() { return 0; }\" >> code_directory/main.c\n\necho \"#include \" > code_directory/subdir1/test1.c\necho \"void foo() { }\" >> code_directory/subdir1/test1.c\n\necho \"#include \" > code_directory/subdir2/test2.c\necho \"void bar() { }\" >> code_directory/subdir2/test2.c" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\n\nfind code_directory -type f -name \"*.c\" -exec grep -cve '^ *$' {} \\; | awk '{s+=$1} END {print s}'" + } + }, + { + "description": "In this problem, you need to analyze the file system usage (in kilobytes) in a Linux operating system. You will be given a directory in the initialization phase. You need to find out the total number of kilobytes used by all files within that directory (including subdirectories).\n\nYour task is to calculate the total file size in kilobytes within the provided directory, ignoring the sizes of any folders. The answer should be an integer value.", + "explanation": "To solve this problem, you can use the `du` command to estimate file space usage. You can also use the `-s`, `-b`, and `--apparent-size` flags to display only the total size of the given directory and obtain sizes in bytes. You may calculate the file sizes in kilobytes by dividing the total bytes by 1024, rounding up to the nearest integer.", + "create": { + "init": "\n#!/bin/bash\nmkdir -p experiment_folder/sub_folder_{1,2,3}\necho \"Creating files with various sizes in different folders\"\necho \"testing\" > experiment_folder/test_1.txt\necho \"testing\" > experiment_folder/sub_folder_1/test_2.txt\ndd if=/dev/urandom of=experiment_folder/sub_folder_2/random_file.txt bs=1024 count=10 2>/dev/null\ndd if=/dev/urandom of=experiment_folder/sub_folder_3/random_file_2.txt bs=1024 count=5 2>/dev/null" + }, + "evaluation": { + "check": [ + null, + { + "language": "python", + "file": "check/integer-match.py" + } + ], + "example": "#!/bin/bash\nprintf \"%.0f\\n\" $(($(du -sb --apparent-size experiment_folder | cut -f1) / 1024))" + } + } +] \ No newline at end of file