File size: 3,722 Bytes
e9f3646
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
query,gold
Count the number of files and directories in the entire testbed directory,find /testbed | wc -l
Find all text files in the testbed directory and subdirectories and concatenate them into a single file,find /testbed -type f -name '*.txt' -exec cat {} ; > /testbed/concatenated_text_files.txt
Find all directories in the testbed directory that have at least one Python script and list the number of Python scripts in each directory,"find /testbed -type d -exec sh -c 'echo -n ""{}: ""; ls -1 {}/*.py 2>/dev/null | wc -l' \;"
Sort the lines of textfile1.txt in reverse alphabetical order and save the result to a new file,sort -r /testbed/dir1/textfile1.txt > /testbed/dir1/textfile1_reverse_sorted.txt
Search for all files containing the word 'error' and sort them by size,find testbed/ -type f -exec grep -l 'error' {} + | xargs du -b | sort -n
Find all symbolic links in testbed/ that point to files which were modified in the last 7 days,find testbed/ -type l -lname '*testbed/*' -mtime -7 -ls
Get the total size of all files in testbed/ and save it to a file,find testbed/ -type f -printf '%s\n' | awk '{s+=$1} END {print s}' > total_size.txt
Find all PNG files in testbed/ and convert them to JPEG with a quality of 90%,find testbed/ -name '*.png' -exec convert -quality 90 {} {}.jpg \;
List all files in the directory /testbed/dir1 and sort them by size in human-readable format,ls -lhS /testbed/dir1
Count the number of lines in all text files under the directory /testbed/dir2,grep -rl . /testbed/dir2 | xargs wc -l
Print the name and size of the 3 largest files in the directory /testbed/dir3,du -a /testbed/dir3 | sort -rn | head -n 3
Find all empty directories in the directory /testbed and delete them,find /testbed -type d -empty -delete
Rename all files with extension .txt under the directory /testbed to have a .md extension instead,find /testbed -type f -name '*.txt' -exec rename .txt .md {} +
Find all files modified in the last 2 hours and compress them into a tarball named archive.tar.gz in the directory /testbed,find /testbed -type f -mmin -120 -print0 | xargs -0 tar -czf /testbed/archive.tar.gz
List all subdirectories of /testbed that are not named subdir1,ls -d /testbed/*/ | grep -v /subdir1/
Search for all files that contain the string 'text file' in their name or content under the directory /testbed,grep -r 'text file' /testbed
Compute the MD5 hash of all files under the directory /testbed and store them in a file named hashes.txt in the same directory,find /testbed -type f -exec md5sum {} + > /testbed/hashes.txt
Print the last 10 lines of the file /testbed/dir3/subdir1/subsubdir1/textfile3.txt,tail -n 10 /testbed/dir3/subdir1/subsubdir1/textfile3.txt
Find all symbolic links under the directory /testbed and print their target path,"find /testbed -type l -printf '%p -> %l
'"
Print the line number and contents of all lines containing the string 'value3' in the file /testbed/dir1/subdir1/jsonfile1.json,grep -n 'value3' /testbed/dir1/subdir1/jsonfile1.json
Find all files in the directory /testbed that have been modified in the last 24 hours and print their path,find /testbed -type f -mtime -1 -print
Display the contents of jsonfile1.json in a prettified JSON format using a third-party tool 'jq',cat /testbed/dir1/subdir1/jsonfile1.json | jq .
Search for all the files in /testbed directory and its subdirectories that contain the word 'Hello' and replace it with 'Hi' in-place.,"grep -rl ""Hello"" /testbed | xargs sed -i 's/Hello/Hi/g'"
"Display the contents of textfile3.txt and textfile4.txt side by side, with line numbers and a separator between them.","paste -d ""	"" - -s < /testbed/dir3/subdir1/subsubdir1/textfile3.txt < /testbed/dir1/subdir1/textfile4.txt"