nl
stringlengths 15
184
| bash
stringlengths 1
176
| bash2
stringlengths 4
166
| difficulty
int64 0
2
|
---|---|---|---|
Calculate the md5sum of each ".txt" file under "/system" and sort the output.
|
find /system -type f -name '*.txt' -exec md5sum {} + | awk '{print $1}' | sort
|
find /system -type f -name "*.txt" -exec md5sum {} + | sort
| 2 |
Search for the system host name in "/etc/hosts" and print the IP address in the first awk field
|
more /etc/hosts | grep `hostname` | awk '{print $1}'
|
grep "$(hostname)" /etc/hosts | awk '{print $1}'
| 2 |
Find files in /workspace directory modified within 30 days.
|
find /workspace -daystart -type f -mtime -30
|
find /workspace -type f -mtime -30
| 1 |
find files in the /workspace directory with pattern` *.c that larger than 1 Kilobytes
|
find /workspace -name '*.c' -size +1k -print
|
find /workspace -name '*.c' -size +1k
| 1 |
Find files in the /workspace directory and sub-directories, that changed over an hour ago.
|
find /workspace -type f -cmin +60
|
find /workspace -type f -cmin +60 -print
| 1 |
Find files in the /workspace directory and sub-directories, that were accessed over an hour ago.
|
find /workspace -type f -amin +60
|
find /workspace -type f -amin +60 -print
| 1 |
list all the drectories present in the /workspace directory and do not search in the sub directories.
|
find /workspace -maxdepth 1 -type d
|
find /workspace -maxdepth 1 -type d
| 1 |
list all the files in the /workspace directory which are of size 0 bytes.
|
find /workspace -empty
|
find /workspace -empty -print
| 1 |
list all zero-length files under the /workspace directory
|
find /workspace -empty -exec ls {} \;
|
find /workspace -type f -size 0
| 1 |
locate and remove large files (> 1 KB) in /workspace
|
find /workspace -type f -size +1k -delete
|
find /workspace -type f -size +1k -exec rm {} \;
| 1 |
List all the files in the /workspace directory which have only read permission to the group.
|
find /workspace -perm 400 -type f -exec ls -l {} \;
|
find /workspace -perm 400 -ls
| 1 |
List all the files in the /workspace directory which have permissions 777.
|
find /workspace -perm 777 -type f -exec ls -l {} \;
|
find /workspace -perm 777 -ls
| 1 |
List the details of all the text files in /workspace directory.
|
find /workspace -name "*.txt" -exec ls -ld {} \;
|
find /workspace -name "*.txt" | xargs ls -ld
| 1 |
move all files in the /workspace folder to / and do not move the files in the sub folder
|
find /workspace -maxdepth 1 -type f -exec mv -t / {} +
|
find /workspace -maxdepth 1 -type f -exec mv {} / \;
| 2 |
Move files in /workspace accessed less than one day ago to directory /.
|
find /workspace -atime -1 -type f -exec mv {} / \;
|
find /workspace -type f -atime -1 -print0 | xargs -0 -I {} mv {} /
| 1 |
print all filenames of files under /workspace/dir1 dir containing 'hello', case-insensitive
|
find /workspace/dir1 -type f -exec grep -il 'hello' {} \;
|
grep -ril 'hello' /workspace/dir1
| 2 |
print disk usage of files or folders in /workspace
|
du -sh /workspace
|
du -h /workspace
| 1 |
print the last word in /workspace/dir1/long.txt
|
tac /workspace/dir1/long.txt | awk 'NF{print $NF; exit}'
|
awk '{ for (i=1; i<=NF; i++) last=$i } END { print last }' /workspace/dir1/long.txt
| 2 |
Print the 3 largest directories in /workspace.
|
du -a /workspace | sort -nr | head -n 3
|
find /workspace -exec du -h {} + | sort -rh | head -n 3
| 1 |
prints first line of "/workspace/dir1/long.txt"
|
head -n1 /workspace/dir1/long.txt
|
sed -n '1p' /workspace/dir1/long.txt
| 1 |
prints the last non-empty line of "/workspace/dir1/a.txt"
|
tac /workspace/dir1/a.txt | grep -m 1 '.'
|
awk 'NF' /workspace/dir1/a.txt | tail -n 1
| 1 |
prune all the files in the /workspace directory
|
find /workspace -type f -delete
|
find /workspace -type f -exec rm -f {} +
| 1 |
search for all the files in the /workspace directory which have size greater than 1KB (approx) and less than 32KB(approx).
|
find /workspace -type f -size +1k -size -32k
|
find /workspace -type f -size +1k -size -32k -print
| 1 |
search for all the files in the /workspace folder and sort them in the order of their depth and display the file names
|
find /workspace -type f | awk -F/ '{print NF, $0}' | sort -n
|
find /workspace -type f | awk -F/ '{print NF, $0}' | sort -n | cut -d' ' -f2-
| 2 |
Search for all the files in the /workspace folder which are bigger than 1KB and display the biggest file.
|
find /workspace -type f -size +1k -exec ls -ls {} + | sort -n | tail -1
|
find /workspace -type f -size +1k -exec ls -lh {} + | sort -k 5 -rh | head -n 1
| 2 |
search for text files in the /workspace folder which do not have write access to others
|
find /workspace -type f \( -iname "*.txt" -not -perm -o=w \)
|
find /workspace -type f -name "*.txt" ! -perm -o=w
| 2 |
Search for the directory "mysql" in the workspace directory.
|
find /workspace -name mysql -type d
|
find workspace -type d -name "mysql"
| 1 |
Print a list of all duplicate case insensitive filenames in the /workspace directory tree
|
find /workspace -type f | awk -F/ '{print $NF}' | sort -f | uniq -i -d
|
find /workspace -type f | awk -F/ '{print tolower($NF)}' | sort | uniq -d
| 2 |
Search for the file old2.txt in the /workspace folder and list its permissions and creation time.
|
find /workspace -name old2.txt | xargs ls -tl
|
find /workspace -name old2.txt -print0 | xargs -0 ls -tl
| 1 |
search for the word "hello" in all the regular/normal files in the /workspace folder and display the matched file name
|
find /workspace -type f | xargs grep -l "hello"
|
grep -rnw '/workspace' -e 'hello'
| 1 |
Calculate the md5 sum of all files in the /workspace directory with the filename printed first
|
find /workspace -type f -exec md5sum {} + | awk '{print $2 " " $1}'
|
find /workspace -type f -print0 | xargs -0 md5sum | awk '{print $2 " " $1}'
| 2 |
Calculate the md5 sum of all files in directory tree "/workspace"
|
find /workspace -type f -exec md5sum {} + | sort
|
find /workspace -type f -exec md5sum {} +
| 1 |
Count the number of unique 3 to 6 character file extensions are in the /workspace directory tree
|
find /workspace -type f -name '*.*' | awk -F. 'NF>1 {ext=tolower($NF); if (length(ext) >= 3 && length(ext) <= 6) print ext}' | sort | uniq -c | wc -l
|
find /workspace -type f -name '*.*' | sed -n 's/.*\.//p' | awk '{print tolower($0)}' | grep -E '^[a-z]{3,6}$' | sort -u | wc -l
| 2 |
Create a copy of the /workspace directory structure in the /usr directory,
|
find /workspace -type d -print|sed 's@^@/usr/@'|xargs mkdir -p
|
find /workspace -type d | cpio -pdm /usr
| 2 |
Display a long listing of the oldest file under '/workspace' directory tree
|
find /workspace -type f -printf '%T+ %p\n' | sort | head -n 1 | awk '{print $2}' | xargs ls -l
|
find /workspace -type f -exec stat --format '%Y %n' {} \; | sort -n | head -n 1 | cut -d' ' -f2- | xargs ls -l
| 2 |
Find the largest 2 directories under /workspace directory
|
find /workspace -type d -print0 | xargs -0 du | sort -n | tail -2 | cut -f2 | xargs -I{} du -sh {}
|
find /workspace -type d -print0 | xargs -0 du | sort -n | tail -2
| 2 |
List all files with their paths that have identical content in /workspace directory
|
find /workspace -type f | xargs md5sum | sort | uniq -Dw32
|
find /workspace -type f -print0 | xargs -0 md5sum | sort | uniq -w32 -D
| 2 |
Make directories for each unique file path in "/workspace/files.txt"
|
cat /workspace/files.txt |xargs -I {} dirname "{}"| sort -u | xargs -I{} mkdir -p "{}"
|
cat /workspace/files.txt | xargs -I {} dirname {}| sort -u | xargs -I{} mkdir -p "{}"
| 2 |
Print the total disk usage in bytes of all files listed in "/workspace/files.txt"
|
cat /workspace/files.txt | xargs du -b | tail -1 | awk '{print $1}'
|
awk '{print $0}' /workspace/files.txt | xargs du -b | awk '{sum += $1} END {print sum}'
| 2 |
Unhide all hidden files in the /workspace directory. Do not include subdirectories.
|
find /workspace -maxdepth 1 -type f -name '.*' -exec sh -c 'mv "$0" "${0%/\.*}/${0##*/.}"' {} \;
|
find /workspace -maxdepth 1 -type f -name '.*' -exec sh -c 'mv "$1" "${1%/\.*}/${1##*/.}"' _ {} \;
| 2 |
Count the number of differing lines in "/workspace/dir1/long.txt" and "/workspace/dir1/terminate.txt"
|
diff /workspace/dir1/long.txt /workspace/dir1/terminate.txt | grep ^[\>\<] | wc -l
|
diff /workspace/dir1/long.txt /workspace/dir1/terminate.txt | grep '^>' | wc -l
| 2 |
Count the number of differing lines in "/workspace/dir1/terminate.txt" and "/workspace/dir1/long.txt" with 0 lines of unified context
|
diff -U 0 /workspace/dir1/terminate.txt /workspace/dir1/long.txt | grep -v ^@ | wc -l
|
diff -U 0 /workspace/dir1/terminate.txt /workspace/dir1/long.txt | grep -v '^@' | wc -l
| 2 |
Counts lines in file /workspace/dir1/a.txt ignoring empty lines and lines with spaces only.
|
awk '!/^[[:space:]]*$/{++x} END{print x}' /workspace/dir1/a.txt
|
grep -v '^[[:space:]]*$' /workspace/dir1/a.txt | wc -l
| 2 |
Create a symbolic link in directory "~/newlinks" for each file listed in "/workspace/results.txt"
|
cat /workspace/results.txt | xargs -I{} ln -s {} ~/newlinks
|
cat /workspace/results.txt | xargs -I {} ln -s {} ~/newlinks
| 2 |
Delete all hidden files under /workspace
|
find /workspace -type f -name '.*' -delete
|
find /workspace -type f -name '.*' -exec rm -f {} \;
| 1 |
Display a dump of "/workspace/dir1/long.txt" as floating point values of double size
|
od -t fD /workspace/dir1/long.txt
|
od -An -t fD /workspace/dir1/long.txt
| 1 |
Display differences between list of files in /workspace/dir1 and /workspace/dir2.
|
diff <(ls /workspace/dir1) <(ls /workspace/dir2)
|
diff -qr /workspace/dir1 /workspace/dir2
| 1 |
Display the file size of file '/workspace/dir1/sum.c' in bytes
|
du -sb /workspace/dir1/sum.c | cut -f1
|
stat -c %s /workspace/dir1/sum.c
| 1 |
Display the last slash-separated part of each filename path in /workspace/dir1/file.txt
|
rev /workspace/dir1/file.txt | cut -d/ -f1 | rev
|
awk -F/ '{print $NF}' /workspace/dir1/file.txt
| 1 |
Display the sizes and filepaths of all files/directories in /workspace directory sorted in descending order of size
|
du /workspace -a -h | sort -hr
|
du -ah /workspace | sort -rh
| 1 |
Print percentage of the space used on the /workspace directory.
|
df -k /workspace | tail -1 | awk '{print $5}'
|
df -h /workspace | awk 'NR==2 {print $5}'
| 1 |
Print the contents of "/workspace/dir1/long.txt" in reverse order
|
nl /workspace/dir1/long.txt | sort -nr | cut -b8-
|
tac /workspace/dir1/long.txt
| 1 |
Create an empty file "Icon" in workspace/ with a carriage return character in the end of its name.
|
echo $'workspace/Icon\r' | xargs touch
|
touch "workspace/Icon"$'\r'
| 1 |
Create a symbolc link in the /workspace/dir1 to root folder
|
ln /workspace/dir1 -s /
|
ln -s /workspace/dir1 /
| 1 |
Display permissions, user, group, and full path for each file in the /workspace directory tree
|
tree /workspace -p -u -g -f
|
find /workspace -type f -exec stat --format '%A %U %G %N' {} \;
| 1 |
Search for 'hello' case insensitively in all files under /workspace directory tree and show the matched lines with their filenames
|
find /workspace -type f -print0 | xargs -0 grep -iH "hello"
|
grep -ri 'hello' /workspace
| 2 |
Unpack all *.gz archives in the /workspace directory tree
|
find /workspace -name '*.gz' -print0 | xargs -0 gunzip
|
find /workspace -type f -name '*.gz' -exec gunzip {} +
| 2 |
Uncompress "/workspace/archive.tar.gz" and extract the archive to "/backup"
|
gzip -dc /workspace/archive.tar.gz | tar -xf - -C /backup
|
tar -xzvf /workspace/archive.tar.gz -C /backup
| 2 |
Create a symbolic link to "/workspace/dir1/terminate.txt" named "/workspace/test"
|
ln /workspace/dir1/terminate.txt /workspace/test
|
ln -s /workspace/dir1/terminate.txt /workspace/test
| 1 |
Retrieve only build number of current kernel, ie. #104
|
uname -v | grep -o '#[0-9]\+'
|
uname -r | awk -F'-' '{print $2}'
| 1 |
Print reverse lookup for adress 127.0.0.1
|
dig -x 127.0.0.1
|
nslookup 127.0.0.1
| 1 |
List file information of the full path of command "grep"
|
ls -ald `which grep`
|
stat $(which grep)
| 1 |
Extract host name part from "http://www.google.com"
|
echo "http://www.google.com" | cut -d'/' -f3
|
echo "http://www.google.com" | sed -E 's|https?://([^/]+).*|\1|'
| 1 |
List environment variables and their values, escaping all semicolons with a backslash.
|
env | sed 's/;/\\;/g'
|
while IFS= read -r line; do echo "${line//;/\\;}"; done < <(env)
| 1 |
Displays a tree of all process alongside their command line arguments.
|
pstree -a
|
ps -eo pid,ppid,cmd --forest
| 1 |
Create intermediate directories "dir" and "subdir" as required and create "subsubdir"
|
mkdir -p dir/subdir/subsubdir
|
mkdir -p dir/subdir/subsubdir
| 1 |
Print numbers 1 through 10 separated by ":"
|
yes | head -n10 | grep -n . | cut -d: -f1 | paste -sd:
|
echo $(seq -s ":" 1 10)
| 2 |
print all readline bindings
|
bind -P
|
bind -P
| 1 |
list names of bind functions containing "p"
|
bind -l | grep p
|
bind -l | egrep 'p'
| 1 |
Save first IP address of domain 'google.com' in 'address' variable and display it
|
address=$(dig +short google.com | grep -E '^[0-9.]+$' | head -n 1) && echo $address
|
address=$(dig +short google.com | grep -m 1 '^[0-9]' | head -n 1) && echo $address
| 2 |
Remove all characters except ";" and digits from the string " Hello world;876 "
|
echo ' Hello world;876 ' | tr -cd ';0-9'
|
echo " Hello world;876 " | sed 's/[^0-9;]//g'
| 1 |
Remove leading and trailing spaces or tabs from " Hello world! "
|
echo ' Hello world! ' | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//'
|
echo -n " Hello world! " | sed 's/^[ \t]*//;s/[ \t]*$//'
| 2 |
Remove the last 3 characters from "987654321"
|
echo 987654321 | rev | cut -c 4- | rev
|
echo "987654321" | sed 's/...$//'
| 1 |
Print source of the file system containing current working directory.
|
df . | tail -1 | awk '{print $1}'
|
df -P . | awk 'NR==2 {print $1}'
| 1 |
List all variables (names only) with names containing "H".
|
env | awk -F= '{if($1 ~ /H/) print $1}'
|
env | grep '^[^=]*H[^=]*=' | awk -F= '{print $1}'
| 1 |
Print a list of unique users who are logged in
|
who | cut -d' ' -f1 | sort | uniq
|
who | awk '{print $1}' | sort | uniq
| 1 |
ping 192.168.1.1
|
ping -w 1 192.168.1.1
|
ping -w 1 192.168.1.1
| 1 |
Print a line of 99 '=' characters
|
seq -s= 100|tr -d '[:digit:]'
|
printf '=%.0s' {1..99}
| 1 |
Count number of users logged in
|
who | awk -F' ' '{print $1}' | sort -u | wc -l
|
who | wc -l
| 1 |
Displays calendar of a previous, current and next month for December of 2120 year.
|
cal -3 12 2120
|
cal -3 12 2120
| 1 |
Extract, sort and print only group names from /etc/group.
|
cut -d: -f1 /etc/group | sort
|
cut -d: -f1 /etc/group | sort | uniq
| 1 |
Calculate the sum of all the numbers from 1 to 10
|
seq 10 | jq -s 'add'
|
echo $(( (10 * (10 + 1)) / 2 ))
| 1 |
Count the number of files and directories in the entire testbed directory
|
find /testbed | wc -l
|
find /testbed -print | wc -l
| 1 |
Print the number of python files in the testbed directory.
|
find testbed -type f -name "*.py" | wc -l
|
find testbed -type f -name "*.py" -print | wc -l
| 1 |
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
|
sort -r /testbed/dir1/textfile1.txt > /testbed/dir1/textfile1_reverse_sorted.txt
| 2 |
Search for all files containing the word 'Shell' in testbed.
|
find /testbed -type f -exec grep -l 'Shell' {} +
|
grep -r 'Shell' /testbed
| 1 |
Find all symbolic links in the testbed directory.
|
find /testbed -type l
|
find /testbed -type l -print
| 1 |
Get the total size of all files in testbed/ and save it to total_size.txt
|
du -sh testbed/ | awk '{print $1}' > total_size.txt
|
du -s testbed/ | awk '{print $1}' > total_size.txt
| 1 |
List all files in the directory /testbed/dir1 and sort them by size in human-readable format
|
ls -lhS /testbed/dir1
|
ls -lhS /testbed/dir1
| 1 |
Count the number of lines in files under the directory /testbed/dir2.
|
grep -rl . /testbed/dir2 | xargs wc -l
|
find /testbed/dir2 -type f -exec wc -l {} +
| 1 |
Print the name and size of the 3 largest files in the directory /testbed/dir3
|
find /testbed/dir3 -type f -exec ls -lhS {} + | sort -rh -k5 | head -n 3
|
find /testbed/dir3 -type f -exec ls -lhS {} + 2>/dev/null | sort -rh -k5 | head -n 3
| 2 |
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
|
find /testbed -type f -mmin -120 -print0 | xargs -0 tar -czf /testbed/archive.tar.gz
| 2 |
List all subdirectories of /testbed that are not named subdir1
|
ls -d /testbed/*/ | grep -v /subdir1/
|
find /testbed -mindepth 1 -maxdepth 1 -type d ! -name "subdir1"
| 1 |
Search for all files that contain the string 'text file' under the directory /testbed
|
grep -r 'text file' /testbed
|
grep -rl 'text file' /testbed
| 1 |
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
|
find /testbed -type f -exec md5sum {} + > /testbed/hashes.txt
| 2 |
Print the last 10 lines of the file /testbed/dir3/subdir1/subsubdir1/textfile3.txt
|
tail -n 10 /testbed/dir3/subdir1/subsubdir1/textfile3.txt
|
tail -n 10 /testbed/dir3/subdir1/subsubdir1/textfile3.txt
| 2 |
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
|
grep -n 'value3' /testbed/dir1/subdir1/jsonfile1.json
| 2 |
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
|
find /testbed -type f -mtime -1
| 1 |
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'
|
grep -rl 'Hello' /testbed | xargs sed -i 's/Hello/Hi/g'
| 2 |
Display the contents of textfile3.txt and textfile4.txt side by side, with line numbers and a separator between them.
|
paste <(nl /testbed/dir3/subdir1/subsubdir1/textfile3.txt) <(nl /testbed/dir1/subdir1/textfile4.txt)
|
paste <(nl /testbed/dir3/subdir1/subsubdir1/textfile3.txt) <(nl /testbed/dir1/subdir1/textfile4.txt)
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.