Skip to content

Instantly share code, notes, and snippets.

@wisetara
Last active December 12, 2017 05:16
Show Gist options
  • Save wisetara/fa45c8c71d3d42d1aa2b3f11263a695d to your computer and use it in GitHub Desktop.
Save wisetara/fa45c8c71d3d42d1aa2b3f11263a695d to your computer and use it in GitHub Desktop.
Bash script
# Write a bash script named "hw22-3" that accepts a list of inode numbers from the command line,
# and displays
# the file name and physical file system of each file with that inode number. If no
# file exists with that inode number display "no such file".
#
# EXAMPLE:
# > hw22-3 8384567 12345
# Inode "8384567" has files:
# main.cpp on /dev/mapper/system-student
#
# Inode "12345" has files:
# No such file
# submitted version:
#!/bin/bash
read -a inodes
for i in ${inodes[@]}
do
filename=$(find -inum $i)
if [[ "$filename" == *"/"* ]]
then
location=$(df $filename | awk '{if(NR>1)print $1}' 2>&1)
echo Inode $i has files: $file on $location
else
echo Inode $i has files: No such file
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment